Skip to content

Commit

Permalink
gets memory from /proc/meminfo
Browse files Browse the repository at this point in the history
  • Loading branch information
odra committed Apr 24, 2017
1 parent fd9f009 commit 63867f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/default/lib/memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import traceback
from collections import Counter
import re

import openshift
import nagios
Expand All @@ -28,10 +29,20 @@ def generate_parser():
return parser


check_memory_usage_cmd = ("cat", "/sys/fs/cgroup/memory/memory.usage_in_bytes")
check_memory_usage_cmd = ("cat", "/proc/meminfo")
check_memory_limit_cmd = ("cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes")


def get_memfree(output):
data = None
try:
data = int(re.findall(r'MemFree\:\s+([0-9]+)\skB\n', output)[0]) * 1024
except IndexError:
data = -1
finally:
return data


def analize(pod, container, memory_limit, memory_used, warning_threshold, critical_threshold):
results = []
usage = (float(memory_used) / float(memory_limit)) * 100
Expand Down Expand Up @@ -103,6 +114,7 @@ def check(warn, crit, project):
try:
memory_usage = openshift.exec_in_pod_container(
project, pod_name, container_name, check_memory_usage_cmd)
memory_usage = get_memfree(memory_usage)
if memory_limit:
memory_limit = openshift.exec_in_pod_container(
project, pod_name, container_name, check_memory_limit_cmd)
Expand Down

0 comments on commit 63867f1

Please sign in to comment.