X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=3b2c54fc9265bb49c05618164af4dc7d8f8ce121;hb=66e0fe82631c8a8e44ffcad8ffd378fab83bc83f;hp=dc06d68a100eac4013b6080d9027df154345135a;hpb=8cf1acdb96d027b1d48c9dfb74fea313e63ceedf;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index dc06d68a..3b2c54fc 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; @@ -285,7 +285,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) if (isnan (d->min)) { - strcpy (min, "U"); + sstrncpy (min, "U", sizeof (min)); } else { @@ -295,7 +295,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) if (isnan (d->max)) { - strcpy (max, "U"); + sstrncpy (max, "U", sizeof (max)); } else { @@ -342,7 +342,7 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up, optind = 0; /* bug in librrd? */ rrd_clear_error (); - status = rrd_create_r (filename, pdp_step, last_up, argc, argv); + status = rrd_create_r (filename, pdp_step, last_up, argc, (void *) argv); if (status != 0) { @@ -360,7 +360,7 @@ static int srrd_update (char *filename, char *template, int argc, char **argv) optind = 0; /* bug in librrd? */ rrd_clear_error (); - status = rrd_update_r (filename, template, argc, argv); + status = rrd_update_r (filename, template, argc, (void *) argv); if (status != 0) { @@ -893,6 +893,19 @@ static int rrd_cache_insert (const char *filename, return (0); } /* int rrd_cache_insert */ +static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr) +{ + int a = *((int *) a_ptr); + int b = *((int *) b_ptr); + + if (a < b) + return (-1); + else if (a > b) + return (1); + else + return (0); +} /* int rrd_compare_numeric */ + static int rrd_write (const data_set_t *ds, const value_list_t *vl) { struct stat statbuf; @@ -934,6 +947,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) @@ -1031,6 +1058,12 @@ static int rrd_config (const char *key, const char *value) if (rra_timespans_custom[rra_timespans_custom_num] != 0) rra_timespans_custom_num++; } /* while (strtok_r) */ + + qsort (/* base = */ rra_timespans_custom, + /* nmemb = */ rra_timespans_custom_num, + /* size = */ sizeof (rra_timespans_custom[0]), + /* compar = */ rrd_compare_numeric); + free (value_copy); } else if (strcasecmp ("XFF", key) == 0) @@ -1080,12 +1113,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 " @@ -1138,5 +1166,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); }