diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-11 15:35:24 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-11 15:35:24 +0100 |
commit | 258441019881c451686dbe537069228cc8e49612 (patch) | |
tree | 2b788d0ad445608afe01e8801553ffe0a28de047 /modules/private/monitoring/plugins/check_eriomem | |
parent | 423c3f1caefdf5f125a2acf7456b5ca0273cee4b (diff) | |
download | Nix-258441019881c451686dbe537069228cc8e49612.tar.gz Nix-258441019881c451686dbe537069228cc8e49612.tar.zst Nix-258441019881c451686dbe537069228cc8e49612.zip |
Add some monitoring services (eriomem)
Diffstat (limited to 'modules/private/monitoring/plugins/check_eriomem')
-rwxr-xr-x | modules/private/monitoring/plugins/check_eriomem | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_eriomem b/modules/private/monitoring/plugins/check_eriomem new file mode 100755 index 0000000..65ca790 --- /dev/null +++ b/modules/private/monitoring/plugins/check_eriomem | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/env python | ||
2 | import os | ||
3 | import sys | ||
4 | import getopt | ||
5 | import signal | ||
6 | from subprocess import Popen, PIPE | ||
7 | |||
8 | STATE_OK = 0 | ||
9 | STATE_WARNING = 1 | ||
10 | STATE_CRITICAL = 2 | ||
11 | STATE_UNKNOWN = 3 | ||
12 | |||
13 | keys = sys.argv[1].split(",") | ||
14 | |||
15 | def to_args(k): | ||
16 | access, secret = k.split(":", 1) | ||
17 | return [ | ||
18 | "s3cmd", | ||
19 | '-c=/dev/null', | ||
20 | '--no-check-certificate', | ||
21 | '--access_key={}'.format(access), | ||
22 | '--secret_key={}'.format(secret), | ||
23 | '--host=e.eriomem.net', | ||
24 | '--host-bucket=%(bucket)s.e.eriomem.net', | ||
25 | 'du' | ||
26 | ] | ||
27 | |||
28 | ARGS1= to_args(keys[0]) | ||
29 | ARGS2= to_args(keys[1]) | ||
30 | |||
31 | max_size = 1024*1024*1024*1024 | ||
32 | warning_percent = 99.75 | ||
33 | critical_percent = 99.95 | ||
34 | |||
35 | def output(code, msg): | ||
36 | print(msg) | ||
37 | sys.exit(code) | ||
38 | |||
39 | def main(): | ||
40 | def handler(signum, frame): | ||
41 | raise IOError | ||
42 | signal.signal(signal.SIGALRM, handler) | ||
43 | signal.alarm(60) | ||
44 | |||
45 | try: | ||
46 | ps = [Popen(to_args(a), stdout=PIPE, stderr=PIPE) for a in keys] | ||
47 | outs = [p.communicate() for p in ps] | ||
48 | rets = [p.wait() for p in ps] | ||
49 | except IOError: | ||
50 | for p in ps: | ||
51 | os.kill(p.pid, signal.SIGTERM) | ||
52 | output(STATE_UNKNOWN, | ||
53 | "eriomem UNKNOWN - Command timeout after 60 seconds!") | ||
54 | |||
55 | signal.alarm(0) | ||
56 | |||
57 | if sum(rets) == 0: | ||
58 | usages = [int(out[0].decode().split("\n")[-2].split()[0]) for out in outs] | ||
59 | usage = sum(usages) | ||
60 | use_percent = 100 * usage / max_size | ||
61 | if use_percent > critical_percent: | ||
62 | output(STATE_CRITICAL, | ||
63 | "eriomem CRITICAL - bucket usage: %s (%s%%);| size=%s;;;;" % | ||
64 | (sizeof_fmt(usage), use_percent, usage)) | ||
65 | elif use_percent > warning_percent: | ||
66 | output(STATE_WARNING, | ||
67 | "eriomem WARNING - bucket usage: %s (%s%%);| size=%s;;;;" % | ||
68 | (sizeof_fmt(usage), use_percent, usage)) | ||
69 | else: | ||
70 | output(STATE_OK, | ||
71 | "eriomem OK - bucket usage: %s (%d%%);| size=%s;;;;" % | ||
72 | (sizeof_fmt(usage), use_percent, usage)) | ||
73 | else: | ||
74 | messages = "\n".join([out[0].decode() + out[1].decode() for out in outs]) | ||
75 | output(STATE_UNKNOWN, | ||
76 | "eriomem Unknown - Error in command\n" + messages) | ||
77 | |||
78 | def sizeof_fmt(num): | ||
79 | for unit in ['','ko','Mo','Go','To','Po','Eo','Zo']: | ||
80 | if abs(num) < 1024.0: | ||
81 | return "%3.1f%s" % (num, unit) | ||
82 | num /= 1024.0 | ||
83 | return "%.1f%s%s" % (num, 'Yo') | ||
84 | |||
85 | if __name__ == '__main__': | ||
86 | main() | ||