33import sys
44import traceback
55from collections import Counter
6+ import re
67
78import openshift
89import nagios
@@ -28,10 +29,31 @@ def generate_parser():
2829 return parser
2930
3031
31- check_memory_usage_cmd = ("cat" , "/sys/fs/cgroup/memory/memory.usage_in_bytes " )
32+ check_memory_usage_cmd = ("cat" , "/proc/meminfo " )
3233check_memory_limit_cmd = ("cat" , "/sys/fs/cgroup/memory/memory.limit_in_bytes" )
3334
3435
36+ def get_meminfo_data (field , output ):
37+ data = None
38+ try :
39+ data = int (re .findall (r'%s\:\s+([0-9]+)\skB\n' % data , output )[0 ])
40+ except IndexError :
41+ data = None
42+ finally :
43+ return data
44+
45+
46+ def get_memused (data , in_bytes = True ):
47+ free = get_meminfo_data ('MemFree' , data )
48+ total = get_meminfo_data ('MemTotal' , data )
49+ if free is None or total is None :
50+ return - 1
51+ used = total - free
52+ if in_bytes :
53+ return used * 1024
54+ return used
55+
56+
3557def analize (pod , container , memory_limit , memory_used , warning_threshold , critical_threshold ):
3658 results = []
3759 usage = (float (memory_used ) / float (memory_limit )) * 100
@@ -103,6 +125,7 @@ def check(warn, crit, project):
103125 try :
104126 memory_usage = openshift .exec_in_pod_container (
105127 project , pod_name , container_name , check_memory_usage_cmd )
128+ memory_usage = get_memused (memory_usage )
106129 if memory_limit :
107130 memory_limit = openshift .exec_in_pod_container (
108131 project , pod_name , container_name , check_memory_limit_cmd )
0 commit comments