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. |