summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 07b05dd)
raw | patch | inline | side by side (parent: 07b05dd)
author | Patrik Weiskircher <weiskircher@inqnet.at> | |
Thu, 1 Oct 2009 11:57:12 +0000 (13:57 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Fri, 2 Oct 2009 07:26:01 +0000 (09:26 +0200) |
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/collectd.conf.in | patch | blob | history | |
src/contextswitch.c | [new file with mode: 0644] | patch | blob |
src/types.db | patch | blob | history |
diff --git a/configure.in b/configure.in
index 08de43b17aeaa08c84e1ec2da411fdc5f0fe0dd1..f091d025d3a7fab497a7c0aca9a60b2d2082422e 100644 (file)
--- a/configure.in
+++ b/configure.in
plugin_battery="no"
plugin_bind="no"
plugin_conntrack="no"
+plugin_contextswitch="no"
plugin_cpu="no"
plugin_cpufreq="no"
plugin_curl_json="no"
then
plugin_battery="yes"
plugin_conntrack="yes"
+ plugin_contextswitch="yes"
plugin_cpu="yes"
plugin_cpufreq="yes"
plugin_disk="yes"
AC_PLUGIN([battery], [$plugin_battery], [Battery statistics])
AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics])
AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics])
+AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics])
AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
AC_PLUGIN([csv], [yes], [CSV output plugin])
battery . . . . . . . $enable_battery
bind . . . . . . . . $enable_bind
conntrack . . . . . . $enable_conntrack
+ contextswitch . . . . $enable_contextswitch
cpu . . . . . . . . . $enable_cpu
cpufreq . . . . . . . $enable_cpufreq
csv . . . . . . . . . $enable_csv
diff --git a/src/Makefile.am b/src/Makefile.am
index 2e9f265e15cea2a2aeb263610c69f177632048e7..9bae902b7c6a7c76bc5a55ede3568026fc599d28 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectd_DEPENDENCIES += conntrack.la
endif
+if BUILD_PLUGIN_CONTEXTSWITCH
+pkglib_LTLIBRARIES += contextswitch.la
+contextswitch_la_SOURCES = contextswitch.c
+contextswitch_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" contextswitch.la
+collectd_DEPENDENCIES += contextswitch.la
+endif
+
if BUILD_PLUGIN_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 8f28f8f3c3c02755f1322b4ccc4857009e24e428..8d14f97393290f344cb3d54d16225720767b0548 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery
#@BUILD_PLUGIN_BIND_TRUE@LoadPlugin bind
#@BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack
+#@BUILD_PLUGIN_CONTEXTSWITCH_TRUE@LoadPlugin contextswitch
@BUILD_PLUGIN_CPU_TRUE@@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu
#@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq
@LOAD_PLUGIN_CSV@LoadPlugin csv
diff --git a/src/contextswitch.c b/src/contextswitch.c
--- /dev/null
+++ b/src/contextswitch.c
@@ -0,0 +1,95 @@
+/**
+ * collectd - src/contextswitch.c
+ * Copyright (C) 2009 Patrik Weiskircher
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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:
+ * Patrik Weiskircher <weiskircher at inqnet.at>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if !KERNEL_LINUX
+# error "No applicable input method."
+#endif
+
+static void cs_submit (unsigned long context_switches)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].derive = context_switches;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "contextswitch", sizeof (vl.plugin));
+ sstrncpy (vl.type, "contextswitch", sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
+}
+
+static int cs_read (void)
+{
+ FILE *fh;
+ char buffer[64];
+ int numfields;
+ char *fields[2];
+ unsigned long result = 0;
+
+ fh = fopen ("/proc/stat", "r");
+ if (fh == NULL) {
+ ERROR ("contextswitch plugin: unable to open /proc/stat: %s",
+ sstrerror (errno, buffer, sizeof (buffer)));
+ return (-1);
+ }
+
+ while (fgets(buffer, sizeof(buffer), fh))
+ {
+ if (strncmp(buffer, "ctxt", 4))
+ continue;
+
+ numfields = strsplit(buffer, fields, 2);
+ if (numfields != 2) {
+ ERROR ("contextswitch plugin: ctxt in /proc/stat contains more than 2 fields.");
+ break;
+ }
+
+ result = strtoul(fields[1], NULL, 10);
+ if (errno == ERANGE && result == ULONG_MAX) {
+ ERROR ("contextswitch plugin: ctxt value in /proc/stat overflows.");
+ break;
+ }
+
+ break;
+ }
+ fclose(fh);
+
+ if (result == 0) {
+ ERROR ("contextswitch plugin: unable to find context switch value.");
+ return -1;
+ }
+
+ cs_submit(result);
+
+ return 0;
+}
+
+void module_register (void)
+{
+ plugin_register_read ("contextswitch", cs_read);
+} /* void module_register */
diff --git a/src/types.db b/src/types.db
index 399dbd23949654a28a99cd570f8d71848ef243ca..0cbd40322ff7eb69d0ae9b6856eca59588da070d 100644 (file)
--- a/src/types.db
+++ b/src/types.db
compression_ratio value:GAUGE:0:2
connections value:COUNTER:0:U
conntrack entropy:GAUGE:0:4294967295
+contextswitch contextswitches:DERIVE:0:U
counter value:COUNTER:U:U
cpufreq value:GAUGE:0:U
cpu value:COUNTER:0:4294967295