1
/*----------------------------------------------------------------------------*/
2
/* Hobbit RRD handler module. */
4
/* This module handles custom "trends" data. */
6
/* Copyright (C) 2007-2009 Henrik Storner <henrik@hswn.dk> */
8
/* This program is released under the GNU General Public License (GPL), */
9
/* version 2. See the file "COPYING" for details. */
11
/*----------------------------------------------------------------------------*/
13
static char trends_rcsid[] = "$Id: do_trends.c 6125 2009-02-12 13:09:34Z storner $";
16
* This module was inspired by a mail from Stef Coene:
18
* ---------------------------------------------------------------------------
19
* Date: Wed, 17 Jan 2007 14:04:29 +0100
21
* Subject: Re: [hobbit] hobbit monitoring
23
* Just wondering, how hard would it be to create an extra channel for trending?
24
* So you can use the bb client to send "numbers" to the hobbit server together
25
* with some extra control information.
27
* bb <bb server> trends <server name>
28
* <rrd file name> <ds name> <number> <options>
29
* -----------------------------------------------------------------------------
31
* Instead of a dedicated Hobbit channel for this, I decided to use the
32
* existing "data" message type. To use this, send a "data" message to
33
* hobbit formatted like this:
35
* data $MACHINE.trends
37
* DS-definition1 VALUE2
38
* DS-definition2 VALUE2
40
* E.g. to create/update a custom RRD file "weather.rrd" with two
41
* GAUGE datasets "temp" and "wind", with current values "21" and
42
* "8" respectively, send this message:
45
* DS:temp:GAUGE:600:0:U 21
46
* DS:wind:GAUGE:600:0:U 8
50
static int do_trends_rrd(char *hostname, char *testname, char *classname, char *pagepaths, char *msg, time_t tstamp)
52
char *boln, *eoln, *p;
56
creparams = (char **)calloc(1, sizeof(char *));
59
boln = strchr(msg, '\n'); if (boln) boln++;
60
while (boln && *boln) {
61
eoln = strchr(boln, '\n'); if (eoln) *eoln = '\0';
64
/* Flush the current RRD file */
65
if (creparams[0]) create_and_update_rrd(hostname, testname, classname, pagepaths, creparams, NULL);
67
creparams = (char **)realloc(creparams, 1*sizeof(char *));
71
/* Get the RRD filename */
72
p = strchr(boln+1, ']'); if (p) *p = '\0';
73
setupfn("%s", boln+1);
75
/* And setup the initial rrdvalues string */
76
sprintf(rrdvalues, "%d", (int)tstamp);
78
else if (strncmp(boln, "DS:", 3) == 0) {
79
char *valptr = boln + strcspn(boln, " \t");
81
if ((*valptr == ' ') || (*valptr == '\t')) {
82
*valptr = '\0'; valptr += 1 + strspn(valptr+1, " \t");
83
creparams[dscount] = boln;
85
creparams = (char **)realloc(creparams, (1+dscount)*sizeof(char **));
86
creparams[dscount] = NULL;
87
sprintf(rrdvalues+strlen(rrdvalues), ":%s", valptr);
91
boln = (eoln ? eoln+1 : NULL);
94
/* Do the last RRD set */
95
if (creparams[0]) create_and_update_rrd(hostname, testname, classname, pagepaths, creparams, NULL);