-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapertium
executable file
·100 lines (77 loc) · 2.59 KB
/
apertium
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# fmt: off
#%# family=auto
#%# capabilities=autoconf
# fmt: on
import json
import os
import sys
import urllib.request
def fetch_data(server):
req = urllib.request.Request(f"{server}stats")
with urllib.request.urlopen(req) as response:
content = response.read().decode()
return json.loads(content)
NAME = os.path.basename(sys.argv[0])
try:
CMD = sys.argv[1]
except IndexError:
CMD = "fetch"
ATTRIBS = {
"celery_search": {"warning": ":10000", "critical": ":20000"},
"celery_backup": {"warning": ":10", "critical": ":100"},
"celery_celery": {"warning": ":200", "critical": ":1000"},
"celery_notify": {"warning": ":1000", "critical": ":2000"},
"celery_memory": {"warning": ":10000", "critical": ":20000"},
"celery_translate": {"warning": ":200", "critical": ":1000"},
"configuration_errors": {"critical": ":0"},
"changes": {"type": "DERIVE"},
}
def use_count(data):
for key in sorted(data["responseData"]["useCount"]):
yield key, {"type": "DERIVE"}
def use_count_data(data):
yield from sorted(data["responseData"]["useCount"].items())
def period_stats_key(key):
def stats_key(data):
yield key, {}
return stats_key
def period_stats_data(key):
def stats_data(data):
yield key, data["responseData"]["periodStats"][key]
return stats_data
GROUPS = (
("Usage", use_count, use_count_data),
("Chars", period_stats_key("totChars"), period_stats_data("totChars")),
("Requests", period_stats_key("requests"), period_stats_data("requests")),
(
"Chars per second",
period_stats_key("charsPerSec"),
period_stats_data("charsPerSec"),
),
)
server = os.environ.get("SERVER", "http://localhost:2737/")
data = fetch_data(server)
if CMD == "config":
for group, group_keys, _group_data in GROUPS:
print()
print("multigraph {}_{}".format(NAME.lower(), group.lower().replace(" ", "_")))
print()
print(f"graph_title {group}")
print("graph_args --base 1000")
print("graph_scale no")
print("graph_category apertium")
print()
for key, attribs in group_keys(data):
print(f"{key}.label {key}")
for attrib, value in attribs.items():
print(f"{key}.{attrib} {value}")
elif CMD == "autoconf":
print("yes")
else:
for group, _group_keys, group_data in GROUPS:
print()
print("multigraph {}_{}".format(NAME.lower(), group.lower().replace(" ", "_")))
print()
for key, value in group_data(data):
print(f"{key}.value {value}")