summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2bb1a06)
raw | patch | inline | side by side (parent: 2bb1a06)
author | octo <octo> | |
Mon, 23 Jan 2006 09:54:54 +0000 (09:54 +0000) | ||
committer | octo <octo> | |
Mon, 23 Jan 2006 09:54:54 +0000 (09:54 +0000) |
ChangeLog | patch | blob | history | |
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/battery.c | [new file with mode: 0644] | patch | blob |
diff --git a/ChangeLog b/ChangeLog
index bd8bd412b02dabe0c247d5c2d3d349ebc9aeb92a..df2ddc850686f6c1c8af8dc549d1e03cf9de57d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2006-01-23, Version 3.7.0
+ * The `battery' plugin has been added. It collects information about
+ laptop batteries..
+
2006-01-20, Version 3.6.1
* Due to a bug in `configure.in' all modules and the binary were
linked against `libmysqlclient'. This issue is solved by this
plugins.
* A `df' plugin has been added.
* A `mysql' plugin has been added.
- * The `plugin' module doesn't entirely give up hope when a socket
- error occured, but will back of and increase the intervals between
- tries.
+ * The `ping' plugin doesn't entirely give up hope when a socket error
+ occured, but will back of and increase the intervals between tries.
+
+2006-01-21, Version 3.5.2
+ * Fixed yet another bug in the signal handling.. Stupid typo..
+ * Improved the ping plugin to not give up on socket errors (backport
+ from 3.6.0).
2005-12-18, Version 3.5.1
* The PID-file is now deleted correctly when shutting down the daemon.
diff --git a/configure.in b/configure.in
index a6e830fb718db7b3544740a2f059adc44caeaf5d..e7e2ea5aee5624ad6d9f3f9f6d4565ff3d095aa0 100644 (file)
--- a/configure.in
+++ b/configure.in
m4_divert_once([HELP_ENABLE], [
collectd modules:])
+AC_COLLECTD([battery], [disable], [module], [battery statistics])
AC_COLLECTD([cpu], [disable], [module], [cpu usage statistics])
AC_COLLECTD([cpufreq], [disable], [module], [system cpu frequency statistics])
AC_COLLECTD([disk], [disable], [module], [disk/partition statistics])
daemon mode . . . . $enable_daemon
Modules:
+ battery . . . . . . $enable_battery
cpu . . . . . . . . $enable_cpu
cpufreq . . . . . . $enable_cpufreq
df . . . . . . . . $enable_df
diff --git a/src/Makefile.am b/src/Makefile.am
index 236821eb8c115fecddd45133d5ab24a55af7128e..b959eb8b29fc3b389d8d9f2b4f53dc347ebfbd86 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
pkglib_LTLIBRARIES =
+if BUILD_MODULE_BATTERY
+pkglib_LTLIBRARIES += battery.la
+battery_la_SOURCES = battery.c battery.h
+battery_la_LDFLAGS = -module -avoid-version
+battery_la_CFLAGS = -Wall -Werror
+collectd_LDADD += "-dlopen" battery.la
+collectd_DEPENDENCIES += battery.la
+endif
+
if BUILD_MODULE_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c cpu.h
diff --git a/src/battery.c b/src/battery.c
--- /dev/null
+++ b/src/battery.c
@@ -0,0 +1,202 @@
+/**
+ * collectd - src/battery.c
+ * Copyright (C) 2006 Florian octo Forster
+ *
+ * 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>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#define MODULE_NAME "battery"
+#define BUFSIZE 512
+
+#if defined(KERNEL_LINUX)
+# define BATTERY_HAVE_READ 1
+#else
+# define BATTERY_HAVE_READ 0
+#endif
+
+static char *battery_current_file = "battery-%s/current.rrd";
+static char *battery_voltage_file = "battery-%s/voltage.rrd";
+static char *battery_charge_file = "battery-%s/charge.rrd";
+
+static char *ds_def_current[] =
+{
+ "DS:current:GAUGE:25:0:U",
+ NULL
+};
+static int ds_num_current = 1;
+
+static char *ds_def_voltage[] =
+{
+ "DS:voltage:GAUGE:25:0:U",
+ NULL
+};
+static int ds_num_voltage = 1;
+
+static char *ds_def_charge[] =
+{
+ "DS:charge:GAUGE:25:0:U",
+ NULL
+};
+static int ds_num_charge = 1;
+
+static int battery_pmu_num = 0;
+static char *battery_pmu_file = "/proc/pmu/battery_%i";
+
+static void battery_init (void)
+{
+#if BATTERY_HAVE_READ
+ int len;
+ char filename[BUFSIZE];
+
+ for (battery_pmu_num = 0; ; battery_pmu_num++)
+ {
+ len = snprintf (filename, BUFSIZE, battery_pmu_file, battery_pmu_num);
+
+ if ((len >= BUFSIZE) || (len < 0))
+ break;
+
+ if (access (filename, R_OK))
+ break;
+ }
+#endif
+
+ return;
+}
+
+static void battery_current_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, battery_current_file, val,
+ ds_def_current, ds_num_current);
+}
+
+static void battery_voltage_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, battery_voltage_file, val,
+ ds_def_voltage, ds_num_voltage);
+}
+
+static void battery_charge_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, battery_charge_file, val,
+ ds_def_charge, ds_num_charge);
+}
+
+#if BATTERY_HAVE_READ
+static void battery_submit (int batnum, double current, double voltage, double charge)
+{
+ int len;
+ char buffer[BUFSIZE];
+ char batnum_str[BUFSIZE];
+
+ len = snprintf (batnum_str, BUFSIZE, "%i", batnum);
+ if ((len >= BUFSIZE) || (len < 0))
+ return;
+
+ if (current > 0.0)
+ {
+ len = snprintf (buffer, BUFSIZE, "N:%.3f", current);
+
+ if ((len > 0) && (len < BUFSIZE))
+ plugin_submit ("battery_current", batnum_str, buffer);
+ }
+
+ if (voltage > 0.0)
+ {
+ len = snprintf (buffer, BUFSIZE, "N:%.3f", voltage);
+
+ if ((len > 0) && (len < BUFSIZE))
+ plugin_submit ("battery_voltage", batnum_str, buffer);
+ }
+
+ if (charge > 0.0)
+ {
+ len = snprintf (buffer, BUFSIZE, "N:%.3f", charge);
+
+ if ((len > 0) && (len < BUFSIZE))
+ plugin_submit ("battery_charge", batnum_str, buffer);
+ }
+}
+
+static void battery_read (void)
+{
+#ifdef KERNEL_LINUX
+ FILE *fh;
+ char buffer[BUFSIZE];
+ char filename[BUFSIZE];
+
+ char *fields[8];
+ int numfields;
+
+ int i;
+ int len;
+
+ for (i = 0; i < battery_pmu_num; i++)
+ {
+ double current = 0.0;
+ double voltage = 0.0;
+ double charge = 0.0;
+
+ len = snprintf (filename, BUFSIZE, battery_pmu_file, i);
+
+ if ((len >= BUFSIZE) || (len < 0))
+ continue;
+
+ if ((fh = fopen (filename, "r")) == NULL)
+ continue;
+
+ while (fgets (buffer, BUFSIZE, fh) != NULL)
+ {
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 3)
+ continue;
+
+ if (strcmp ("current", fields[0]) == 0)
+ current = atof (fields[2]) / 1000;
+ else if (strcmp ("voltage", fields[0]) == 0)
+ voltage = atof (fields[2]) / 1000;
+ else if (strcmp ("charge", fields[0]) == 0)
+ charge = atof (fields[2]) / 1000;
+ }
+
+ if ((current != 0.0) || (voltage != 0.0) || (charge != 0.0))
+ battery_submit (i, current, voltage, charge);
+
+ fclose (fh);
+ fh = NULL;
+ }
+#endif /* KERNEL_LINUX */
+}
+#else
+# define battery_read NULL
+#endif /* BATTERY_HAVE_READ */
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, battery_init, battery_read, NULL);
+ plugin_register ("battery_current", NULL, NULL, battery_current_write);
+ plugin_register ("battery_voltage", NULL, NULL, battery_voltage_write);
+ plugin_register ("battery_charge", NULL, NULL, battery_charge_write);
+}
+
+#undef BUFSIZE
+#undef MODULE_NAME