Skip to content

Commit 02950e1

Browse files
committed
gets memory from /proc/meminfo
1 parent fd9f009 commit 02950e1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

plugins/default/lib/memory_usage.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import traceback
55
from collections import Counter
6+
import re
67

78
import openshift
89
import nagios
@@ -27,11 +28,20 @@ def generate_parser():
2728
)
2829
return parser
2930

30-
31-
check_memory_usage_cmd = ("cat", "/sys/fs/cgroup/memory/memory.usage_in_bytes")
31+
check_memory_usage_cmd = ("cat", "/proc/meminfo")
3232
check_memory_limit_cmd = ("cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes")
3333

3434

35+
def get_memfree(output):
36+
data = None
37+
try:
38+
data = int(re.findall(r'MemFree\:\s+([0-9]+)\skB\n', output)[0]) * 1024
39+
except IndexError:
40+
data = -1
41+
finally:
42+
return data
43+
44+
3545
def analize(pod, container, memory_limit, memory_used, warning_threshold, critical_threshold):
3646
results = []
3747
usage = (float(memory_used) / float(memory_limit)) * 100
@@ -103,6 +113,7 @@ def check(warn, crit, project):
103113
try:
104114
memory_usage = openshift.exec_in_pod_container(
105115
project, pod_name, container_name, check_memory_usage_cmd)
116+
memory_usage = get_memfree(memory_usage)
106117
if memory_limit:
107118
memory_limit = openshift.exec_in_pod_container(
108119
project, pod_name, container_name, check_memory_limit_cmd)

0 commit comments

Comments
 (0)