diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | doc/rrdbot.conf.5 | 5 | ||||
-rw-r--r-- | tools/rrdbot-create.c | 93 |
4 files changed, 80 insertions, 25 deletions
@@ -1,3 +1,6 @@ +0.9.4 [2009-01-19] + - Add support for creating multiple CFs in rrdbot-create. [Stoned Elipot] + 0.9.3 [2009-01-16] - Add support for printing out MIB name in rrdbot-get diff --git a/configure.in b/configure.in index fef519a..59744e2 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(rrdbot, 0.9.2, stef@memberwebs.com) -AM_INIT_AUTOMAKE(rrdbot, 0.9.2) +AC_INIT(rrdbot, 0.9.4, stef@memberwebs.com) +AM_INIT_AUTOMAKE(rrdbot, 0.9.4) LDFLAGS="$LDFLAGS -L/usr/local/lib" CFLAGS="$CFLAGS -I/usr/local/include" diff --git a/doc/rrdbot.conf.5 b/doc/rrdbot.conf.5 index 0a31ce4..f4fceec 100644 --- a/doc/rrdbot.conf.5 +++ b/doc/rrdbot.conf.5 @@ -160,8 +160,9 @@ The example below describes three archives of "2 per minute for 1 week", rrdbot-create 8 ] .It Ar cf -This is the consolidation function to use to consolidate RRD values when -archiving them. This applies to all fields in the RRD. The valid settings are: +The consolidation functions to use to consolidate RRD values when +archiving them. This applies to all fields in the RRD. There can be multiple +functions specified, separated by commas. The valid functions are: .Bl -tag -width Fl .It Ar AVERAGE Average out the values when archiving them. diff --git a/tools/rrdbot-create.c b/tools/rrdbot-create.c index 23989bb..f79434f 100644 --- a/tools/rrdbot-create.c +++ b/tools/rrdbot-create.c @@ -74,6 +74,10 @@ #define VAL_MIN "MIN" #define VAL_MAX "MAX" #define VAL_LAST "LAST" +#define FLAG_AVERAGE 0x01 +#define FLAG_MIN 0x02 +#define FLAG_MAX 0x04 +#define FLAG_LAST 0x08 #define VAL_SECOND "second" #define VAL_SECONDS "seconds" @@ -137,7 +141,7 @@ typedef struct _create_ctx const char* confname; const char* rrdname; uint interval; - const char *cf; + int cfs; int create; int skip; @@ -211,7 +215,7 @@ context_reset(create_ctx* ctx) } ctx->confname = NULL; - ctx->cf = VAL_AVERAGE; + ctx->cfs = FLAG_AVERAGE; ctx->interval = 0; ctx->create = 0; @@ -316,8 +320,9 @@ create_file(create_ctx* ctx, const char* rrd) field_arg* field; int nargs = 0; uint rows, steps; - int argc, r; + int argc, r, cfs; const char** argv; + char *val_cf; if(!ctx->interval) { @@ -347,14 +352,32 @@ create_file(create_ctx* ctx, const char* rrd) continue; } rows = rra->total / (ctx->interval * steps); - - arg = (create_arg*)xcalloc(sizeof(create_arg)); - snprintf(arg->buf, sizeof(arg->buf), "RRA:%s:0.6:%d:%d", - ctx->cf, steps, rows); - arg->buf[sizeof(arg->buf) - 1] = 0; - arg->next = args; - args = arg; - nargs++; + cfs = ctx->cfs; + while (cfs) { + arg = (create_arg*)xcalloc(sizeof(create_arg)); + if (cfs & FLAG_AVERAGE) { + val_cf = VAL_AVERAGE; + cfs &= ~FLAG_AVERAGE; + } + else if (cfs & FLAG_MIN) { + val_cf = VAL_MIN; + cfs &= ~FLAG_MIN; + } + else if (cfs & FLAG_MAX) { + val_cf = VAL_MAX; + cfs &= ~FLAG_MAX; + } + else { + val_cf = VAL_LAST; + cfs &= ~FLAG_LAST; + } + snprintf(arg->buf, sizeof(arg->buf), "RRA:%s:0.6:%d:%d", + val_cf, steps, rows); + arg->buf[sizeof(arg->buf) - 1] = 0; + arg->next = args; + args = arg; + nargs++; + } } if(!nargs) @@ -514,6 +537,37 @@ unit_to_seconds(char* unit) } static int +add_cfs(create_ctx* ctx, char* value) +{ + char* t; + int cfs = 0; + + while(value && *value) + { + /* Skip any delimiters, and parse next */ + value = value + strspn(value, " \t,"); + t = strchr(value, ','); + if(t) + *(t++) = 0; + strtrim(value); + if (strcmp(value, VAL_AVERAGE) == 0) + cfs |= FLAG_AVERAGE; + else if (strcmp(value, VAL_MIN) == 0) + cfs |= FLAG_MIN; + else if (strcmp(value, VAL_MAX) == 0) + cfs |= FLAG_MAX; + else if (strcmp(value, VAL_LAST) == 0) + cfs |= FLAG_LAST; + else { + warnx("%s: invalid 'cf' value: %s", ctx->confname, value); + return -1; + } + value = t; + } + return cfs; +} + +static int add_rras(create_ctx* ctx, char* value) { uint per; @@ -679,18 +733,15 @@ cfg_value(const char* filename, const char* header, const char* name, if(strcmp(name, CONFIG_CF) == 0) { strupr(value); - if(strcmp(value, VAL_AVERAGE) == 0 || - strcmp(value, VAL_MIN) == 0 || - strcmp(value, VAL_MAX) == 0 || - strcmp(value, VAL_LAST) == 0) - { - ctx->cf = value; - } - else - { - warnx("%s: invalid 'cf' value: %s", ctx->confname, value); + int cfs = add_cfs(ctx, value); + if(cfs < 0) + { ctx->skip = 1; } + else + { + ctx->cfs = cfs; + } ctx->create = 0; return 0; |