[collectd] [PATCH] system plugin (interrupts/context switches/forks) for collectd 4.7
Jari Takkala
jari.takkala at tradefair.com
Fri Jul 17 15:04:29 CEST 2009
Hello,
I found a patch by Nic Bellamy from January 2007 that adds a system
plugin for collectd to gather total interrupts, context switches, and
forks. The plugin wouldn't apply cleanly to version 4.7.1, so I've made
some modifications and cleaned it up a bit.
I think it's useful to have a plugin to gather totals for these values,
rather than the separate values in the CPU plugin. Can we get this
commited?
Signed-off-by: Jari Takkala <jari.takkala at tradefair.com>
---
diff -ruN collectd-4.7.1.orig/configure.in collectd-4.7.1/configure.in
--- collectd-4.7.1.orig/configure.in 2009-06-02 09:41:03.000000000 +0000
+++ collectd-4.7.1/configure.in 2009-07-16 13:15:26.000000000 +0000
@@ -3318,6 +3318,7 @@
plugin_protocols="no"
plugin_serial="no"
plugin_swap="no"
+plugin_system="no"
plugin_tape="no"
plugin_tcpconns="no"
plugin_ted="no"
@@ -3347,6 +3348,7 @@
plugin_protocols="yes"
plugin_serial="yes"
plugin_swap="yes"
+ plugin_system="yes"
plugin_tcpconns="yes"
plugin_thermal="yes"
plugin_uptime="yes"
@@ -3619,6 +3621,7 @@
AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin])
AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics])
AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin])
+AC_PLUGIN([system], [$plugin_system], [Total interrupts/context switches/forks])
AC_PLUGIN([table], [yes], [Parsing of tabular data])
AC_PLUGIN([tail], [yes], [Parsing of logfiles])
AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics])
@@ -3910,6 +3913,7 @@
snmp . . . . . . . . $enable_snmp
swap . . . . . . . . $enable_swap
syslog . . . . . . . $enable_syslog
+ system . . . . . . . $enable_system
table . . . . . . . . $enable_table
tail . . . . . . . . $enable_tail
tape . . . . . . . . $enable_tape
diff -ruN collectd-4.7.1.orig/src/collectd.conf.in collectd-4.7.1/src/collectd.conf.in
--- collectd-4.7.1.orig/src/collectd.conf.in 2009-06-02 09:41:03.000000000 +0000
+++ collectd-4.7.1/src/collectd.conf.in 2009-07-16 13:15:26.000000000 +0000
@@ -109,6 +109,7 @@
#@BUILD_PLUGIN_SERIAL_TRUE at LoadPlugin serial
#@BUILD_PLUGIN_SNMP_TRUE at LoadPlugin snmp
#@BUILD_PLUGIN_SWAP_TRUE at LoadPlugin swap
+#@BUILD_PLUGIN_SYSTEM at LoadPlugin system
#@BUILD_PLUGIN_TABLE_TRUE at LoadPlugin table
#@BUILD_PLUGIN_TAIL_TRUE at LoadPlugin tail
#@BUILD_PLUGIN_TAPE_TRUE at LoadPlugin tape
diff -ruN collectd-4.7.1.orig/src/Makefile.am collectd-4.7.1/src/Makefile.am
--- collectd-4.7.1.orig/src/Makefile.am 2009-06-02 09:41:03.000000000 +0000
+++ collectd-4.7.1/src/Makefile.am 2009-07-16 13:15:26.000000000 +0000
@@ -826,6 +826,14 @@
collectd_DEPENDENCIES += syslog.la
endif
+if BUILD_PLUGIN_SYSTEM
+pkglib_LTLIBRARIES += system.la
+system_la_SOURCES = system.c
+system_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" system.la
+collectd_DEPENDENCIES += system.la
+endif
+
if BUILD_PLUGIN_TABLE
pkglib_LTLIBRARIES += table.la
table_la_SOURCES = table.c
diff -ruN collectd-4.7.1.orig/src/system.c collectd-4.7.1/src/system.c
--- collectd-4.7.1.orig/src/system.c 1970-01-01 00:00:00.000000000 +0000
+++ collectd-4.7.1/src/system.c 2009-07-16 13:15:32.000000000 +0000
@@ -0,0 +1,107 @@
+/**
+ * collectd - src/system.c
+ * Copyright (C) 2005,2006 Florian octo Forster
+ * Copyright (C) 2007 Vadacom Limited (NZ)
+ * Copyright (C) 2009 Tradefair Limited
+ *
+ * This program 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; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org> (src/cpu.c used as template)
+ * Nic Bellamy <nic dot bellamy at vadacom dot co dot nz>
+ * Jari Takkala <jari dot takkala at tradefair dot com> (adapted for collectd version 4.7)
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#ifndef KERNEL_LINUX
+# error "Sorry, this plugin is Linux-only at this point. Patches welcomed!"
+#endif
+
+#define MODULE_NAME "system"
+
+static void system_submit (counter_t intr, counter_t ctxt, counter_t forks)
+{
+ value_t values[3];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].counter = intr;
+ values[1].counter = ctxt;
+ values[2].counter = forks;
+
+ vl.values = values;
+ vl.values_len = STATIC_ARRAY_SIZE (values);
+ sstrncpy (vl.host, hostname_g, sizeof(vl.host));
+ sstrncpy (vl.plugin, "system", sizeof(vl.plugin));
+ sstrncpy (vl.type, "system", sizeof(vl.type));
+
+ plugin_dispatch_values (&vl);
+}
+
+static int system_read (void)
+{
+ FILE *fh;
+ char buf[BUFSIZ];
+ char *fields[3];
+ int numfields;
+ unsigned long long intr = 0, ctxt = 0, forks = 0;
+
+ if ((fh = fopen ("/proc/stat", "r")) == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("system plugin: fopen (/proc/stat) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));;
+ return (-1);
+ }
+
+ while (fgets (buf, sizeof(buf), fh) != NULL)
+ {
+ if (strncmp (buf, "intr ", 5) == 0) {
+ numfields = strsplit (buf, fields, 3);
+ if (numfields >= 2) {
+ intr = strtoull(fields[1], NULL, 10);
+ }
+ continue;
+ }
+ if (strncmp (buf, "ctxt ", 5) == 0) {
+ numfields = strsplit (buf, fields, 2);
+ if (numfields >= 2) {
+ ctxt = strtoull(fields[1], NULL, 10);
+ }
+ continue;
+ }
+ if (strncmp (buf, "processes ", 10) == 0) {
+ numfields = strsplit (buf, fields, 2);
+ if (numfields >= 2) {
+ forks = strtoull(fields[1], NULL, 10);
+ }
+ continue;
+ }
+ }
+ system_submit (intr, ctxt, forks);
+
+ fclose (fh);
+
+ return (0);
+}
+
+void module_register (void)
+{
+ plugin_register_read (MODULE_NAME, system_read);
+}
+
+#undef MODULE_NAME
diff -ruN collectd-4.7.1.orig/src/types.db collectd-4.7.1/src/types.db
--- collectd-4.7.1.orig/src/types.db 2009-06-02 09:41:03.000000000 +0000
+++ collectd-4.7.1/src/types.db 2009-07-16 13:15:26.000000000 +0000
@@ -109,6 +109,7 @@
spam_check value:GAUGE:0:U
spam_score value:GAUGE:U:U
swap value:GAUGE:0:1099511627776
+system intr:COUNTER:0:U, ctxt:COUNTER:0:U, forks:COUNTER:0:U
tcp_connections value:GAUGE:0:4294967295
temperature value:GAUGE:-273.15:U
time_dispersion seconds:GAUGE:-1000000:1000000
More information about the collectd
mailing list