-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_mem.py
More file actions
executable file
·68 lines (59 loc) · 1.29 KB
/
check_mem.py
File metadata and controls
executable file
·68 lines (59 loc) · 1.29 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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
# - flo932@uxsrv.de micha.r
import os
import subprocess
os.system("id")
_exit = 3
r=100
cmd="free -m| tail -n 2 | xargs | jq -R 'split(\" \")|{all:.[1],used:.[2],free:.[6]}'"
print(cmd.replace("|","I"))
#r = subprocess.Popen([cmd])a
r = os.popen(cmd)
#print(dir(r))
#if not r:
# _exit += 1
#exitcode = writer.wait()
txt = r.read()
#print(txt)
import json
j = json.loads(txt)
print(j)
perf = []
_max = 95
_warn = 90
_min = 0
if "free" in j and "all" in j:
pf = "|mem="
try:
f = int(j["free"])
a = int(j["all"])
u = a-f #f/a # used in %
_warn = int(a*0.90)
_krit = int(a*0.95)
_max = a
#u = a/f-1 # used in %
#u = f/(a/100)
#u = (f)/(a/100)
print("used: {:0.02f} k".format(u) )
if u > _krit:
_exit = 2 # 2 krit
elif u > _warn:
_exit = 1 # 1 warn
else:
_exit = 0 # 0 OK
pf = "{:0.02f};{:0.02f};{:0.02f};{:0.02f};{:0.02f}".format(u,_warn,_krit,_min,_max)
perf.append(pf)
except Exception as e:
print(e)
_exit = 3
print()
print("exit:",_exit)
# 0 OK
# 1 warning
# 2 krit
#
if perf:
for i,p in enumerate(perf):
print("|mem{}=".format(i)+p)
print()