X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Frrdtool.c;h=fad1e4b4455d5c6403df9ecc3a09522edade8981;hb=2354eda94fa44c8bcb8e39b24b117e7937110224;hp=024b04e5e928a11daaeb6edb31d0a985a8c1af4d;hpb=7237c726f589df921a26d6951c2d1bf853580c43;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 024b04e5..fad1e4b4 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -195,7 +195,7 @@ static int rra_get (char ***ret, const value_list_t *vl) span = rts[i]; if ((span / ss) < rrarows) - continue; + span = ss * rrarows; if (cdp_len == 0) cdp_len = 1; @@ -591,10 +591,10 @@ static int value_list_to_filename (char *buffer, int buffer_len, if (strlen (vl->type_instance) > 0) status = snprintf (buffer + offset, buffer_len - offset, - "%s-%s.rrd", ds->type, vl->type_instance); + "%s-%s.rrd", vl->type, vl->type_instance); else status = snprintf (buffer + offset, buffer_len - offset, - "%s.rrd", ds->type); + "%s.rrd", vl->type); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; @@ -913,6 +913,11 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl) char values[512]; int status; + if (0 != strcmp (ds->type, vl->type)) { + ERROR ("rrdtool plugin: DS type does not match value list type"); + return -1; + } + if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0) return (-1); @@ -947,6 +952,20 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl) return (status); } /* int rrd_write */ +static int rrd_flush (const int timeout) +{ + pthread_mutex_lock (&cache_lock); + + if (cache == NULL) { + pthread_mutex_unlock (&cache_lock); + return (0); + } + + rrd_cache_flush (timeout); + pthread_mutex_unlock (&cache_lock); + return (0); +} /* int rrd_flush */ + static int rrd_config (const char *key, const char *value) { if (strcasecmp ("CacheTimeout", key) == 0) @@ -1099,12 +1118,7 @@ static int rrd_init (void) if (stepsize < 0) stepsize = 0; if (heartbeat <= 0) - { - if (stepsize > 0) - heartbeat = 2 * stepsize; - else - heartbeat = 0; - } + heartbeat = 2 * stepsize; if ((heartbeat > 0) && (heartbeat < interval_g)) WARNING ("rrdtool plugin: Your `heartbeat' is " @@ -1157,5 +1171,6 @@ void module_register (void) config_keys, config_keys_num); plugin_register_init ("rrdtool", rrd_init); plugin_register_write ("rrdtool", rrd_write); + plugin_register_flush ("rrdtool", rrd_flush); plugin_register_shutdown ("rrdtool", rrd_shutdown); }