From 0ec172537192932c11f7a9cdc799fbc7e49a22e1 Mon Sep 17 00:00:00 2001 From: Eric MacDonald Date: Wed, 12 Dec 2018 17:15:10 -0500 Subject: [PATCH] Fix collectd Memory plugin Strict Mode learning Existing code sets overcommit strict mode to True if any non-zero value is returned from a read of /proc/sys/vm/overcommit_memory. This is incorrect. Strict mode should only be set when the returned value is 2. Change-Id: I2c5328624571bb3b2f478d5a79615650bb92cbd2 Closes-Bug: 1808225 Signed-off-by: Eric MacDonald --- .../collectd-extensions/centos/build_srpm.data | 2 +- monitoring/collectd-extensions/src/memory.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/monitoring/collectd-extensions/centos/build_srpm.data b/monitoring/collectd-extensions/centos/build_srpm.data index cb4885304..fb8be4619 100644 --- a/monitoring/collectd-extensions/centos/build_srpm.data +++ b/monitoring/collectd-extensions/centos/build_srpm.data @@ -16,4 +16,4 @@ COPY_LIST="$PKG_BASE/src/LICENSE \ $PKG_BASE/src/example.py \ $PKG_BASE/src/example.conf" -TIS_PATCH_VER=2 +TIS_PATCH_VER=3 diff --git a/monitoring/collectd-extensions/src/memory.py b/monitoring/collectd-extensions/src/memory.py index 2b436aeca..65e467c1b 100755 --- a/monitoring/collectd-extensions/src/memory.py +++ b/monitoring/collectd-extensions/src/memory.py @@ -74,16 +74,26 @@ def config_func(config): (PLUGIN, obj.cmd)) -# Get the platform cpu list and number of cpus reported by /proc/cpuinfo +# Load the hostname and kernel memory 'overcommit' setting. def init_func(): # get current hostname obj.hostname = os.uname()[1] + # get strict setting + # + # a value of 0 means "heuristic overcommit" + # a value of 1 means "always overcommit" + # a value of 2 means "don't overcommit". + # + # set strict true strict=1 if value is = 2 + # otherwise strict is false strict=0 (default) + fn = '/proc/sys/vm/overcommit_memory' if os.path.exists(fn): with open(fn, 'r') as infile: for line in infile: - obj.strict = int(line) + if int(line) == 2: + obj.strict = 1 break collectd.info("%s strict:%d" % (PLUGIN, obj.strict))