From d8825859c7b31f068899c2d5f8a147ea1ef65750 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 14 Oct 2012 16:37:18 +0200 Subject: [PATCH] Don't use 'interval_g' in any plugins. Rather, use plugin_get_interval () in order to honor any plugin specific interval settings. --- src/amqp.c | 10 ++++++---- src/cpu.c | 2 +- src/dns.c | 2 +- src/exec.c | 5 +++-- src/ipmi.c | 2 +- src/libvirt.c | 2 -- src/memcached.c | 4 ++-- src/modbus.c | 2 +- src/network.c | 1 - src/plugin.c | 10 +++++----- src/plugin.h | 3 +-- src/postgresql.c | 3 ++- src/powerdns.c | 2 +- src/snmp.c | 2 +- src/utils_cmd_putval.c | 2 +- src/utils_complain.c | 4 ++-- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/amqp.c b/src/amqp.c index adf4792b..30a85810 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -543,6 +543,8 @@ static void *camqp_subscribe_thread (void *user_data) /* {{{ */ camqp_config_t *conf = user_data; int status; + cdtime_t interval = plugin_get_interval (); + while (subscriber_threads_running) { amqp_frame_t frame; @@ -552,8 +554,8 @@ static void *camqp_subscribe_thread (void *user_data) /* {{{ */ { ERROR ("amqp plugin: camqp_connect failed. " "Will sleep for %.3f seconds.", - CDTIME_T_TO_DOUBLE (interval_g)); - sleep (interval_g); + CDTIME_T_TO_DOUBLE (interval)); + sleep (interval); continue; } @@ -562,9 +564,9 @@ static void *camqp_subscribe_thread (void *user_data) /* {{{ */ { ERROR ("amqp plugin: amqp_simple_wait_frame failed. " "Will sleep for %.3f seconds.", - CDTIME_T_TO_DOUBLE (interval_g)); + CDTIME_T_TO_DOUBLE (interval)); camqp_close_connection (conf); - sleep (interval_g); + sleep (interval); continue; } diff --git a/src/cpu.c b/src/cpu.c index 12071a2c..5448003a 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -163,7 +163,7 @@ static int init (void) DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors"); INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s"); - cpu_temp_retry_max = 86400 / CDTIME_T_TO_TIME_T (interval_g); + cpu_temp_retry_max = 86400 / CDTIME_T_TO_TIME_T (plugin_get_interval ()); /* #endif PROCESSOR_CPU_LOAD_INFO */ #elif defined(HAVE_LIBKSTAT) diff --git a/src/dns.c b/src/dns.c index 95797f54..08a03692 100644 --- a/src/dns.c +++ b/src/dns.c @@ -228,7 +228,7 @@ static void *dns_child_loop (__attribute__((unused)) void *dummy) pcap_obj = pcap_open_live ((pcap_device != NULL) ? pcap_device : "any", PCAP_SNAPLEN, 0 /* Not promiscuous */, - (int) CDTIME_T_TO_MS (interval_g / 2), + (int) CDTIME_T_TO_MS (plugin_get_interval () / 2), pcap_error); if (pcap_obj == NULL) { diff --git a/src/exec.c b/src/exec.c index 4f6f9dfb..6dfdfe6a 100644 --- a/src/exec.c +++ b/src/exec.c @@ -270,14 +270,15 @@ static void set_environment (void) /* {{{ */ char buffer[1024]; #ifdef HAVE_SETENV - ssnprintf (buffer, sizeof (buffer), "%.3f", CDTIME_T_TO_DOUBLE (interval_g)); + ssnprintf (buffer, sizeof (buffer), "%.3f", + CDTIME_T_TO_DOUBLE (plugin_get_interval ())); setenv ("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1); ssnprintf (buffer, sizeof (buffer), "%s", hostname_g); setenv ("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1); #else ssnprintf (buffer, sizeof (buffer), "COLLECTD_INTERVAL=%.3f", - CDTIME_T_TO_DOUBLE (interval_g)); + CDTIME_T_TO_DOUBLE (plugin_get_interval ())); putenv (buffer); ssnprintf (buffer, sizeof (buffer), "COLLECTD_HOSTNAME=%s", hostname_g); diff --git a/src/ipmi.c b/src/ipmi.c index f341320d..7eafea86 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -664,7 +664,7 @@ static int c_ipmi_init (void) int status; /* Don't send `ADD' notifications during startup (~ 1 minute) */ - time_t iv = CDTIME_T_TO_TIME_T (interval_g); + time_t iv = CDTIME_T_TO_TIME_T (plugin_get_interval ()); c_ipmi_init_in_progress = 1 + (60 / iv); c_ipmi_active = 1; diff --git a/src/libvirt.c b/src/libvirt.c index 774067cd..e076891c 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -139,8 +139,6 @@ init_value_list (value_list_t *vl, virDomainPtr dom) const char *name; char uuid[VIR_UUID_STRING_BUFLEN]; - vl->interval = interval_g; - sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); vl->host[0] = '\0'; diff --git a/src/memcached.c b/src/memcached.c index ee3dbe12..eda1b03b 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -177,13 +177,13 @@ static int memcached_query_daemon (char *buffer, int buffer_size) /* {{{ */ p.revents = 0; status = poll (&p, /* nfds = */ 1, - /* timeout = */ CDTIME_T_TO_MS (interval_g)); + /* timeout = */ CDTIME_T_TO_MS (plugin_get_interval ())); if (status <= 0) { if (status == 0) { ERROR ("memcached: poll(2) timed out after %.3f seconds.", - CDTIME_T_TO_DOUBLE (interval_g)); + CDTIME_T_TO_DOUBLE (plugin_get_interval ())); } else { diff --git a/src/modbus.c b/src/modbus.c index 19848b0b..8a9fe93f 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -237,7 +237,7 @@ static int mb_submit (mb_host_t *host, mb_slave_t *slave, /* {{{ */ return (EINVAL); if (host->interval <= 0) - host->interval = interval_g; + host->interval = plugin_get_interval (); if (slave->instance[0] == 0) ssnprintf (slave->instance, sizeof (slave->instance), "slave_%i", diff --git a/src/network.c b/src/network.c index 840577f5..59c2be7c 100644 --- a/src/network.c +++ b/src/network.c @@ -3225,7 +3225,6 @@ static int network_stats_read (void) /* {{{ */ vl.values = values; vl.values_len = 2; vl.time = 0; - vl.interval = interval_g; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "network", sizeof (vl.plugin)); diff --git a/src/plugin.c b/src/plugin.c index 002955d5..9c2af5d7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -380,7 +380,7 @@ static void *plugin_read_thread (void __attribute__((unused)) *args) { now = cdtime (); - CDTIME_T_TO_TIMESPEC (interval_g, &rf->rf_interval); + CDTIME_T_TO_TIMESPEC (plugin_get_interval (), &rf->rf_interval); rf->rf_effective_interval = rf->rf_interval; @@ -804,10 +804,10 @@ int plugin_register_read (const char *name, int status; if (ctx.interval != 0) { - /* If ctx.interval is not zero (== use interval_g), we need to - * use the "complex" read callback, because only that allows to - * specify a different interval. Wrap the callback using - * read_cb_wrapper(). */ + /* If ctx.interval is not zero (== use the plugin or global + * interval), we need to use the "complex" read callback, + * because only that allows to specify a different interval. + * Wrap the callback using read_cb_wrapper(). */ struct timespec interval; user_data_t user_data; diff --git a/src/plugin.h b/src/plugin.h index e147a938..3f2d98cb 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -99,8 +99,7 @@ struct value_list_s }; typedef struct value_list_s value_list_t; -#define VALUE_LIST_INIT { NULL, 0, 0, \ - (plugin_interval > 0) ? plugin_interval : interval_g, \ +#define VALUE_LIST_INIT { NULL, 0, 0, plugin_get_interval (), \ "localhost", "", "", "", "", NULL } #define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "", NULL } diff --git a/src/postgresql.c b/src/postgresql.c index a8812e21..953bcd83 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -337,7 +337,8 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db, case C_PSQL_PARAM_INTERVAL: ssnprintf (interval, sizeof (interval), "%.3f", (db->interval > 0) - ? CDTIME_T_TO_DOUBLE (db->interval) : interval_g); + ? CDTIME_T_TO_DOUBLE (db->interval) + : plugin_get_interval ()); params[i] = interval; break; default: diff --git a/src/powerdns.c b/src/powerdns.c index a1b23555..a140a126 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -364,7 +364,7 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ break; } - cdt_timeout = interval_g * 3 / 4; + cdt_timeout = plugin_get_interval () * 3 / 4; if (cdt_timeout < TIME_T_TO_CDTIME_T (2)) cdt_timeout = TIME_T_TO_CDTIME_T (2); diff --git a/src/snmp.c b/src/snmp.c index 7a848511..35f51b32 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1525,7 +1525,7 @@ static int csnmp_read_host (user_data_t *ud) host = ud->data; if (host->interval == 0) - host->interval = interval_g; + host->interval = plugin_get_interval (); time_start = cdtime (); diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index dd43337e..4cbc2f1d 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -250,7 +250,7 @@ int create_putval (char *ret, size_t ret_len, /* {{{ */ buffer_ident, (vl->interval > 0) ? CDTIME_T_TO_DOUBLE (vl->interval) - : CDTIME_T_TO_DOUBLE (interval_g), + : CDTIME_T_TO_DOUBLE (plugin_get_interval ()), buffer_values); return (0); diff --git a/src/utils_complain.c b/src/utils_complain.c index 9074b183..328a6ab6 100644 --- a/src/utils_complain.c +++ b/src/utils_complain.c @@ -39,8 +39,8 @@ static int vcomplain (int level, c_complain_t *c, c->last = now; - if (c->interval < interval_g) - c->interval = interval_g; + if (c->interval < plugin_get_interval ()) + c->interval = plugin_get_interval (); else c->interval *= 2; -- 2.11.0