-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpfpm_
More file actions
76 lines (62 loc) · 2.38 KB
/
phpfpm_
File metadata and controls
76 lines (62 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import os
import sys
import json
import urllib.request
# Munin plugin for PHP-FPM pool status monitoring
# Supports JSON status endpoint
# Author: ChatGPT + Stanislav Janů
POOL = os.getenv("pool", "www")
URL = os.getenv("url", f"http://127.0.0.1/status-{POOL}?json")
TIMEOUT = int(os.getenv("timeout", "3"))
def fetch_status():
try:
with urllib.request.urlopen(URL, timeout=TIMEOUT) as response:
data = json.loads(response.read().decode())
return data
except Exception as e:
print(f"# ERROR: {e}", file=sys.stderr)
sys.exit(1)
def print_config():
# --- accepted_conn ---
print(f"multigraph phpfpm_{POOL}_accepted_conn")
print(f"graph_title PHP-FPM {POOL}: Accepted connections")
print("graph_vlabel connections")
print("graph_category php-fpm")
print("accepted_conn.label accepted connections")
print("accepted_conn.type DERIVE")
print("accepted_conn.min 0")
# --- processes ---
print(f"\nmultigraph phpfpm_{POOL}_processes")
print(f"graph_title PHP-FPM {POOL}: Processes")
print("graph_vlabel processes")
print("graph_category php-fpm")
print("active_processes.label active")
print("idle_processes.label idle")
print("max_active_processes.label max active")
# --- slow_requests ---
print(f"\nmultigraph phpfpm_{POOL}_slow_requests")
print(f"graph_title PHP-FPM {POOL}: Slow requests")
print("graph_vlabel slow requests")
print("graph_category php-fpm")
print("slow_requests.label slow requests")
print("slow_requests.type DERIVE")
print("slow_requests.min 0")
def print_values(data):
# --- accepted_conn ---
print(f"multigraph phpfpm_{POOL}_accepted_conn")
print(f"accepted_conn.value {data.get('accepted conn', 0)}")
# --- processes ---
print(f"\nmultigraph phpfpm_{POOL}_processes")
print(f"active_processes.value {data.get('active processes', 0)}")
print(f"idle_processes.value {data.get('idle processes', 0)}")
print(f"max_active_processes.value {data.get('max active processes', 0)}")
# --- slow_requests ---
print(f"\nmultigraph phpfpm_{POOL}_slow_requests")
print(f"slow_requests.value {data.get('slow requests', 0)}")
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == "config":
print_config()
else:
status = fetch_status()
print_values(status)