diff --git a/.gitignore b/.gitignore index 70f3774..be2949c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.so *.d sammler sammler.log diff --git a/Makefile b/Makefile index df5c068..714cdea 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Toplevel Makefile WITH_RRD=yes -PLUGINS := ctstat diskstat load memory mount netdev random rtstat stat uptime vmstat +PLUGINS := ctstat diskstat hwmon load memory mount netdev random rtstat stat uptime vmstat PLUGINS += apache mysql conntrack DESTDIR = diff --git a/plugins/.gitignore b/plugins/.gitignore deleted file mode 100644 index fd9c310..0000000 --- a/plugins/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -*.d diff --git a/plugins/hwmon.c b/plugins/hwmon.c new file mode 100644 index 0000000..c64fe80 --- /dev/null +++ b/plugins/hwmon.c @@ -0,0 +1,124 @@ +/*************************************************************************** + * Copyright (C) 10/2006 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include +#include +#include + +#include "configfile.h" +#include "helper.h" +#include "list.h" +#include "logging.h" +#include "plugins.h" +#include "probe.h" + +struct sammler_plugin plugin; + +struct hwmon_entry { + struct list_head list; + char *name; + char *path; +}; + +static LIST_HEAD(hwmon_list); + +static const char *ds_def = { + "DS:temp:GAUGE:15:0:U " +}; + +static const char * get_ds(int ds_id) +{ + return ds_def; +} + +static int probe(void) +{ + struct hwmon_entry *entry; + list_for_each_entry(entry, &hwmon_list, list) { + FILE *fp = fopen(entry->path, "r"); + if (fp == NULL) { + log_print(LOG_WARN, "plugin hwmon: fopen(%s)", entry->path); + continue; + } + + int temp; + if (fscanf(fp, "%d\n", &temp) != 1) { + log_print(LOG_WARN, "plugin hwmon: fscanf()"); + fclose(fp); + continue; + } + fclose(fp); + + char filename[32]; + int len = snprintf(filename, sizeof(filename), "hwmon-%s.rrd", entry->name); + if (len < 0 || len >= sizeof(filename)) + continue; + + probe_submit(&plugin, filename, 0, "%d", temp); + } + return 0; +} + +static int init_cb(const char *parameter, void *privdata) +{ + char *part[2]; + int ret = strsplit(parameter, ",", part, 2); + if (ret != 2) { + log_print(LOG_ERROR, "p_hwmon: parse error"); + return -1; + } + + struct hwmon_entry *entry = malloc(sizeof(struct hwmon_entry)); + if (entry == NULL) { + log_print(LOG_ERROR, "p_hwmon: out of memory"); + return -1; + } + + entry->name = part[0]; + entry->path = part[1]; + + log_print(LOG_DEBUG, "p_hwmon: added sensor '%s' (%s)", entry->name, entry->path); + list_add_tail(&entry->list, &hwmon_list); + + return 0; +} + +static int init(void) +{ + config_get_strings("p_hwmon", "temp", init_cb, NULL); + return 0; +} + +static int fini(void) +{ + struct hwmon_entry *entry, *tmp; + list_for_each_entry_safe(entry, tmp, &hwmon_list, list) + free(entry); + + return 0; +} + +struct sammler_plugin plugin = { + .name = "hwmon", + .interval = 10, + .init = &init, + .fini = &fini, + .probe = &probe, + .get_ds = &get_ds, +}; diff --git a/sammler.conf b/sammler.conf index f5a3f76..eded3d7 100644 --- a/sammler.conf +++ b/sammler.conf @@ -38,3 +38,7 @@ rra RRA:MIN:0.5:4320:1440 RRA:AVERAGE:0.5:4320:1440 RRA:MAX:0.5:4320:1440 [p_apache] #server name,url,user,password + +[p_hwmon] +#temp board,/sys/class/hwmon/hwmon0/device/temp1_input +#temp cpu,/sys/class/hwmon/hwmon0/device/temp2_input diff --git a/sammler.php b/sammler.php index a224d14..07aa65b 100644 --- a/sammler.php +++ b/sammler.php @@ -171,6 +171,7 @@ function get_rrd_type($filename) { "vmstat", "random", "uptime", + "hwmon", "net", "rtstat", "rtcache", @@ -515,6 +516,16 @@ function show_rrd($conf) { ''; break; + case 'hwmon': + $cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"Temperature\" ". + "DEF:a={$rrdfile}:temp:AVERAGE ". + "CDEF:aa=a,1000,/ ". + 'CDEF:err=a,UN,INF,UNKN,IF '. + 'AREA:err#FFD0D0 '. + 'AREA:aa#00CF00:"Temperature" GPRINT:aa:LAST:"Current\:%8.2lf %s" GPRINT:aa:AVERAGE:"Average\:%8.2lf %s" GPRINT:aa:MAX:"Maximum\:%8.2lf %s" '. + 'LINE1:aa#404040 '; + break; + case 'load': $cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"load\" ". "DEF:a={$rrdfile}:1min:MAX ".