diff --git a/Makefile b/Makefile index c3ce706..cf13ff8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ WITH_RRD=yes PLUGINS := ctstat diskstat hwmon load memory mount netdev random rtstat stat uptime vmstat -PLUGINS += apache mysql conntrack +PLUGINS += apache mysql conntrack alixusv DESTDIR = BINARY_DIR = /usr/local/bin diff --git a/plugins/alixusv.c b/plugins/alixusv.c new file mode 100644 index 0000000..dff2060 --- /dev/null +++ b/plugins/alixusv.c @@ -0,0 +1,106 @@ +/*************************************************************************** + * Copyright (C) 04/2009 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 +#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; + +static const char *socket_path; + +static const char *ds_def = { + "DS:ibat:GAUGE:15:U:U " + "DS:ubat:GAUGE:15:0:U " + "DS:uin:GAUGE:15:0:U " +}; + +static const char * get_ds(int ds_id) +{ + return ds_def; +} + +static int probe(void) +{ + int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd == -1) { + log_print(LOG_WARN, "plugin alixusv: socket()"); + return -1; + } + + struct sockaddr_un addr; + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)); + int len = sizeof(addr.sun_family) + strlen(addr.sun_path); + + if (connect(sockfd, (struct sockaddr *)&addr, len) < 0) { + log_print(LOG_ERROR, "plugin alixusv: connect(%s)", addr.sun_path); + close(sockfd); + return 0; + } + + char buf[64] = "status"; + write(sockfd, buf, strlen(buf)); + + len = read(sockfd, buf, sizeof(buf)); + if (len <= 0) { + log_print(LOG_ERROR, "plugin alixusv: read()"); + close(sockfd); + return -1; + } + + close(sockfd); + + char *field[4]; + if (strsplit(buf, ": \t\n", field, 4) != 4) + return -1; + + int ibat = strtoll(field[1], NULL, 10); + int ubat = strtoll(field[2], NULL, 10); + int uin = strtoll(field[3], NULL, 10); + + probe_submit(&plugin, "alixusv.rrd", 0, "%d:%d:%d", ibat, ubat, uin); + return 0; +} + +static int init(void) +{ + socket_path = config_get_string("p_alixusv", "socket", NULL); + return (socket_path == NULL) ? -1 : 0; +} + +struct sammler_plugin plugin = { + .name = "alixusv", + .interval = 10, + .init = &init, + .probe = &probe, + .get_ds = &get_ds, +}; diff --git a/sammler.conf b/sammler.conf index eded3d7..4fcb969 100644 --- a/sammler.conf +++ b/sammler.conf @@ -24,6 +24,8 @@ plugin random.so #plugin mysql.so #plugin apache.so #plugin conntrack.so +#plugin hwmon.so +#plugin alixusv.so # 1h(10s), 12h(1min), 48h(2min), 14d(15min), 4w(60min), 2y(12h) rra RRA:MIN:0.5:1:360 RRA:AVERAGE:0.5:1:360 RRA:MAX:0.5:1:360 @@ -42,3 +44,6 @@ rra RRA:MIN:0.5:4320:1440 RRA:AVERAGE:0.5:4320:1440 RRA:MAX:0.5:4320:1440 [p_hwmon] #temp board,/sys/class/hwmon/hwmon0/device/temp1_input #temp cpu,/sys/class/hwmon/hwmon0/device/temp2_input + +[p_alixusv] +socket /var/run/alix-usvd.sock diff --git a/sammler.php b/sammler.php index 07aa65b..e3ed8f4 100644 --- a/sammler.php +++ b/sammler.php @@ -172,6 +172,7 @@ function get_rrd_type($filename) { "random", "uptime", "hwmon", + "alixusv", "net", "rtstat", "rtcache", @@ -348,6 +349,23 @@ function show_rrd($conf) { $tmp2 = explode('_', $tmp1[0]); $tmp3 = explode('.', $tmp2[0]); switch ($tmp3[0]) { + case 'alixusv': + $height *= 2; + $cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale --vertical-label=\"Voltage\" ". + "DEF:a={$rrdfile}:ibat:AVERAGE ". + "DEF:b={$rrdfile}:ubat:AVERAGE ". + "DEF:c={$rrdfile}:uin:AVERAGE ". + 'CDEF:aa=a,50,/ '. + 'CDEF:bb=b,1000,/ '. + 'CDEF:cc=c,1000,/ '. + 'CDEF:perr=aa,UN,INF,UNKN,IF CDEF:nerr=aa,UN,-INF,UNKN,IF '. + 'HRULE:0#808080 AREA:perr#FFD0D0 AREA:nerr#FFD0D0 '. + 'LINE2:aa#FF0000:"Ibat " GPRINT:a:LAST:"Current\:%7.0lf%smA" GPRINT:a:MIN:"Minimum\:%7.0lf%smA" GPRINT:a:MAX:"Maximum\:%7.0lf%smA\n" '. + 'LINE2:bb#00CF00:"Ubat " GPRINT:bb:LAST:"Current\:%7.3lf%s V" GPRINT:bb:MIN:"Minimum\:%7.3lf%s V" GPRINT:bb:MAX:"Maximum\:%7.3lf%s V\n" '. + 'LINE2:cc#0000FF:"Uin " GPRINT:cc:LAST:"Current\:%7.3lf%s V" GPRINT:cc:MIN:"Minimum\:%7.3lf%s V" GPRINT:cc:MAX:"Maximum\:%7.3lf%s V\n" '. + ''; + break; + case 'apache': $cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"Workers\" ". "DEF:aa={$rrdfile}:total_accesses:AVERAGE ".