diff options
Diffstat (limited to 'modules/private/monitoring/plugins/check_eriomem')
-rwxr-xr-x | modules/private/monitoring/plugins/check_eriomem | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/modules/private/monitoring/plugins/check_eriomem b/modules/private/monitoring/plugins/check_eriomem deleted file mode 100755 index 880b88a..0000000 --- a/modules/private/monitoring/plugins/check_eriomem +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
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 | max_size = 1024*1024*1024*1024 | ||
29 | warning_percent = 99.75 | ||
30 | critical_percent = 99.95 | ||
31 | |||
32 | def output(code, msg): | ||
33 | print(msg) | ||
34 | sys.exit(code) | ||
35 | |||
36 | def main(): | ||
37 | def handler(signum, frame): | ||
38 | raise IOError | ||
39 | signal.signal(signal.SIGALRM, handler) | ||
40 | signal.alarm(60) | ||
41 | |||
42 | try: | ||
43 | ps = [Popen(to_args(a), stdout=PIPE, stderr=PIPE) for a in keys] | ||
44 | outs = [p.communicate() for p in ps] | ||
45 | rets = [p.wait() for p in ps] | ||
46 | except IOError: | ||
47 | for p in ps: | ||
48 | os.kill(p.pid, signal.SIGTERM) | ||
49 | output(STATE_UNKNOWN, | ||
50 | "Eriomem UNKNOWN - Command timeout after 60 seconds!") | ||
51 | |||
52 | signal.alarm(0) | ||
53 | |||
54 | if sum(rets) == 0: | ||
55 | usages = [int(out[0].decode().split("\n")[-2].split()[0]) for out in outs] | ||
56 | usage = sum(usages) | ||
57 | use_percent = 100 * usage / max_size | ||
58 | if use_percent > critical_percent: | ||
59 | output(STATE_CRITICAL, | ||
60 | "Eriomem CRITICAL - bucket usage: %s (%s%%);| size=%s;;;;" % | ||
61 | (sizeof_fmt(usage), use_percent, sizeof_fmt(usage))) | ||
62 | elif use_percent > warning_percent: | ||
63 | output(STATE_WARNING, | ||
64 | "Eriomem WARNING - bucket usage: %s (%s%%);| size=%s;;;;" % | ||
65 | (sizeof_fmt(usage), use_percent, sizeof_fmt(usage))) | ||
66 | else: | ||
67 | output(STATE_OK, | ||
68 | "Eriomem OK - bucket usage: %s (%d%%);| size=%s;;;;" % | ||
69 | (sizeof_fmt(usage), use_percent, sizeof_fmt(usage))) | ||
70 | else: | ||
71 | messages = "\n".join([out[0].decode() + out[1].decode() for out in outs]) | ||
72 | output(STATE_UNKNOWN, | ||
73 | "Eriomem UNKNOWN - Error in command") | ||
74 | |||
75 | def sizeof_fmt(num): | ||
76 | for unit in ['','ko','Mo','Go','To','Po','Eo','Zo']: | ||
77 | if abs(num) < 1024.0: | ||
78 | return "%3.1f%s" % (num, unit) | ||
79 | num /= 1024.0 | ||
80 | return "%.1f%s%s" % (num, 'Yo') | ||
81 | |||
82 | if __name__ == '__main__': | ||
83 | main() | ||