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. |
From: <buc...@us...> - 2008-01-24 05:45:33
|
Revision: 37 http://devmon.svn.sourceforge.net/devmon/?rev=37&view=rev Author: buchanmilne Date: 2008-01-23 21:45:22 -0800 (Wed, 23 Jan 2008) Log Message: ----------- Use strncmp instead of strstr for better parsing Use dbgprintf instead of errprintf for debugging statements Dynamically generate the rrd template from the values devmon sends Modified Paths: -------------- trunk/extras/do_devmon.c Modified: trunk/extras/do_devmon.c =================================================================== --- trunk/extras/do_devmon.c 2008-01-22 06:51:07 UTC (rev 36) +++ trunk/extras/do_devmon.c 2008-01-24 05:45:22 UTC (rev 37) @@ -13,9 +13,8 @@ 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 }; + int maxcols = 20; + char *devmon_params[maxcols+7]; static char *devmon_tpl = NULL; char *eoln, *curline; @@ -28,20 +27,23 @@ curline = msg; while (curline) { char *fsline, *p; - char *columns[20]; + char *columns[maxcols]; int columncount; char *ifname = NULL; int pused = -1; int wanteddisk = 1; long long aused = 0; - int ds[20]; + int ds[maxcols]; 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, "-->")) { + if(!strncmp(curline, "<!--DEVMON",10)) { + in_devmon = 0; + goto nextline; + } + if(in_devmon == 0 && !strncmp(curline, "-->",3)) { in_devmon = 1; goto nextline; } @@ -52,19 +54,26 @@ 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); + if (!strncmp(curline, "DS:",3)) { + devmon_params[0] = "rrdcreate"; + devmon_params[1] = rrdfn; + dbgprintf("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; + dbgprintf("Seeing if column %d that has %s is a DS\n",numds,columns[numds]); + if (strncmp(columns[numds],"DS:",3)) break; + devmon_params[numds+2] = xstrdup(columns[numds]); numds++; } + devmon_params[numds+2] = rra1; + devmon_params[numds+3] = rra2; + devmon_params[numds+4] = rra3; + devmon_params[numds+5] = rra4; + devmon_params[numds+6] = NULL; - /* 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); + dbgprintf("Found %d DS definitions\n",numds); /* Now we should be on to values: * eth0.0 4678222:9966777 @@ -84,7 +93,7 @@ sprintf(dsval,":%d",ds[i]); strcat(rrdvalues,dsval); } - errprintf("Sending from devmon to RRD for %s %s: %s\n",testname,ifname,rrdvalues); + dbgprintf("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; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <buc...@us...> - 2008-02-01 05:53:59
|
Revision: 61 http://devmon.svn.sourceforge.net/devmon/?rev=61&view=rev Author: buchanmilne Date: 2008-01-31 21:53:57 -0800 (Thu, 31 Jan 2008) Log Message: ----------- Allocate dsval before printing values to it Modified Paths: -------------- trunk/extras/do_devmon.c Modified: trunk/extras/do_devmon.c =================================================================== --- trunk/extras/do_devmon.c 2008-01-31 14:01:10 UTC (rev 60) +++ trunk/extras/do_devmon.c 2008-02-01 05:53:57 UTC (rev 61) @@ -85,6 +85,7 @@ dsval = strtok(NULL,":"); ds[i] = atoi(dsval); } + dsval = calloc(numds+1,21); /* 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'; @@ -93,6 +94,7 @@ sprintf(dsval,":%d",ds[i]); strcat(rrdvalues,dsval); } + free(dsval); dbgprintf("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; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <buc...@us...> - 2008-02-01 05:56:28
|
Revision: 62 http://devmon.svn.sourceforge.net/devmon/?rev=62&view=rev Author: buchanmilne Date: 2008-01-31 21:56:24 -0800 (Thu, 31 Jan 2008) Log Message: ----------- Don't do format conversion on the data we get from devmon, thus we don't even need the previous fix (or fill dsval from the ds array). Modified Paths: -------------- trunk/extras/do_devmon.c Modified: trunk/extras/do_devmon.c =================================================================== --- trunk/extras/do_devmon.c 2008-02-01 05:53:57 UTC (rev 61) +++ trunk/extras/do_devmon.c 2008-02-01 05:56:24 UTC (rev 62) @@ -33,7 +33,6 @@ int pused = -1; int wanteddisk = 1; long long aused = 0; - int ds[MAXCOLS]; char *dsval; int i; @@ -80,21 +79,16 @@ */ ifname = xstrdup(columns[0]); dsval = strtok(columns[1],":"); - ds[0] = atoi(dsval); + sprintf(rrdvalues, "%d:", (int)tstamp); + strcat(rrdvalues,dsval); for (i=1;i < numds;i++) { dsval = strtok(NULL,":"); - ds[i] = atoi(dsval); + strcat(rrdvalues,":"); + strcat(rrdvalues,dsval); } - dsval = calloc(numds+1,21); /* 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); - } - free(dsval); dbgprintf("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; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |