Module: check_mk
Branch: master
Commit: ebd176a2851555418e5e954d03058e5bdcdaeeeb
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ebd176a2851555…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sun Mar 3 15:18:40 2019 +0100
Change MK_IN_CONTAINER to more specific name: It only applies to docker containers
Change-Id: I69c64731c3bf5b3da1cbb075dec4ff9056ec9eaf
---
agents/check_mk_agent.linux | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index adc18e5..e8b3565 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -79,9 +79,9 @@ fi
# Detect whether or not the agent is being executed in a container
# environment.
if [ -f /.dockerenv ]; then
- MK_IN_CONTAINER=1
+ IS_DOCKERIZED=1
else
- unset MK_IN_CONTAINER
+ unset IS_DOCKERIZED
fi
# Prefer (relatively) new /usr/bin/timeout from coreutils against
@@ -116,7 +116,7 @@ fi
function section_mem()
{
- if [ -z "$MK_IN_CONTAINER" ]; then
+ if [ -z "$IS_DOCKERIZED" ]; then
echo '<<<mem>>>'
grep -E -v '^Swap:|^Mem:|total:' < /proc/meminfo
else
@@ -139,7 +139,7 @@ function section_cpu()
fi
NUM_CPUS=$(grep -c -E $CPU_REGEX < /proc/cpuinfo)
- if [ -z "$MK_IN_CONTAINER" ]; then
+ if [ -z "$IS_DOCKERIZED" ]; then
echo '<<<cpu>>>'
echo "$(cat /proc/loadavg) $NUM_CPUS"
else
@@ -153,7 +153,7 @@ function section_cpu()
function section_uptime()
{
echo '<<<uptime>>>'
- if [ -z "$MK_IN_CONTAINER" ]; then
+ if [ -z "$IS_DOCKERIZED" ]; then
cat /proc/uptime
else
echo "$(($(date +%s) - $(stat -c %Z /dev/pts)))"
@@ -168,7 +168,7 @@ function section_uptime()
# These should generally be monitored on the NFS server, not on the clients.
function section_df()
{
- if [ -n "$MK_IN_CONTAINER" ]; then
+ if [ -n "$IS_DOCKERIZED" ]; then
return
fi
@@ -507,7 +507,7 @@ if type multipath >/dev/null ; then
fi
# Performancecounter Platten
-if [ -z "$MK_IN_CONTAINER" ]; then
+if [ -z "$IS_DOCKERIZED" ]; then
echo '<<<diskstat>>>'
date +%s
grep -E ' (x?[shv]d[a-z]*[0-9]*|cciss/c[0-9]+d[0-9]+|emcpower[a-z]+|dm-[0-9]+|VxVM.*|mmcblk.*|dasd[a-z]*|bcache[0-9]+|nvme[0-9]+n[0-9]+) ' < /proc/diskstats
@@ -536,7 +536,7 @@ fi
# Performancecounter Kernel
-if [ -z "$MK_IN_CONTAINER" ]; then
+if [ -z "$IS_DOCKERIZED" ]; then
echo '<<<kernel>>>'
date +%s
cat /proc/vmstat /proc/stat
@@ -696,7 +696,7 @@ then
done
fi
-if [ -z "$MK_IN_CONTAINER" ] && [ -e /proc/drbd ]; then
+if [ -z "$IS_DOCKERIZED" ] && [ -e /proc/drbd ]; then
echo '<<<drbd>>>'
cat /proc/drbd
fi
@@ -1017,7 +1017,7 @@ fi
# Gather thermal information provided e.g. by acpi
# At the moment only supporting thermal sensors
-if [ -z "$MK_IN_CONTAINER" ] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
+if [ -z "$IS_DOCKERIZED" ] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
echo '<<<lnx_thermal:sep(124)>>>'
for F in /sys/class/thermal/thermal_zone*; do
line="${F##*/}"
Module: check_mk
Branch: master
Commit: 1df8068f9a6c93c6af207f1b39e998db933a53ec
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1df8068f9a6c93…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 4 09:58:18 2019 +0100
Improve custom host attribute texts
Change-Id: I373179f41887badc18f47a6a2301c8f2c400bb14
---
cmk/gui/wato/pages/custom_attributes.py | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/cmk/gui/wato/pages/custom_attributes.py b/cmk/gui/wato/pages/custom_attributes.py
index dbe0598..e29d3a4 100644
--- a/cmk/gui/wato/pages/custom_attributes.py
+++ b/cmk/gui/wato/pages/custom_attributes.py
@@ -251,16 +251,16 @@ class ModeEditCustomAttr(WatoMode):
self._add_extra_form_sections()
- forms.section(_('Show in Table'))
+ forms.section(_('Show in WATO host table'))
html.help(
- _('This attribute is only visibile on the detail pages by default, but '
- 'you can also make it visible in the overview tables.'))
+ _('This attribute is only visibile on the edit host and folder pages by default, but '
+ 'you can also make it visible in the host overview tables of WATO.'))
html.checkbox(
'show_in_table',
self._attr.get('show_in_table', False),
- label=_("Show the setting of the attribute in the list table"))
+ label=_("Show the setting of the attribute in the WATO host list table"))
- forms.section(_('Add as custom macro'))
+ forms.section(_('Add to monitoring configuration'))
html.help(self._macro_help)
html.checkbox(
'add_custom_macro', self._attr.get('add_custom_macro', False), label=self._macro_label)
@@ -357,14 +357,17 @@ class ModeEditCustomHostAttr(ModeEditCustomAttr):
@property
def _macro_help(self):
- return _("The attribute can be added to the host definition in order to "
- "use it as monitoring macro in different places, for example "
- "as macro in check commands or notifications.")
+ return _(
+ "The attribute can be added to the host definition in order to use it as custom host attribute "
+ "(sometimes called monitoring macro) in different places, for example as in check commands or "
+ "notifications. You can also only display this attribute in the status GUI when enabling this "
+ "option.")
@property
def _macro_label(self):
- return _("Make this variable available as monitoring macro, "
- "e.g. in check commands or in notifications.")
+ return _(
+ "Make this custom attribute available to check commands, notifications and the status GUI"
+ )
def _update_config(self):
_update_host_custom_attrs()
Module: check_mk
Branch: master
Commit: 5297a36d112cd5684c2e62dc83f247ff5dcf4567
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5297a36d112cd5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sun Mar 3 18:02:51 2019 +0100
LXC: Add basic support for Linux containers
The agent is now detecting when it is executed in a Linux container
context and changes it's behaviour depending the environment.
In containers the agent currently does the following:
<ul>
<li>lxc_container_cpu: This check is used instead of the normal CPU
utilization check</li>
<li>zfs filesystems are not excluded for the df section anymore</li>
<li>kernel section is not processed, because it's the host systems
kernel the agent reports information for</li>
<li>drbd section is not processed for the same reason</li>
<li>lnx_thermal section is not processed for the same reason</li>
</ul>
CMK-1561
Change-Id: I94a515be6f7c0fbaf8831d1c62c9563ee0aec759
---
.werks/7226 | 23 +++++++++++++++++++++++
agents/check_mk_agent.linux | 30 +++++++++++++++++++++++-------
checkman/lxc_container_cpu | 14 ++++++++++++++
checks/cpu_util.include | 23 +++++++++++++++++++++++
checks/docker_container_cpu | 26 +-------------------------
checks/lxc_container_cpu | 34 ++++++++++++++++++++++++++++++++++
cmk/utils/man_pages.py | 1 +
7 files changed, 119 insertions(+), 32 deletions(-)
diff --git a/.werks/7226 b/.werks/7226
new file mode 100644
index 0000000..e079c94
--- /dev/null
+++ b/.werks/7226
@@ -0,0 +1,23 @@
+Title: LXC: Add basic support for Linux containers
+Level: 2
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1551686646
+Class: feature
+
+The agent is now detecting when it is executed in a Linux container
+context and changes it's behaviour depending the environment.
+
+In containers the agent currently does the following:
+
+<ul>
+<li>lxc_container_cpu: This check is used instead of the normal CPU
+utilization check</li>
+<li>zfs filesystems are not excluded for the df section anymore</li>
+<li>kernel section is not processed, because it's the host systems
+kernel the agent reports information for</li>
+<li>drbd section is not processed for the same reason</li>
+<li>lnx_thermal section is not processed for the same reason</li>
+</ul>
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index e8b3565..8f1c447 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -80,8 +80,16 @@ fi
# environment.
if [ -f /.dockerenv ]; then
IS_DOCKERIZED=1
+elif grep container=lxc /proc/1/environ >/dev/null 2>&1; then
+ # Works in lxc environment e.g. on Ubuntu bionic, but does not
+ # seem to work in proxmox (see CMK-1561)
+ IS_LXC_CONTAINER=1
+elif grep 'lxcfs /proc/cpuinfo fuse.lxcfs' /proc/mounts >/dev/null 2>&1; then
+ # Seems to work in proxmox
+ IS_LXC_CONTAINER=1
else
unset IS_DOCKERIZED
+ unset IS_LXC_CONTAINER
fi
# Prefer (relatively) new /usr/bin/timeout from coreutils against
@@ -139,11 +147,15 @@ function section_cpu()
fi
NUM_CPUS=$(grep -c -E $CPU_REGEX < /proc/cpuinfo)
- if [ -z "$IS_DOCKERIZED" ]; then
+ if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ]; then
echo '<<<cpu>>>'
echo "$(cat /proc/loadavg) $NUM_CPUS"
else
- echo '<<<docker_container_cpu>>>'
+ if [ -n "$IS_DOCKERIZED" ]; then
+ echo '<<<docker_container_cpu>>>'
+ else
+ echo '<<<lxc_container_cpu>>>'
+ fi
grep "^cpu " /proc/stat
echo "num_cpus $NUM_CPUS"
cat /sys/fs/cgroup/cpuacct/cpuacct.stat
@@ -172,10 +184,14 @@ function section_df()
return
fi
- echo '<<<df>>>'
# The exclusion list is getting a bit of a problem. -l should hide any remote FS but seems
# to be all but working.
- local excludefs="-x smbfs -x cifs -x iso9660 -x udf -x nfsv4 -x nfs -x mvfs -x zfs -x prl_fs -x squashfs"
+ local excludefs="-x smbfs -x cifs -x iso9660 -x udf -x nfsv4 -x nfs -x mvfs -x prl_fs -x squashfs"
+ if [ -n "$IS_LXC_CONTAINER" ]; then
+ excludefs+=" -x zfs"
+ fi
+
+ echo '<<<df>>>'
df -PTlk $excludefs | sed 1d
# df inodes information
@@ -536,7 +552,7 @@ fi
# Performancecounter Kernel
-if [ -z "$IS_DOCKERIZED" ]; then
+if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ]; then
echo '<<<kernel>>>'
date +%s
cat /proc/vmstat /proc/stat
@@ -696,7 +712,7 @@ then
done
fi
-if [ -z "$IS_DOCKERIZED" ] && [ -e /proc/drbd ]; then
+if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ] && [ -e /proc/drbd ]; then
echo '<<<drbd>>>'
cat /proc/drbd
fi
@@ -1017,7 +1033,7 @@ fi
# Gather thermal information provided e.g. by acpi
# At the moment only supporting thermal sensors
-if [ -z "$IS_DOCKERIZED" ] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
+if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
echo '<<<lnx_thermal:sep(124)>>>'
for F in /sys/class/thermal/thermal_zone*; do
line="${F##*/}"
diff --git a/checkman/lxc_container_cpu b/checkman/lxc_container_cpu
new file mode 100644
index 0000000..7711a5f
--- /dev/null
+++ b/checkman/lxc_container_cpu
@@ -0,0 +1,14 @@
+title: Linux container CPU utilization
+agents: linux
+catalog: containerization/lxc
+license: GPL
+distribution: check_mk
+description:
+ This check measures the CPU utilization of a linux container (LXC) during
+ the last check cycle. Levels can be set on the total utilization.
+
+ This check can currently report user and system time.
+
+inventory:
+ One check per container is created if the Check_MK agent is executed
+ in the context of a linux container.
diff --git a/checks/cpu_util.include b/checks/cpu_util.include
index cf862b4..a7a6621 100644
--- a/checks/cpu_util.include
+++ b/checks/cpu_util.include
@@ -248,6 +248,29 @@ def util_perfdata(core, total_perc, core_index, this_time, params):
yield state, infotext, []
+def check_cpu_util_linux_container(_no_item, params, info):
+ if not params:
+ params = {}
+
+ ticks = {}
+ for line in info:
+ if line[0] == "cpu":
+ ticks["total"] = sum(map(int, line[1:]))
+ else:
+ ticks[line[0]] = int(line[1])
+
+ this_time = time.time()
+ node_delta = get_rate("node_total", this_time, ticks["total"])
+ container_delta = get_rate("container", this_time, ticks["user"] + ticks["system"])
+
+ if not node_delta or not container_delta:
+ raise MKCounterWrapped("Too short time difference since last check")
+
+ cpu_usage = (container_delta / node_delta) * ticks["num_cpus"] * 100.0
+
+ return check_cpu_util(cpu_usage, params)
+
+
# .--helper--------------------------------------------------------------.
# | _ _ |
# | | |__ ___| |_ __ ___ _ __ |
diff --git a/checks/docker_container_cpu b/checks/docker_container_cpu
index 41eb43b..64fd386 100644
--- a/checks/docker_container_cpu
+++ b/checks/docker_container_cpu
@@ -24,32 +24,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-
-def check_docker_container_cpu(_no_item, params, info):
- if not params:
- params = {}
-
- ticks = {}
- for line in info:
- if line[0] == "cpu":
- ticks["total"] = sum(map(int, line[1:]))
- else:
- ticks[line[0]] = int(line[1])
-
- this_time = time.time()
- node_delta = get_rate("node_total", this_time, ticks["total"])
- container_delta = get_rate("container", this_time, ticks["user"] + ticks["system"])
-
- if not node_delta or not container_delta:
- raise MKCounterWrapped("Too short time difference since last check")
-
- cpu_usage = (container_delta / node_delta) * ticks["num_cpus"] * 100.0
-
- return check_cpu_util(cpu_usage, params)
-
-
check_info["docker_container_cpu"] = {
- "check_function": check_docker_container_cpu,
+ "check_function": check_cpu_util_linux_container,
"inventory_function": discover_single,
"service_description": "CPU utilization",
"has_perfdata": True,
diff --git a/checks/lxc_container_cpu b/checks/lxc_container_cpu
new file mode 100644
index 0000000..6b04de1
--- /dev/null
+++ b/checks/lxc_container_cpu
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+check_info["lxc_container_cpu"] = {
+ "check_function": check_cpu_util_linux_container,
+ "inventory_function": discover_single,
+ "service_description": "CPU utilization",
+ "has_perfdata": True,
+ "includes": ["cpu_util.include"],
+ "group": "cpu_utilization_os",
+}
diff --git a/cmk/utils/man_pages.py b/cmk/utils/man_pages.py
index 0f9e90b..3f6c9f1 100644
--- a/cmk/utils/man_pages.py
+++ b/cmk/utils/man_pages.py
@@ -233,6 +233,7 @@ catalog_titles = {
"containerization" : "Containerization",
"docker" : "Docker",
"kubernetes" : "Kubernetes",
+ "lxc" : "Linux Container",
"agentless": "Networking checks without agent",
"generic" : "Generic check plugins",
"unsorted" : "Uncategorized",