[collectd] cpu module and saving jiffies / OpenBSD
Michael Stapelberg
michael+collectd at stapelberg.de
Fri Aug 1 16:08:32 CEST 2008
Hi,
I'm using collectd on OpenBSD (previously on linux) and I noticed that the cpu
plugin saves broken values. That is, my CPU would be idle 126% ;-).
I'm not sure how you accomplish putting jiffies (from /proc/stat) to rrdtool
and getting percentage values in the file actually... I tried writing a proof
of concept but it didn't work, it'd be nice if you enlighten me.
Anyway, as the CPU stats are collected on OpenBSD using libstatgrab which also
support percentages, I changed the cpu-rrd-files to use GAUGE and cpu.c to
submit a gauge_t. Now the values are accurate. I wonder why this is not by
default a GAUGE? Are there any reasons or should we change it? Patch file for
the libstatgrab-part is attached.
Best regards,
Michael
-------------- next part --------------
diff --git a/cpu.c b/cpu.c
index e9ab783..25f038e 100644
--- a/cpu.c
+++ b/cpu.c
@@ -170,12 +170,12 @@ static int init (void)
return (0);
} /* int init */
-static void submit (int cpu_num, const char *type_instance, counter_t value)
+static void submit (int cpu_num, const char *type_instance, gauge_t gauge)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- values[0].counter = value;
+ values[0].gauge = gauge;
vl.values = values;
vl.values_len = 1;
@@ -386,21 +386,21 @@ static int cpu_read (void)
/* #endif HAVE_SYSCTLBYNAME */
#elif defined(HAVE_LIBSTATGRAB)
- sg_cpu_stats *cs;
- cs = sg_get_cpu_stats ();
+ sg_cpu_percents *cs;
+ cs = sg_get_cpu_percents ();
if (cs == NULL)
{
- ERROR ("cpu plugin: sg_get_cpu_stats failed.");
+ ERROR ("cpu plugin: sg_get_cpu_percents failed.");
return (-1);
}
- submit (0, "idle", (counter_t) cs->idle);
- submit (0, "nice", (counter_t) cs->nice);
- submit (0, "swap", (counter_t) cs->swap);
- submit (0, "system", (counter_t) cs->kernel);
- submit (0, "user", (counter_t) cs->user);
- submit (0, "wait", (counter_t) cs->iowait);
+ submit (0, "idle", (gauge_t) cs->idle);
+ submit (0, "nice", (gauge_t) cs->nice);
+ submit (0, "swap", (gauge_t) cs->swap);
+ submit (0, "system", (gauge_t) cs->kernel);
+ submit (0, "user", (gauge_t) cs->user);
+ submit (0, "wait", (gauge_t) cs->iowait);
#endif /* HAVE_LIBSTATGRAB */
return (0);
-------------- next part --------------
diff --git a/types.db b/types.db
index 9d814ad..673684d 100644
--- a/types.db
+++ b/types.db
@@ -9,7 +9,7 @@ charge value:GAUGE:0:U
connections value:COUNTER:0:U
counter value:COUNTER:U:U
cpufreq value:GAUGE:0:U
-cpu value:COUNTER:0:4294967295
+cpu value:GAUGE:0:100
current value:GAUGE:U:U
delay seconds:GAUGE:-1000000:1000000
df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
More information about the collectd
mailing list