From 316e98b3dd28090272627a83cb8c9707380611cd Mon Sep 17 00:00:00 2001 From: Rinigus Date: Thu, 4 Aug 2016 00:41:25 +0300 Subject: [PATCH] cpusleep plugin: changing reported type to total_time_in_ms; other small changes --- configure.ac | 8 ++++---- src/collectd.conf.pod | 11 ++++++----- src/cpusleep.c | 13 +++++-------- src/types.db | 1 - 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 949f0407..d66a3b4c 100644 --- a/configure.ac +++ b/configure.ac @@ -759,14 +759,14 @@ AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"]) AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported], [c_cv_have_clock_boottime_monotonic], AC_COMPILE_IFELSE([AC_LANG_PROGRAM( -[[[ +[[ #include -]]], -[[[ +]], +[[ struct timespec b, m; clock_gettime(CLOCK_BOOTTIME, &b ); clock_gettime(CLOCK_MONOTONIC, &m ); -]]] +]] )], [c_cv_have_clock_boottime_monotonic="yes"], [c_cv_have_clock_boottime_monotonic="no"])) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index c3e239b6..16138fef 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1460,11 +1460,12 @@ installed and an "cpu governor" (that's a kernel module) is loaded. =head2 Plugin C This plugin doesn't have any options. It reads CLOCK_BOOTTIME and -CLOCK_MONOTONIC and reports the differences between these -clocks. Since BOOTTIME clock increments while device is suspended and -MONOTONIC clock does not, the derivative of the difference between -these clocks gives the relative amount of time the device has spent in -suspend state. The recorded value is in milliseconds / seconds. +CLOCK_MONOTONIC and reports the difference between these clocks. Since +BOOTTIME clock increments while device is suspended and MONOTONIC +clock does not, the derivative of the difference between these clocks +gives the relative amount of time the device has spent in suspend +state. The recorded value is in milliseconds of sleep per seconds of +wall clock. =head2 Plugin C diff --git a/src/cpusleep.c b/src/cpusleep.c index 7dcde8a1..7cf22272 100644 --- a/src/cpusleep.c +++ b/src/cpusleep.c @@ -27,9 +27,9 @@ * Authors: * rinigus - CPU sleep is reported in milliseconds / s. For that, derive type was - selected and the time difference between BOOT and MONOTONIC clocks - fed to RRD + CPU sleep is reported in milliseconds of sleep per second of wall + time. For that, the time difference between BOOT and MONOTONIC clocks + is reported using derive type. **/ @@ -49,7 +49,7 @@ static void cpusleep_submit(derive_t cpu_sleep) vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof (vl.host)); sstrncpy(vl.plugin, "cpusleep", sizeof (vl.plugin)); - sstrncpy(vl.type, "cpusleep", sizeof (vl.type)); + sstrncpy(vl.type, "total_time_in_ms", sizeof (vl.type)); plugin_dispatch_values(&vl); } @@ -69,12 +69,9 @@ static int cpusleep_read(void) return (-1); } - double db = b.tv_sec + 1e-9 * b.tv_nsec; - double dm = m.tv_sec + 1e-9 * m.tv_nsec; - // to avoid false positives in counter overflow due to reboot, // derive is used - derive_t sleep = (derive_t) ((db-dm) * 1000); + derive_t sleep = (derive_t) ((b.tv_sec - m.tv_sec)*1e3 + (b.tv_nsec - m.tv_nsec)*1e-6); cpusleep_submit(sleep); diff --git a/src/types.db b/src/types.db index e5719bc3..77a9d06f 100644 --- a/src/types.db +++ b/src/types.db @@ -37,7 +37,6 @@ count value:GAUGE:0:U counter value:COUNTER:U:U cpu value:DERIVE:0:U cpufreq value:GAUGE:0:U -cpusleep value:DERIVE:0:U current value:GAUGE:U:U current_connections value:GAUGE:0:U current_sessions value:GAUGE:0:U -- 2.11.0