Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gets memory from /proc/meminfo #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 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,37 @@ 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_jvm_max_heap_cmd = ("java", "-XX:+PrintFlagsFinal", "-version")
check_memory_limit_cmd = ("cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes")


def jvm_data(data, key):
return re.findall(r'\s+[a-zA-Z]+\s%s\s+\:?\=\s([0-9]+)\s+\{[a-zA-Z\s?]+\}\n' % key, data)[0]


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 heap_thread_size(pid=1, thread_size=1024):
folder = '/proc/%s/task' % pid
total_tasks = len([task for task in os.listdir(folder) if task.isdigit()])
return total_tasks * thread_size


def get_memused(data, jvm_data):
initial = int(jvm_data(jvm_data, 'InitialHeapSize'))
single_thread_size = int(jvm_data(info, 'ThreadStackSize'))
return initial + heap_thread_size(2727, thread_size=single_thread_size)


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 +131,9 @@ def check(warn, crit, project):
try:
memory_usage = openshift.exec_in_pod_container(
project, pod_name, container_name, check_memory_usage_cmd)
jvm_heap = openshift.exec_in_pod_container(
project, pod_name, container_name, check_jvm_max_heap_cmd)
memory_usage = get_memused(memory_usage, jvm_heap)
if memory_limit:
memory_limit = openshift.exec_in_pod_container(
project, pod_name, container_name, check_memory_limit_cmd)
Expand Down