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 bdf5175
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 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,31 @@ 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_meminfo_data(field, output):
data = None
try:
data = int(re.findall(r'%s\:\s+([0-9]+)\skB\n' % data, output)[0])
except IndexError:
data = None
finally:
return data


def get_memused(data, in_bytes=True):
free = get_meminfo_data('MemFree', data)
total = get_meminfo_data('MemTotal', data)
if free is None or total is None:
return -1
used = total - free
if in_bytes:
return used * 1024
return used


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 +125,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_memused(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 bdf5175

Please sign in to comment.