From: <buc...@us...> - 2008-01-22 06:51:24
|
Revision: 36 http://devmon.svn.sourceforge.net/devmon/?rev=36&view=rev Author: buchanmilne Date: 2008-01-21 22:51:07 -0800 (Mon, 21 Jan 2008) Log Message: ----------- Initial Hobbit module for devmon Added Paths: ----------- trunk/extras/do_devmon.c Added: trunk/extras/do_devmon.c =================================================================== --- trunk/extras/do_devmon.c (rev 0) +++ trunk/extras/do_devmon.c 2008-01-22 06:51:07 UTC (rev 36) @@ -0,0 +1,99 @@ +/*----------------------------------------------------------------------------*/ +/* Hobbit RRD handler module for Devmon */ +/* */ +/* Copyright (C) 2004-2006 Henrik Storner <he...@hs...> */ +/* Copyright (C) 2008 Buchan Milne */ +/* */ +/* This program is released under the GNU General Public License (GPL), */ +/* version 2. See the file "COPYING" for details. */ +/* */ +/*----------------------------------------------------------------------------*/ + +static char devmon_rcsid[] = "$Id $"; + +int do_devmon_rrd(char *hostname, char *testname, char *msg, time_t tstamp) +{ +/* static char *devmon_params[] = { "rrdcreate", rrdfn, "DS:pct:GAUGE:600:0:100", "DS:used:GAUGE:600:0:U", + rra1, rra2, rra3, rra4, NULL };*/ + char *devmon_params[] = { "rrdcreate", rrdfn, "DS:ds0:COUNTER:600:0:100", "DS:ds1:COUNTER:600:0:U", rra1, rra2, rra3, rra4, NULL }; + static char *devmon_tpl = NULL; + + char *eoln, *curline; + static int ptnsetup = 0; + static pcre *inclpattern = NULL; + static pcre *exclpattern = NULL; + int in_devmon = 1; + int numds = 0; + + curline = msg; + while (curline) { + char *fsline, *p; + char *columns[20]; + int columncount; + char *ifname = NULL; + int pused = -1; + int wanteddisk = 1; + long long aused = 0; + int ds[20]; + char *dsval; + int i; + + eoln = strchr(curline, '\n'); if (eoln) *eoln = '\0'; + + if(strstr(curline, "<!--DEVMON")) in_devmon = 0; + if(in_devmon == 0 && strstr(curline, "-->")) { + in_devmon = 1; + goto nextline; + } + if (in_devmon != 0 ) goto nextline; + + for (columncount=0; (columncount<20); columncount++) columns[columncount] = ""; + fsline = xstrdup(curline); columncount = 0; p = strtok(fsline, " "); + while (p && (columncount < 20)) { columns[columncount++] = p; p = strtok(NULL, " "); } + + /* DS:ds0:COUNTER:600:0:U DS:ds1:COUNTER:600:0:U */ + if (strstr(curline, "DS:")) { + errprintf("Looking for DS defintions in %s\n",curline); + while ( numds < 20) { + errprintf("Seeing if column %d that has %s is a DS\n",numds,columns[numds]); + if (!strstr(columns[numds],"DS:")) break; + numds++; + } + + /* FIXME Create Template from DS tags as above */ + if (devmon_tpl == NULL) devmon_tpl = setup_template(devmon_params); + goto nextline; + } + errprintf("Found %d DS definitions\n",numds); + + /* Now we should be on to values: + * eth0.0 4678222:9966777 + */ + ifname = xstrdup(columns[0]); + dsval = strtok(columns[1],":"); + ds[0] = atoi(dsval); + for (i=1;i < numds;i++) { + dsval = strtok(NULL,":"); + ds[i] = atoi(dsval); + } + /* File names in the format if_load.eth0.0.rrd */ + snprintf(rrdfn, sizeof(rrdfn)-1, "%s.%s.rrd", testname, ifname); + rrdfn[sizeof(rrdfn)-1] = '\0'; + sprintf(rrdvalues, "%d", (int)tstamp); + for (i=0;i<numds;i++) { + sprintf(dsval,":%d",ds[i]); + strcat(rrdvalues,dsval); + } + errprintf("Sending from devmon to RRD for %s %s: %s\n",testname,ifname,rrdvalues); + create_and_update_rrd(hostname, rrdfn, devmon_params, devmon_tpl); + if (ifname) { xfree(ifname); ifname = NULL; } + + if (eoln) *eoln = '\n'; + xfree(fsline); + +nextline: + curline = (eoln ? (eoln+1) : NULL); + } + + return 0; +} Property changes on: trunk/extras/do_devmon.c ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |