Skip to content
Permalink
Browse files

7064 cpu.threads: now returns the percentage of threads used

The check cpu.threads is now able to return the percentage of threads
used on linux systems. To use this feature the check_mk_agent has to
be updated. Levels for the thread usage can be defined in WATO.

Change-Id: I7238a0e78b8434e17c0ce927205e1ae31cead9ec
  • Loading branch information...
7omb committed Mar 6, 2019
1 parent d9a54e1 commit 1cb127801176f34fda3b46bd701213b4b94ed29c
@@ -0,0 +1,12 @@
Title: cpu.threads: now returns the percentage of threads used
Level: 1
Component: checks
Compatible: compat
Edition: cre
Version: 1.6.0i1
Date: 1551881294
Class: feature

The check cpu.threads is now able to return the percentage of threads
used on linux systems. To use this feature the check_mk_agent has to
be updated. Levels for the thread usage can be defined in WATO.
@@ -150,6 +150,9 @@ function section_cpu()
if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ]; then
echo '<<<cpu>>>'
echo "$(cat /proc/loadavg) $NUM_CPUS"
if [ -f "/proc/sys/kernel/threads-max" ]; then
cat /proc/sys/kernel/threads-max
fi
else
if [ -n "$IS_DOCKERIZED" ]; then
echo '<<<docker_container_cpu>>>'
@@ -40,7 +40,7 @@ cpuload_default_levels = (5.0, 10.0)


def inventory_cpu_load(info):
if len(info) == 1 and len(info[0]) >= 5:
if len(info) >= 1 and len(info[0]) >= 5:
return [(None, "cpuload_default_levels")]


@@ -88,26 +88,47 @@ check_info["cpu.loads"] = {
# | |
# '----------------------------------------------------------------------'

threads_default_levels = (2000, 4000)
threads_default_levels = {} # legacy default levels variable

factory_settings["cpu_threads_default_levels"] = {
"levels": (2000, 4000),
}


def inventory_cpu_threads(info):
if len(info) == 1 and len(info[0]) >= 5:
return [(None, "threads_default_levels")]
if len(info) >= 1 and len(info[0]) >= 5:
return [(None, {})]


def check_cpu_threads(item, params, info):
if isinstance(params, tuple):
params = {'levels': params}

try:
nthreads = int(info[0][3].split('/')[1])
num_threads = int(info[0][3].split('/')[1])
except:
return (3, "invalid output from plugin")
warn, crit = params
perfdata = [('threads', nthreads, warn, crit, 0)]
if nthreads >= crit:
return (2, "%d threads (critical at %d)" % (nthreads, crit), perfdata)
elif nthreads >= warn:
return (1, "%d threads (warning at %d)" % (nthreads, warn), perfdata)
return (0, "%d threads" % (nthreads,), perfdata)
yield (3, "invalid output from plugin")
return

absolute_levels = params.get("levels", (None, None))
yield check_levels(
num_threads,
'threads',
absolute_levels,
unit="threads",
human_readable_func=lambda x: "%.f" % x,
infoname="Count")

if len(info) > 1:
max_threads = int(info[1][0])
thread_usage = 100.0 * num_threads / max_threads
relative_levels = params.get("levels_percent", (None, None))
yield check_levels(
thread_usage,
'thread_usage',
relative_levels,
human_readable_func=get_percent_human_readable,
infoname="Usage")


check_info["cpu.threads"] = {
@@ -116,5 +137,6 @@ check_info["cpu.threads"] = {
"service_description": "Number of threads",
"has_perfdata": True,
"group": "threads",
"default_levels_variable": "cpu_threads_default_levels",
"handle_real_time_checks": True,
}
@@ -1225,6 +1225,12 @@ def register_hop_metrics():
"color": "#8040f0",
}

metric_info["thread_usage"] = {
"title": _("Thread usage"),
"unit": "%",
"color": "22/a",
}

metric_info["threads_idle"] = {
"title": _("Idle threads"),
"unit": "count",
@@ -8698,6 +8704,12 @@ def get_skype_mobile_perfometer_segments():
],
}

graph_info["thread_usage"] = {
"metrics": [("thread_usage", "area"),],
"scalars": ["thread_usage:warn", "thread_usage:crit"],
"range": (0, 100),
}

graph_info["threadpool"] = {
"title": _("Threadpool"),
"metrics": [
@@ -26,8 +26,11 @@

from cmk.gui.i18n import _
from cmk.gui.valuespec import (
Dictionary,
Integer,
Percentage,
Tuple,
Transform,
)

from cmk.gui.plugins.wato import (
@@ -51,14 +54,31 @@ def check_group_name(self):
def title(self):
return _("Number of threads")

@property
def match_type(self):
return "dict"

@property
def parameter_valuespec(self):
return Tuple(
help=_(
"These levels check the number of currently existing threads on the system. Each process has at "
"least one thread."),
elements=[
Integer(title=_("Warning at"), unit=_("threads"), default_value=1000),
Integer(title=_("Critical at"), unit=_("threads"), default_value=2000)
],
return Transform(
Dictionary(
elements=[
("levels",
Tuple(
title=_("Absolute levels"),
elements=[
Integer(title=_("Warning at"), unit=_("threads"), default_value=2000),
Integer(title=_("Critical at"), unit=_("threads"), default_value=4000)
],
)),
("levels_percent",
Tuple(
title=_("Relative levels"),
elements=[
Percentage(title=_("Warning at"), default_value=80),
Percentage(title=_("Critical at"), default_value=90)
],
)),
],),
forth=lambda params: params if isinstance(params, dict) else {'levels': params},
)

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,37 @@
# yapf: disable

checkname = 'cpu'

info = [[u'0.88', u'0.83', u'0.87', u'2/2148', u'21050', u'8']]

discovery = {
'loads': [(None, 'cpuload_default_levels')],
'threads': [(None, {})],
}

checks = {
'loads': [(
None,
(5.0, 10.0),
[(
0,
'15 min load: 0.87 at 8 Cores (0.11 per Core)',
[
('load1', 0.88, 40.0, 80.0, 0, 8),
('load5', 0.83, 40.0, 80.0, 0, 8),
('load15', 0.87, 40.0, 80.0, 0, 8),
],
)],
)],
'threads': [(
None,
{
'levels': (2000, 4000)
},
[(
1,
'Count: 2148 threads (warn/crit at 2000 threads/4000 threads)',
[('threads', 2148, 2000.0, 4000.0, None, None)],
)],
)]
}
@@ -0,0 +1,36 @@
# yapf: disable

checkname = 'cpu'

info = [[u'0.88', u'0.83', u'0.87', u'2/1748', u'21050', u'8'], [u'124069']]

discovery = {
'loads': [(None, 'cpuload_default_levels')],
'threads': [(None, {})],
}

checks = {
'loads': [(
None,
(5.0, 10.0),
[(
0,
'15 min load: 0.87 at 8 Cores (0.11 per Core)',
[
('load1', 0.88, 40.0, 80.0, 0, 8),
('load5', 0.83, 40.0, 80.0, 0, 8),
('load15', 0.87, 40.0, 80.0, 0, 8),
],
)],
)],
'threads': [(
None,
{
'levels': (2000, 4000)
},
[
(0, 'Count: 1748 threads', [('threads', 1748, 2000.0, 4000.0, None, None)]),
(0, 'Usage: 1.41%', [('thread_usage', 1.408893438328672, None, None, None, None)]),
],
)],
}

0 comments on commit 1cb1278

Please sign in to comment.
You can’t perform that action at this time.