From e14e8b7f5c5bf9d0fe5cc632c6383f304d4ac2ad Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 14 Sep 2016 08:19:41 +0200 Subject: [PATCH] Tree wide: Use compound literals when dealing with value_t. --- src/apache.c | 10 ++--- src/apcups.c | 5 +-- src/apple_sensors.c | 8 +--- src/aquaero.c | 5 +-- src/ascent.c | 5 +-- src/battery.c | 5 +-- src/battery_statefs.c | 5 +-- src/bind.c | 5 +-- src/chrony.c | 5 +-- src/contextswitch.c | 5 +-- src/cpu.c | 32 ++++++--------- src/cpusleep.c | 5 +-- src/curl.c | 19 +++------ src/daemon/plugin.c | 21 ++++------ src/df.c | 5 +-- src/disk.c | 6 +-- src/dns.c | 5 +-- src/email.c | 5 +-- src/ethstat.c | 4 +- src/fhcount.c | 7 +--- src/filecount.c | 9 ++--- src/gps.c | 5 +-- src/hddtemp.c | 5 +-- src/ipc.c | 5 +-- src/ipmi.c | 5 +-- src/iptables.c | 19 ++++----- src/ipvs.c | 5 +-- src/irq.c | 5 +-- src/lpar.c | 5 +-- src/lvm.c | 5 +-- src/madwifi.c | 14 +++---- src/mbmon.c | 5 +-- src/md.c | 5 +-- src/memcachec.c | 9 ++--- src/memcached.c | 14 ++----- src/mic.c | 47 +++++++++------------- src/multimeter.c | 5 +-- src/mysql.c | 103 +++++++++++++++++++++---------------------------- src/netapp.c | 18 ++------- src/netlink.c | 5 +-- src/nginx.c | 2 +- src/ntpd.c | 5 +-- src/nut.c | 7 +--- src/olsrd.c | 5 +-- src/onewire.c | 19 ++++----- src/openldap.c | 8 +--- src/openvpn.c | 7 +--- src/pinba.c | 14 +++---- src/ping.c | 5 +-- src/powerdns.c | 12 +++--- src/processes.c | 10 +---- src/protocols.c | 6 +-- src/redis.c | 5 +-- src/rrdcached.c | 10 ++--- src/sensors.c | 7 +--- src/sigrok.c | 4 +- src/smart.c | 5 +-- src/statsd.c | 25 ++++++------ src/swap.c | 12 ++---- src/target_v5upgrade.c | 21 ++++------ src/teamspeak2.c | 5 +-- src/ted.c | 5 +-- src/tokyotyrant.c | 9 ++--- src/turbostat.c | 4 +- src/uptime.c | 7 +--- src/users.c | 5 +-- src/varnish.c | 14 ++----- src/virt.c | 74 ++++++++++++----------------------- src/vserver.c | 7 +--- src/wireless.c | 5 +-- src/xencpu.c | 12 +++--- src/xmms.c | 5 +-- src/zfs_arc.c | 23 +++-------- src/zookeeper.c | 14 ++----- 74 files changed, 267 insertions(+), 571 deletions(-) diff --git a/src/apache.c b/src/apache.c index c02dfe0f..20a2a3cd 100644 --- a/src/apache.c +++ b/src/apache.c @@ -411,19 +411,15 @@ static void submit_value (const char *type, const char *type_instance, } /* void submit_value */ static void submit_derive (const char *type, const char *type_instance, - derive_t c, apache_t *st) + derive_t d, apache_t *st) { - value_t v; - v.derive = c; - submit_value (type, type_instance, v, st); + submit_value (type, type_instance, (value_t) { .derive = d }, st); } /* void submit_derive */ static void submit_gauge (const char *type, const char *type_instance, gauge_t g, apache_t *st) { - value_t v; - v.gauge = g; - submit_value (type, type_instance, v, st); + submit_value (type, type_instance, (value_t) { .gauge = g }, st); } /* void submit_gauge */ static void submit_scoreboard (char *buf, apache_t *st) diff --git a/src/apcups.c b/src/apcups.c index af5f24c7..821bd65e 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -416,12 +416,9 @@ static int apcups_config (oconfig_item_t *ci) static void apc_submit_generic (const char *type, const char *type_inst, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "apcups", sizeof (vl.plugin)); diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 48fbcb91..06ca7a85 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -83,15 +83,9 @@ static int as_init (void) static void as_submit (const char *type, const char *type_instance, double val) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DEBUG ("type = %s; type_instance = %s; val = %f;", - type, type_instance, val); - - values[0].gauge = val; - - vl.values = values; + vl.values = &(value_t) { .gauge = val }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "apple_sensors", sizeof (vl.plugin)); diff --git a/src/aquaero.c b/src/aquaero.c index 81a4efd4..08271f87 100644 --- a/src/aquaero.c +++ b/src/aquaero.c @@ -60,16 +60,13 @@ static void aquaero_submit (const char *type, const char *type_instance, double value) { const char *instance = conf_device?conf_device:"default"; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* Don't report undefined values. */ if (value == AQ5_FLOAT_UNDEF) return; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/ascent.c b/src/ascent.c index 11bb97f0..16568e6c 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -126,12 +126,9 @@ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static int ascent_submit_gauge (const char *plugin_instance, /* {{{ */ const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ascent", sizeof (vl.plugin)); diff --git a/src/battery.c b/src/battery.c index d227d559..ebf41deb 100644 --- a/src/battery.c +++ b/src/battery.c @@ -78,12 +78,9 @@ static _Bool query_statefs = 0; static void battery_submit2 (char const *plugin_instance, /* {{{ */ char const *type, char const *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "battery", sizeof (vl.plugin)); diff --git a/src/battery_statefs.c b/src/battery_statefs.c index ee739bf5..03729fdb 100644 --- a/src/battery_statefs.c +++ b/src/battery_statefs.c @@ -54,12 +54,9 @@ SOFTWARE. static void battery_submit(const char *type, gauge_t value, const char *type_instance) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "battery", sizeof(vl.plugin)); diff --git a/src/bind.c b/src/bind.c index 9b6b32e3..09de4a3f 100644 --- a/src/bind.c +++ b/src/bind.c @@ -247,12 +247,9 @@ static int memsummary_translation_table_length = static void submit (time_t ts, const char *plugin_instance, /* {{{ */ const char *type, const char *type_instance, value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0] = value; - - vl.values = values; + vl.values = &value; vl.values_len = 1; if (config_parse_time) vl.time = TIME_T_TO_CDTIME_T (ts); diff --git a/src/chrony.c b/src/chrony.c index f6294e49..353ede79 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -677,12 +677,9 @@ ntohf(tFloat p_float) static void chrony_push_data(const char *p_type, const char *p_type_inst, double p_value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = p_value; /* TODO: Check type??? (counter, gauge, derive, absolute) */ - - vl.values = values; + vl.values = &(value_t) { .gauge = p_value }; vl.values_len = 1; /* XXX: Shall g_chrony_host/g_chrony_port be reflected in the plugin's output? */ diff --git a/src/contextswitch.c b/src/contextswitch.c index 76e2a6c0..3bd6d9f5 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -49,12 +49,9 @@ static void cs_submit (derive_t context_switches) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = (derive_t) context_switches; - - vl.values = values; + vl.values = &(value_t) { .derive = context_switches }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "contextswitch", sizeof (vl.plugin)); diff --git a/src/cpu.c b/src/cpu.c index 1ac5b4a3..fbd07143 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -325,12 +325,9 @@ static int init (void) static void submit_value (int cpu_num, int cpu_state, const char *type, value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - memcpy(&values[0], &value, sizeof(value)); - - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); @@ -346,26 +343,22 @@ static void submit_value (int cpu_num, int cpu_state, const char *type, value_t plugin_dispatch_values (&vl); } -static void submit_percent(int cpu_num, int cpu_state, gauge_t percent) +static void submit_percent (int cpu_num, int cpu_state, gauge_t value) { - value_t value; - /* This function is called for all known CPU states, but each read * method will only report a subset. The remaining states are left as * NAN and we ignore them here. */ - if (isnan (percent)) + if (isnan (value)) return; - value.gauge = percent; - submit_value (cpu_num, cpu_state, "percent", value); + submit_value (cpu_num, cpu_state, "percent", + (value_t) { .gauge = value }); } -static void submit_derive(int cpu_num, int cpu_state, derive_t derive) +static void submit_derive (int cpu_num, int cpu_state, derive_t value) { - value_t value; - - value.derive = derive; - submit_value (cpu_num, cpu_state, "cpu", value); + submit_value (cpu_num, cpu_state, "cpu", + (value_t) { .derive = value }); } /* Takes the zero-index number of a CPU and makes sure that the module-global @@ -464,14 +457,11 @@ static void cpu_commit_one (int cpu_num, /* {{{ */ } /* }}} void cpu_commit_one */ /* Commits the number of cores */ -static void cpu_commit_num_cpu (gauge_t num_cpu) /* {{{ */ +static void cpu_commit_num_cpu (gauge_t value) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = num_cpu; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); @@ -555,7 +545,7 @@ static int cpu_stage (size_t cpu_num, size_t state, derive_t d, cdtime_t now) /* int status; cpu_state_t *s; gauge_t rate = NAN; - value_t val = {.derive = d}; + value_t val = { .derive = d }; if (state >= COLLECTD_CPU_STATE_ACTIVE) return (EINVAL); diff --git a/src/cpusleep.c b/src/cpusleep.c index 326c29ce..5de0e470 100644 --- a/src/cpusleep.c +++ b/src/cpusleep.c @@ -37,12 +37,9 @@ #include static void cpusleep_submit(derive_t cpu_sleep) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = cpu_sleep; - - vl.values = values; + vl.values = &(value_t) { .derive = cpu_sleep }; vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "cpusleep", sizeof(vl.plugin)); diff --git a/src/curl.c b/src/curl.c index 74ef13c9..8401e6ca 100644 --- a/src/curl.c +++ b/src/curl.c @@ -608,14 +608,11 @@ static int cc_init (void) /* {{{ */ } /* }}} int cc_init */ static void cc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */ - const cu_match_value_t *mv) + value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0] = mv->value; - - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "curl", sizeof (vl.plugin)); @@ -629,12 +626,9 @@ static void cc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */ static void cc_submit_response_code (const web_page_t *wp, long code) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = code; - - vl.values = values; + vl.values = &(value_t) { .gauge = (gauge_t) code }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "curl", sizeof (vl.plugin)); @@ -647,12 +641,9 @@ static void cc_submit_response_code (const web_page_t *wp, long code) /* {{{ */ static void cc_submit_response_time (const web_page_t *wp, /* {{{ */ cdtime_t response_time) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = CDTIME_T_TO_DOUBLE (response_time); - - vl.values = values; + vl.values = &(value_t) { .gauge = CDTIME_T_TO_DOUBLE (response_time) }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "curl", sizeof (vl.plugin)); @@ -714,7 +705,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ continue; } - cc_submit (wp, wm, mv); + cc_submit (wp, wm, mv->value); match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index c6efc3fe..d4b962fb 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -151,34 +151,28 @@ static const char *plugin_get_dir (void) } static void plugin_update_internal_statistics (void) { /* {{{ */ - derive_t copy_write_queue_length; - value_list_t vl = VALUE_LIST_INIT; - value_t values[2]; - copy_write_queue_length = write_queue_length; + gauge_t copy_write_queue_length = (gauge_t) write_queue_length; /* Initialize `vl' */ - vl.values = values; - vl.values_len = 2; - vl.time = 0; + value_list_t vl = VALUE_LIST_INIT; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "collectd", sizeof (vl.plugin)); - vl.type_instance[0] = 0; - vl.values_len = 1; - /* Write queue */ sstrncpy (vl.plugin_instance, "write_queue", sizeof (vl.plugin_instance)); /* Write queue : queue length */ - vl.values[0].gauge = (gauge_t) copy_write_queue_length; + vl.values = &(value_t) { .gauge = copy_write_queue_length }; + vl.values_len = 1; sstrncpy (vl.type, "queue_length", sizeof (vl.type)); vl.type_instance[0] = 0; plugin_dispatch_values (&vl); /* Write queue : Values dropped (queue length > low limit) */ - vl.values[0].derive = (derive_t) stats_values_dropped; + vl.values = &(value_t) { .gauge = (gauge_t) stats_values_dropped }; + vl.values_len = 1; sstrncpy (vl.type, "derive", sizeof (vl.type)); sstrncpy (vl.type_instance, "dropped", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); @@ -188,7 +182,8 @@ static void plugin_update_internal_statistics (void) { /* {{{ */ sizeof (vl.plugin_instance)); /* Cache : Nb entry in cache tree */ - vl.values[0].gauge = (gauge_t) uc_get_size(); + vl.values = &(value_t) { .gauge = (gauge_t) uc_get_size() }; + vl.values_len = 1; sstrncpy (vl.type, "cache_size", sizeof (vl.type)); vl.type_instance[0] = 0; plugin_dispatch_values (&vl); diff --git a/src/df.c b/src/df.c index af54c92f..632787b2 100644 --- a/src/df.c +++ b/src/df.c @@ -161,12 +161,9 @@ static void df_submit_one (char *plugin_instance, const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "df", sizeof (vl.plugin)); diff --git a/src/disk.c b/src/disk.c index 465b0057..f29029c5 100644 --- a/src/disk.c +++ b/src/disk.c @@ -337,12 +337,9 @@ static void submit_io_time (char const *plugin_instance, derive_t io_time, deriv #if KERNEL_LINUX static void submit_in_progress (char const *disk_name, gauge_t in_progress) { - value_t v; value_list_t vl = VALUE_LIST_INIT; - v.gauge = in_progress; - - vl.values = &v; + vl.values = &(value_t) { .gauge = in_progress }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); @@ -352,7 +349,6 @@ static void submit_in_progress (char const *disk_name, gauge_t in_progress) plugin_dispatch_values (&vl); } - static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops) { double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ()); diff --git a/src/dns.c b/src/dns.c index 0494b4ba..ef80e575 100644 --- a/src/dns.c +++ b/src/dns.c @@ -370,12 +370,9 @@ static int dns_init (void) static void submit_derive (const char *type, const char *type_instance, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "dns", sizeof (vl.plugin)); diff --git a/src/email.c b/src/email.c index 2662da9e..97fbdfe6 100644 --- a/src/email.c +++ b/src/email.c @@ -653,12 +653,9 @@ static int email_shutdown (void) static void email_submit (const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "email", sizeof (vl.plugin)); diff --git a/src/ethstat.c b/src/ethstat.c index d0e77281..f0b8d9f0 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -172,7 +172,6 @@ static void ethstat_submit_value (const char *device, { static c_complain_t complain_no_map = C_COMPLAIN_INIT_STATIC; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; value_map_t *map = NULL; @@ -189,8 +188,7 @@ static void ethstat_submit_value (const char *device, return; } - values[0].derive = value; - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/fhcount.c b/src/fhcount.c index 4b3abff7..a2f5aa8c 100644 --- a/src/fhcount.c +++ b/src/fhcount.c @@ -60,13 +60,9 @@ static int fhcount_config(const char *key, const char *value) { static void fhcount_submit( const char *type, const char *type_instance, gauge_t value) { - - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; // Compose the metric @@ -79,7 +75,6 @@ static void fhcount_submit( plugin_dispatch_values(&vl); } - static int fhcount_read(void) { int numfields = 0; int buffer_len = 60; diff --git a/src/filecount.c b/src/filecount.c index 9de9e6c5..c1e53a2d 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -61,13 +61,10 @@ static size_t directories_num = 0; static void fc_submit_dir (const fc_directory_conf_t *dir) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = (gauge_t) dir->files_num; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = (gauge_t) dir->files_num }; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "filecount", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, dir->instance, sizeof (vl.plugin_instance)); @@ -75,7 +72,7 @@ static void fc_submit_dir (const fc_directory_conf_t *dir) plugin_dispatch_values (&vl); - values[0].gauge = (gauge_t) dir->files_size; + vl.values = &(value_t) { .gauge = (gauge_t) dir->files_size }; sstrncpy (vl.type, "bytes", sizeof (vl.type)); plugin_dispatch_values (&vl); diff --git a/src/gps.c b/src/gps.c index f72cef49..d5b7176b 100644 --- a/src/gps.c +++ b/src/gps.c @@ -220,12 +220,9 @@ quit: */ static void cgps_submit (const char *type, gauge_t value, const char *type_instance) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "gps", sizeof (vl.plugin)); diff --git a/src/hddtemp.c b/src/hddtemp.c index 865ea861..31960b54 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -226,12 +226,9 @@ static int hddtemp_config (const char *key, const char *value) static void hddtemp_submit (char *type_instance, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "hddtemp", sizeof (vl.plugin)); diff --git a/src/ipc.c b/src/ipc.c index b164cdf7..d6d2bbd5 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -97,12 +97,9 @@ static void ipc_submit_g (const char *plugin_instance, const char *type_instance, gauge_t value) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipc", sizeof (vl.plugin)); diff --git a/src/ipmi.c b/src/ipmi.c index ad62299e..a42b787f 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -115,7 +115,6 @@ static void sensor_read_handler (ipmi_sensor_t *sensor, ipmi_states_t __attribute__((unused)) *states, void *user_data) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; c_ipmi_sensor_list_t *list_item = (c_ipmi_sensor_list_t *)user_data; @@ -214,9 +213,7 @@ static void sensor_read_handler (ipmi_sensor_t *sensor, return; } - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/iptables.c b/src/iptables.c index f6911221..35975e6d 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -242,7 +242,6 @@ static int submit6_match (const struct ip6t_entry_match *match, int rule_num) { int status; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* Select the rules to collect */ @@ -260,8 +259,6 @@ static int submit6_match (const struct ip6t_entry_match *match, return (0); } - vl.values = values; - vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ip6tables", sizeof (vl.plugin)); @@ -285,16 +282,16 @@ static int submit6_match (const struct ip6t_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].derive = (derive_t) entry->counters.bcnt; + vl.values = &(value_t) { .derive = (derive_t) entry->counters.bcnt }; + vl.values_len = 1; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].derive = (derive_t) entry->counters.pcnt; + vl.values = &(value_t) { .derive = (derive_t) entry->counters.pcnt }; plugin_dispatch_values (&vl); return (0); -} /* int submit_match */ - +} /* int submit6_match */ /* This needs to return `int' for IPT_MATCH_ITERATE to work. */ static int submit_match (const struct ipt_entry_match *match, @@ -303,7 +300,6 @@ static int submit_match (const struct ipt_entry_match *match, int rule_num) { int status; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* Select the rules to collect */ @@ -321,8 +317,6 @@ static int submit_match (const struct ipt_entry_match *match, return (0); } - vl.values = values; - vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "iptables", sizeof (vl.plugin)); @@ -346,11 +340,12 @@ static int submit_match (const struct ipt_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].derive = (derive_t) entry->counters.bcnt; + vl.values = &(value_t) { .derive = (derive_t) entry->counters.bcnt }; + vl.values_len = 1; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].derive = (derive_t) entry->counters.pcnt; + vl.values = &(value_t) { .derive = (derive_t) entry->counters.pcnt }; plugin_dispatch_values (&vl); return (0); diff --git a/src/ipvs.c b/src/ipvs.c index 92690e88..a68d20fb 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -228,12 +228,9 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) static void cipvs_submit_connections (const char *pi, const char *ti, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/irq.c b/src/irq.c index 0f1d3f0c..cb444a47 100644 --- a/src/irq.c +++ b/src/irq.c @@ -72,15 +72,12 @@ static int irq_config (const char *key, const char *value) static void irq_submit (const char *irq_name, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; if (ignorelist_match (ignorelist, irq_name) != 0) return; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "irq", sizeof (vl.plugin)); diff --git a/src/lpar.c b/src/lpar.c index 5b0bd13d..0e32c834 100644 --- a/src/lpar.c +++ b/src/lpar.c @@ -114,12 +114,9 @@ static int lpar_init (void) static void lpar_submit (const char *type_instance, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = (gauge_t)value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; if (report_by_serial) { diff --git a/src/lvm.c b/src/lvm.c index 6b9a0317..77cb6eb8 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -55,12 +55,9 @@ static char const *get_lv_property_string(lv_t lv, char const *property) static void lvm_submit (char const *plugin_instance, char const *type_instance, uint64_t ivalue) { - value_t v; value_list_t vl = VALUE_LIST_INIT; - v.gauge = (gauge_t) ivalue; - - vl.values = &v; + vl.values = &(value_t) { .gauge = (gauge_t) ivalue }; vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/madwifi.c b/src/madwifi.c index 053bd7fa..f8065a6d 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -538,7 +538,7 @@ static int madwifi_config (const char *key, const char *value) static void submit (const char *dev, const char *type, const char *ti1, - const char *ti2, value_t *val, int len) + const char *ti2, value_t *val, size_t len) { value_list_t vl = VALUE_LIST_INIT; @@ -558,11 +558,9 @@ static void submit (const char *dev, const char *type, const char *ti1, } static void submit_derive (const char *dev, const char *type, const char *ti1, - const char *ti2, derive_t val) + const char *ti2, derive_t value) { - value_t item; - item.derive = val; - submit (dev, type, ti1, ti2, &item, 1); + submit (dev, type, ti1, ti2, &(value_t) { .derive = value }, 1); } static void submit_derive2 (const char *dev, const char *type, const char *ti1, @@ -575,11 +573,9 @@ static void submit_derive2 (const char *dev, const char *type, const char *ti1, } static void submit_gauge (const char *dev, const char *type, const char *ti1, - const char *ti2, gauge_t val) + const char *ti2, gauge_t value) { - value_t item; - item.gauge = val; - submit (dev, type, ti1, ti2, &item, 1); + submit (dev, type, ti1, ti2, &(value_t) { .gauge = value }, 1); } static void submit_antx (const char *dev, const char *name, diff --git a/src/mbmon.c b/src/mbmon.c index 9629b896..b72be896 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -218,12 +218,9 @@ static int mbmon_config (const char *key, const char *value) static void mbmon_submit (const char *type, const char *type_instance, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "mbmon", sizeof (vl.plugin)); diff --git a/src/md.c b/src/md.c index 44cad2ed..db85c46c 100644 --- a/src/md.c +++ b/src/md.c @@ -72,12 +72,9 @@ static int md_config (const char *key, const char *value) static void md_submit (const int minor, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "md", sizeof (vl.plugin)); diff --git a/src/memcachec.c b/src/memcachec.c index dff55461..97e75c0c 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -441,14 +441,11 @@ static int cmc_init (void) /* {{{ */ } /* }}} int cmc_init */ static void cmc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */ - const cu_match_value_t *mv) + value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0] = mv->value; - - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "memcachec", sizeof (vl.plugin)); @@ -496,7 +493,7 @@ static int cmc_read_page (web_page_t *wp) /* {{{ */ continue; } - cmc_submit (wp, wm, mv); + cmc_submit (wp, wm, mv->value); match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ diff --git a/src/memcached.c b/src/memcached.c index d83d4c83..6d503ea7 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -262,13 +262,10 @@ static void memcached_init_vl (value_list_t *vl, memcached_t const *st) static void submit_derive (const char *type, const char *type_inst, derive_t value, memcached_t *st) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - memcached_init_vl (&vl, st); - - values[0].derive = value; - vl.values = values; + memcached_init_vl (&vl, st); + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) @@ -299,13 +296,10 @@ static void submit_derive2 (const char *type, const char *type_inst, static void submit_gauge (const char *type, const char *type_inst, gauge_t value, memcached_t *st) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - memcached_init_vl (&vl, st); - - values[0].gauge = value; - vl.values = values; + memcached_init_vl (&vl, st); + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) diff --git a/src/mic.c b/src/mic.c index 3e31889f..5ec382ba 100644 --- a/src/mic.c +++ b/src/mic.c @@ -150,17 +150,15 @@ static int mic_config (const char *key, const char *value) { return (0); } -static void mic_submit_memory_use(int micnumber, const char *type_instance, U32 val) +static void mic_submit_memory_use(int micnumber, const char *type_instance, U32 value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* MicAccessAPI reports KB's of memory, adjust for this */ - DEBUG("mic plugin: Memory Value Report; %u %lf",val,((gauge_t)val)*1024.0); - values[0].gauge = ((gauge_t)val)*1024.0; + DEBUG("mic plugin: Memory Value Report; %u %lf",value,((gauge_t)value)*1024.0); - vl.values=values; - vl.values_len=1; + vl.values = &(value_t) { .gauge = ((gauge_t)value) * 1024.0 }; + vl.values_len = 1; strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); @@ -190,15 +188,12 @@ static int mic_read_memory(int mic) return (0); } -static void mic_submit_temp(int micnumber, const char *type, gauge_t val) +static void mic_submit_temp(int micnumber, const char *type, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; - - vl.values=values; - vl.values_len=1; + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); @@ -237,15 +232,12 @@ static int mic_read_temps(int mic) } static void mic_submit_cpu(int micnumber, const char *type_instance, - int core, derive_t val) + int core, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = val; - - vl.values=values; - vl.values_len=1; + vl.values = &(value_t) { .derive = value }; + vl.values_len = 1; strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); @@ -296,15 +288,12 @@ static int mic_read_cpu(int mic) return (0); } -static void mic_submit_power(int micnumber, const char *type, const char *type_instance, gauge_t val) +static void mic_submit_power(int micnumber, const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; - - vl.values=values; - vl.values_len=1; + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); @@ -358,13 +347,13 @@ static int mic_read (void) U32 ret; int error; - error=0; - for (int i=0;i= old_hits) && (new_misses >= old_misses)) { uint64_t hits; @@ -717,8 +709,6 @@ static int submit_cache_ratio (const char *host, /* {{{ */ misses = new_misses - old_misses; v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses)); - } else { - v.gauge = NAN; } return (submit_values (host, plugin_inst, "cache_ratio", type_inst, diff --git a/src/netlink.c b/src/netlink.c index cfca46f7..dee62685 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -194,12 +194,9 @@ static int check_ignorelist (const char *dev, static void submit_one (const char *dev, const char *type, const char *type_instance, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin)); diff --git a/src/nginx.c b/src/nginx.c index 16ce3d5f..3850accf 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -210,7 +210,7 @@ static void submit (const char *type, const char *inst, long long value) return; vl.values = values; - vl.values_len = 1; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "nginx", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); diff --git a/src/ntpd.c b/src/ntpd.c index 30f29c97..ccdecd98 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -313,12 +313,9 @@ static int ntpd_config (const char *key, const char *value) static void ntpd_submit (const char *type, const char *type_inst, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ntpd", sizeof (vl.plugin)); diff --git a/src/nut.c b/src/nut.c index b5c6b41b..29074c4e 100644 --- a/src/nut.c +++ b/src/nut.c @@ -120,13 +120,10 @@ static int nut_config (const char *key, const char *value) static void nut_submit (nut_ups_t *ups, const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.host, (strcasecmp (ups->hostname, "localhost") == 0) ? hostname_g diff --git a/src/olsrd.c b/src/olsrd.c index 899ad3e8..3bf71280 100644 --- a/src/olsrd.c +++ b/src/olsrd.c @@ -216,12 +216,9 @@ __attribute__ ((nonnull(2))) static void olsrd_submit (const char *plugin_instance, /* {{{ */ const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/onewire.c b/src/onewire.c index 8bb2d816..0b4b6f56 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -336,7 +336,6 @@ static int cow_load_config (const char *key, const char *value) static int cow_read_values (const char *path, const char *name, const ow_family_features_t *family_info) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; int success = 0; @@ -347,9 +346,6 @@ static int cow_read_values (const char *path, const char *name, return 0; } - vl.values = values; - vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, name, sizeof (vl.plugin_instance)); @@ -381,7 +377,7 @@ static int cow_read_values (const char *path, const char *name, DEBUG ("Read onewire device %s as %s", file, buffer); endptr = NULL; - values[0].gauge = strtod (buffer, &endptr); + gauge_t g = strtod (buffer, &endptr); if (endptr == NULL) { ERROR ("onewire plugin: Buffer is not a number: %s", buffer); @@ -392,6 +388,9 @@ static int cow_read_values (const char *path, const char *name, sstrncpy (vl.type_instance, family_info->features[i].type_instance, sizeof (vl.type_instance)); + vl.values = &(value_t) { .gauge = g }; + vl.values_len = 1; + plugin_dispatch_values (&vl); success++; @@ -495,7 +494,6 @@ static int cow_read_bus (const char *path) static int cow_simple_read (void) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; char *buffer; size_t buffer_size; @@ -507,9 +505,6 @@ static int cow_simple_read (void) /* traverse list and check entries */ for (traverse = direct_list; traverse != NULL; traverse = traverse->next) { - vl.values = values; - vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, traverse->address, sizeof (vl.plugin_instance)); @@ -524,9 +519,8 @@ static int cow_simple_read (void) } DEBUG ("onewire plugin: Read onewire device %s as %s", traverse->path, buffer); - endptr = NULL; - values[0].gauge = strtod (buffer, &endptr); + gauge_t g = strtod (buffer, &endptr); if (endptr == NULL) { ERROR ("onewire plugin: Buffer is not a number: %s", buffer); @@ -536,6 +530,9 @@ static int cow_simple_read (void) sstrncpy (vl.type, traverse->file, sizeof (vl.type)); sstrncpy (vl.type_instance, "", sizeof ("")); + vl.values = &(value_t) { .gauge = g }; + vl.values_len = 1; + plugin_dispatch_values (&vl); free (buffer); } /* for (traverse) */ diff --git a/src/openldap.c b/src/openldap.c index 066dabcd..dd3226d3 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -192,17 +192,13 @@ static void cldap_submit_value (const char *type, const char *type_instance, /* static void cldap_submit_derive (const char *type, const char *type_instance, /* {{{ */ derive_t d, cldap_t *st) { - value_t v; - v.derive = d; - cldap_submit_value (type, type_instance, v, st); + cldap_submit_value (type, type_instance, (value_t) { .derive = d }, st); } /* }}} void cldap_submit_derive */ static void cldap_submit_gauge (const char *type, const char *type_instance, /* {{{ */ gauge_t g, cldap_t *st) { - value_t v; - v.gauge = g; - cldap_submit_value (type, type_instance, v, st); + cldap_submit_value (type, type_instance, (value_t) { .gauge = g }, st); } /* }}} void cldap_submit_gauge */ static int cldap_read_host (user_data_t *ud) /* {{{ */ diff --git a/src/openvpn.c b/src/openvpn.c index 00ae736a..69ab9fb1 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -99,13 +99,10 @@ static int openvpn_strsplit (char *string, char **fields, size_t size) static void numusers_submit (const char *pinst, const char *tinst, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin)); sstrncpy (vl.type, "users", sizeof (vl.type)); diff --git a/src/pinba.c b/src/pinba.c index 8a0902aa..76b765b8 100644 --- a/src/pinba.c +++ b/src/pinba.c @@ -677,38 +677,36 @@ static int plugin_shutdown (void) /* {{{ */ static int plugin_submit (const pinba_statnode_t *res) /* {{{ */ { - value_t value; value_list_t vl = VALUE_LIST_INIT; - vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "pinba", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, res->name, sizeof (vl.plugin_instance)); - value.derive = res->req_count; + vl.values = &(value_t) { .derive = res->req_count }; sstrncpy (vl.type, "total_requests", sizeof (vl.type)); plugin_dispatch_values (&vl); - value.derive = float_counter_get (&res->req_time, /* factor = */ 1000); + vl.values = &(value_t) { .derive = float_counter_get (&res->req_time, /* factor = */ 1000) }; sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type)); plugin_dispatch_values (&vl); - value.derive = res->doc_size; + vl.values = &(value_t) { .derive = res->doc_size }; sstrncpy (vl.type, "total_bytes", sizeof (vl.type)); plugin_dispatch_values (&vl); - value.derive = float_counter_get (&res->ru_utime, /* factor = */ 100); + vl.values = &(value_t) { .derive = float_counter_get (&res->ru_utime, /* factor = */ 100) }; sstrncpy (vl.type, "cpu", sizeof (vl.type)); sstrncpy (vl.type_instance, "user", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); - value.derive = float_counter_get (&res->ru_stime, /* factor = */ 100); + vl.values = &(value_t) { .derive = float_counter_get (&res->ru_stime, /* factor = */ 100) }; sstrncpy (vl.type, "cpu", sizeof (vl.type)); sstrncpy (vl.type_instance, "system", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); - value.gauge = res->mem_peak; + vl.values = &(value_t) { .gauge = res->mem_peak }; sstrncpy (vl.type, "memory", sizeof (vl.type)); sstrncpy (vl.type_instance, "peak", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); diff --git a/src/ping.c b/src/ping.c index 5f66aab3..39e9de51 100644 --- a/src/ping.c +++ b/src/ping.c @@ -615,12 +615,9 @@ static int ping_config (const char *key, const char *value) /* {{{ */ static void submit (const char *host, const char *type, /* {{{ */ gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ping", sizeof (vl.plugin)); diff --git a/src/powerdns.c b/src/powerdns.c index f907d006..eb541800 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -300,10 +300,10 @@ static char *local_sockpath = NULL; /* */ static void submit (const char *plugin_instance, /* {{{ */ - const char *pdns_type, const char *value) + const char *pdns_type, const char *value_str) { value_list_t vl = VALUE_LIST_INIT; - value_t values[1]; + value_t value; const char *type = NULL; const char *type_instance = NULL; @@ -318,7 +318,7 @@ static void submit (const char *plugin_instance, /* {{{ */ if (i >= lookup_table_length) { INFO ("powerdns plugin: submit: Not found in lookup table: %s = %s;", - pdns_type, value); + pdns_type, value_str); return; } @@ -345,14 +345,14 @@ static void submit (const char *plugin_instance, /* {{{ */ return; } - if (0 != parse_value (value, &values[0], ds->ds[0].type)) + if (0 != parse_value (value_str, &value, ds->ds[0].type)) { ERROR ("powerdns plugin: Cannot convert `%s' " - "to a number.", value); + "to a number.", value_str); return; } - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin)); diff --git a/src/processes.c b/src/processes.c index 0513a156..f07785a1 100644 --- a/src/processes.c +++ b/src/processes.c @@ -660,12 +660,9 @@ static int ps_init (void) /* submit global state (e.g.: qty of zombies, running, etc..) */ static void ps_submit_state (const char *state, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "processes", sizeof (vl.plugin)); @@ -784,12 +781,9 @@ static void ps_submit_proc_list (procstat_t *ps) #if KERNEL_LINUX || KERNEL_SOLARIS static void ps_submit_fork_rate (derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof (vl.host)); sstrncpy(vl.plugin, "processes", sizeof (vl.plugin)); diff --git a/src/protocols.c b/src/protocols.c index 208da8b2..ae35c425 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -55,11 +55,11 @@ static ignorelist_t *values_list = NULL; static void submit (const char *protocol_name, const char *str_key, const char *str_value) { - value_t values[1]; + value_t value; value_list_t vl = VALUE_LIST_INIT; int status; - status = parse_value (str_value, values, DS_TYPE_DERIVE); + status = parse_value (str_value, &value, DS_TYPE_DERIVE); if (status != 0) { ERROR ("protocols plugin: Parsing string as integer failed: %s", @@ -67,7 +67,7 @@ static void submit (const char *protocol_name, return; } - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "protocols", sizeof (vl.plugin)); diff --git a/src/redis.c b/src/redis.c index 5214eccc..7f57571e 100644 --- a/src/redis.c +++ b/src/redis.c @@ -252,12 +252,9 @@ static void redis_submit (char *plugin_instance, const char *type, const char *type_instance, value_t value) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0] = value; - - vl.values = values; + vl.values = &value; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "redis", sizeof (vl.plugin)); diff --git a/src/rrdcached.c b/src/rrdcached.c index 04254194..07eac7b6 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -292,8 +292,9 @@ static int rc_read (void) int status; rrdc_stats_t *head; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; + vl.values = &(value_t) { .gauge = NAN }; + vl.values_len = 1; if (daemon_address == NULL) return (-1); @@ -301,9 +302,6 @@ static int rc_read (void) if (!config_collect_stats) return (-1); - vl.values = values; - vl.values_len = 1; - if ((strncmp ("unix:", daemon_address, strlen ("unix:")) == 0) || (daemon_address[0] == '/')) sstrncpy (vl.host, hostname_g, sizeof (vl.host)); @@ -330,9 +328,9 @@ static int rc_read (void) for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next) { if (ptr->type == RRDC_STATS_TYPE_GAUGE) - values[0].gauge = (gauge_t) ptr->value.gauge; + vl.values[0].gauge = (gauge_t) ptr->value.gauge; else if (ptr->type == RRDC_STATS_TYPE_COUNTER) - values[0].counter = (counter_t) ptr->value.counter; + vl.values[0].counter = (counter_t) ptr->value.counter; else continue; diff --git a/src/sensors.c b/src/sensors.c index 4f3d0d60..f13b3ea1 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -481,12 +481,11 @@ static int sensors_shutdown (void) static void sensors_submit (const char *plugin_instance, const char *type, const char *type_instance, - double val) + double value) { char match_key[1024]; int status; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s", @@ -501,9 +500,7 @@ static void sensors_submit (const char *plugin_instance, return; } - values[0].gauge = val; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/sigrok.c b/src/sigrok.c index 40064553..5b850040 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -161,7 +161,6 @@ static void sigrok_feed_callback(const struct sr_dev_inst *sdi, { const struct sr_datafeed_analog *analog; struct config_device *cfdev; - value_t value; value_list_t vl = VALUE_LIST_INIT; /* Find this device's configuration. */ @@ -199,8 +198,7 @@ static void sigrok_feed_callback(const struct sr_dev_inst *sdi, /* Ignore all but the first sample on the first probe. */ analog = packet->payload; - value.gauge = analog->data[0]; - vl.values = &value; + vl.values = &(value_t) { .gauge = analog->data[0] }; vl.values_len = 1; sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "sigrok", sizeof(vl.plugin)); diff --git a/src/smart.c b/src/smart.c index 752cb74c..5b7a34b3 100644 --- a/src/smart.c +++ b/src/smart.c @@ -86,12 +86,9 @@ static int smart_config (const char *key, const char *value) static void smart_submit (const char *dev, const char *type, const char *type_inst, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "smart", sizeof (vl.plugin)); diff --git a/src/statsd.c b/src/statsd.c index 9c138f97..82ae387b 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -752,10 +752,9 @@ static int statsd_metric_clear_set_unsafe (statsd_metric_t *metric) /* {{{ */ /* Must hold metrics_lock when calling this function. */ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metric) /* {{{ */ { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - vl.values = values; + vl.values = &(value_t) { .gauge = NAN }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "statsd", sizeof (vl.plugin)); @@ -772,7 +771,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri sstrncpy (vl.type_instance, name, sizeof (vl.type_instance)); if (metric->type == STATSD_GAUGE) - values[0].gauge = (gauge_t) metric->value; + vl.values[0].gauge = (gauge_t) metric->value; else if (metric->type == STATSD_TIMER) { _Bool have_events = (metric->updates_num > 0); @@ -782,7 +781,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-average", name); - values[0].gauge = have_events + vl.values[0].gauge = have_events ? CDTIME_T_TO_DOUBLE (latency_counter_get_average (metric->latency)) : NAN; plugin_dispatch_values (&vl); @@ -790,7 +789,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri if (conf_timer_lower) { ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-lower", name); - values[0].gauge = have_events + vl.values[0].gauge = have_events ? CDTIME_T_TO_DOUBLE (latency_counter_get_min (metric->latency)) : NAN; plugin_dispatch_values (&vl); @@ -799,7 +798,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri if (conf_timer_upper) { ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-upper", name); - values[0].gauge = have_events + vl.values[0].gauge = have_events ? CDTIME_T_TO_DOUBLE (latency_counter_get_max (metric->latency)) : NAN; plugin_dispatch_values (&vl); @@ -808,7 +807,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri if (conf_timer_sum) { ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-sum", name); - values[0].gauge = have_events + vl.values[0].gauge = have_events ? CDTIME_T_TO_DOUBLE (latency_counter_get_sum (metric->latency)) : NAN; plugin_dispatch_values (&vl); @@ -818,7 +817,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri { ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-percentile-%.0f", name, conf_timer_percentile[i]); - values[0].gauge = have_events + vl.values[0].gauge = have_events ? CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (metric->latency, conf_timer_percentile[i])) : NAN; plugin_dispatch_values (&vl); @@ -830,7 +829,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri sstrncpy (vl.type, "gauge", sizeof (vl.type)); ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-count", name); - values[0].gauge = latency_counter_get_num (metric->latency); + vl.values[0].gauge = latency_counter_get_num (metric->latency); plugin_dispatch_values (&vl); } @@ -840,9 +839,9 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri else if (metric->type == STATSD_SET) { if (metric->set == NULL) - values[0].gauge = 0.0; + vl.values[0].gauge = 0.0; else - values[0].gauge = (gauge_t) c_avl_size (metric->set); + vl.values[0].gauge = (gauge_t) c_avl_size (metric->set); } else { /* STATSD_COUNTER */ gauge_t delta = nearbyint (metric->value); @@ -854,7 +853,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri if (conf_counter_sum) { sstrncpy (vl.type, "count", sizeof (vl.type)); - values[0].gauge = delta; + vl.values[0].gauge = delta; plugin_dispatch_values (&vl); /* restore vl.type */ @@ -866,7 +865,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri metric->value -= delta; metric->counter += (derive_t) delta; - values[0].derive = metric->counter; + vl.values[0].derive = metric->counter; } return (plugin_dispatch_values (&vl)); diff --git a/src/swap.c b/src/swap.c index 9c63e9bb..3cc9516e 100644 --- a/src/swap.c +++ b/src/swap.c @@ -194,11 +194,10 @@ static void swap_submit_usage (char const *plugin_instance, /* {{{ */ gauge_t used, gauge_t free, char const *other_name, gauge_t other_value) { - value_t v[1]; value_list_t vl = VALUE_LIST_INIT; - vl.values = v; - vl.values_len = STATIC_ARRAY_SIZE (v); + vl.values = &(value_t) { .gauge = NAN }; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "swap", sizeof (vl.plugin)); if (plugin_instance != NULL) @@ -222,12 +221,9 @@ static void swap_submit_derive (char const *type_instance, /* {{{ */ derive_t value) { value_list_t vl = VALUE_LIST_INIT; - value_t v[1]; - v[0].derive = value; - - vl.values = v; - vl.values_len = STATIC_ARRAY_SIZE (v); + vl.values = &(value_t) { .derive = value }; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "swap", sizeof (vl.plugin)); sstrncpy (vl.type, "swap_io", sizeof (vl.type)); diff --git a/src/target_v5upgrade.c b/src/target_v5upgrade.c index f7baa3ae..345ca73f 100644 --- a/src/target_v5upgrade.c +++ b/src/target_v5upgrade.c @@ -53,7 +53,6 @@ static void v5_swap_instances (value_list_t *vl) /* {{{ */ static int v5_df (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; /* Can't upgrade if both instances have been set. */ if ((vl->plugin_instance[0] != 0) @@ -64,7 +63,7 @@ static int v5_df (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -113,7 +112,6 @@ static int v5_interface (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_mysql_qcache (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; if (vl->values_len != 5) return (FC_TARGET_STOP); @@ -122,7 +120,7 @@ static int v5_mysql_qcache (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -171,7 +169,6 @@ static int v5_mysql_qcache (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_mysql_threads (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; if (vl->values_len != 4) return (FC_TARGET_STOP); @@ -180,7 +177,7 @@ static int v5_mysql_threads (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -224,7 +221,6 @@ static int v5_mysql_threads (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_zfs_arc_counts (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; _Bool is_hits; if (vl->values_len != 4) @@ -241,7 +237,7 @@ static int v5_zfs_arc_counts (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -322,7 +318,6 @@ static int v5_zfs_arc_l2_bytes (const data_set_t *ds, value_list_t *vl) /* {{{ * static int v5_zfs_arc_l2_size (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; if (vl->values_len != 1) return (FC_TARGET_STOP); @@ -331,7 +326,7 @@ static int v5_zfs_arc_l2_size (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -359,7 +354,6 @@ static int v5_zfs_arc_l2_size (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_zfs_arc_ratio (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; if (vl->values_len != 1) return (FC_TARGET_STOP); @@ -368,7 +362,7 @@ static int v5_zfs_arc_ratio (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; @@ -397,7 +391,6 @@ static int v5_zfs_arc_ratio (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_zfs_arc_size (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_value; if (vl->values_len != 4) return (FC_TARGET_STOP); @@ -406,7 +399,7 @@ static int v5_zfs_arc_size (const data_set_t *ds, value_list_t *vl) /* {{{ */ memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = &new_value; + new_vl.values = &(value_t) { .gauge = NAN }; new_vl.values_len = 1; new_vl.meta = NULL; diff --git a/src/teamspeak2.c b/src/teamspeak2.c index a1cde320..f5eb2687 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -121,12 +121,9 @@ static void tss2_submit_gauge (const char *plugin_instance, /* * Submits a gauge value to the collectd daemon */ - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin)); diff --git a/src/ted.c b/src/ted.c index 5ed6c278..f167546b 100644 --- a/src/ted.c +++ b/src/ted.c @@ -263,12 +263,9 @@ static int ted_open_device (void) static void ted_submit (const char *type, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ted", sizeof (vl.plugin)); diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c index 7c6d9129..154215f8 100644 --- a/src/tokyotyrant.c +++ b/src/tokyotyrant.c @@ -86,15 +86,12 @@ static void printerr (void) ecode, tcrdberrmsg(ecode)); } -static void tt_submit (gauge_t val, const char* type) +static void tt_submit (gauge_t value, const char* type) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.host, config_host, sizeof (vl.host)); sstrncpy (vl.plugin, "tokyotyrant", sizeof (vl.plugin)); diff --git a/src/turbostat.c b/src/turbostat.c index 7b813c9f..e74cba28 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -524,10 +524,8 @@ turbostat_submit (const char *plugin_instance, gauge_t value) { value_list_t vl = VALUE_LIST_INIT; - value_t v; - v.gauge = value; - vl.values = &v; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, PLUGIN_NAME, sizeof (vl.plugin)); diff --git a/src/uptime.c b/src/uptime.c index cbe2f8c5..34c3e85a 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -58,14 +58,11 @@ static time_t boottime; extern kstat_ctl_t *kc; #endif /* #endif HAVE_LIBKSTAT */ -static void uptime_submit (gauge_t uptime) +static void uptime_submit (gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = uptime; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); diff --git a/src/users.c b/src/users.c index 30e0dbe6..ce626ae3 100644 --- a/src/users.c +++ b/src/users.c @@ -45,12 +45,9 @@ static void users_submit (gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "users", sizeof (vl.plugin)); diff --git a/src/varnish.c b/src/varnish.c index c2149126..18f5902f 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -117,22 +117,16 @@ static int varnish_submit_gauge (const char *plugin_instance, /* {{{ */ const char *category, const char *type, const char *type_instance, uint64_t gauge_value) { - value_t value; - - value.gauge = (gauge_t) gauge_value; - - return (varnish_submit (plugin_instance, category, type, type_instance, value)); + return (varnish_submit (plugin_instance, category, type, type_instance, + (value_t) { .gauge = (gauge_t) gauge_value })); } /* }}} int varnish_submit_gauge */ static int varnish_submit_derive (const char *plugin_instance, /* {{{ */ const char *category, const char *type, const char *type_instance, uint64_t derive_value) { - value_t value; - - value.derive = (derive_t) derive_value; - - return (varnish_submit (plugin_instance, category, type, type_instance, value)); + return (varnish_submit (plugin_instance, category, type, type_instance, + (value_t) { .derive = (derive_t) derive_value })); } /* }}} int varnish_submit_derive */ #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 diff --git a/src/virt.c b/src/virt.c index c1c77bcf..431ac413 100644 --- a/src/virt.c +++ b/src/virt.c @@ -223,83 +223,59 @@ init_value_list (value_list_t *vl, virDomainPtr dom) } /* void init_value_list */ -static void -memory_submit (gauge_t memory, virDomainPtr dom) +static void submit (virDomainPtr dom, + char const *type, char const *type_instance, + value_t *values, size_t values_len) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - init_value_list (&vl, dom); - values[0].gauge = memory; - vl.values = values; - vl.values_len = 1; + vl.values_len = values_len; - sstrncpy (vl.type, "memory", sizeof (vl.type)); - sstrncpy (vl.type_instance, "total", sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } static void -memory_stats_submit (gauge_t memory, virDomainPtr dom, int tag_index) +memory_submit (gauge_t value, virDomainPtr dom) +{ + submit (dom, "memory", "total", &(value_t) { .gauge = value }, 1); +} + +static void +memory_stats_submit (gauge_t value, virDomainPtr dom, int tag_index) { static const char *tags[] = { "swap_in", "swap_out", "major_fault", "minor_fault", "unused", "available", "actual_balloon", "rss"}; - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; - - init_value_list (&vl, dom); - - values[0].gauge = memory; - - vl.values = values; - vl.values_len = 1; - - sstrncpy (vl.type, "memory", sizeof (vl.type)); - sstrncpy (vl.type_instance, tags[tag_index], sizeof (vl.type_instance)); + if ((tag_index < 0) || (tag_index >= STATIC_ARRAY_SIZE (tags))) { + ERROR ("virt plugin: Array index out of bounds: tag_index = %d", tag_index); + return; + } - plugin_dispatch_values (&vl); + submit (dom, "memory", tags[tag_index], &(value_t) { .gauge = value }, 1); } static void -cpu_submit (unsigned long long cpu_time, +cpu_submit (unsigned long long value, virDomainPtr dom, const char *type) { - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; - - init_value_list (&vl, dom); - - values[0].derive = cpu_time; - - vl.values = values; - vl.values_len = 1; - - sstrncpy (vl.type, type, sizeof (vl.type)); - - plugin_dispatch_values (&vl); + submit (dom, type, NULL, &(value_t) { .derive = (derive_t) value }, 1); } static void -vcpu_submit (derive_t cpu_time, +vcpu_submit (derive_t value, virDomainPtr dom, int vcpu_nr, const char *type) { - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; - - init_value_list (&vl, dom); + char type_instance[DATA_MAX_NAME_LEN]; - values[0].derive = cpu_time; - vl.values = values; - vl.values_len = 1; - - sstrncpy (vl.type, type, sizeof (vl.type)); - ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); + ssnprintf (type_instance, sizeof (type_instance), "%d", vcpu_nr); - plugin_dispatch_values (&vl); + submit (dom, type, type_instance, &(value_t) { .derive = value }, 1); } static void diff --git a/src/vserver.c b/src/vserver.c index a7305936..c7adc5c4 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -97,13 +97,10 @@ static void submit_gauge (const char *plugin_instance, const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/wireless.c b/src/wireless.c index b9984625..7d57fea9 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -54,12 +54,9 @@ static double wireless_dbm_to_watt (double dbm) static void wireless_submit (const char *plugin_instance, const char *type, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "wireless", sizeof (vl.plugin)); diff --git a/src/xencpu.c b/src/xencpu.c index f1cd9388..93575df2 100644 --- a/src/xencpu.c +++ b/src/xencpu.c @@ -108,14 +108,11 @@ static int xencpu_shutdown (void) return 0; } /* static int xencpu_shutdown */ -static void submit_value (int cpu_num, gauge_t percent) +static void submit_value (int cpu_num, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = percent; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); @@ -145,9 +142,10 @@ static int xencpu_read (void) int status; for (int cpu = 0; cpu < nr_cpus; cpu++) { gauge_t rate = NAN; - value_t value = {.derive = cpu_info[cpu].idletime}; - status = value_to_rate (&rate, value, DS_TYPE_DERIVE, now, &cpu_states[cpu]); + status = value_to_rate (&rate, + (value_t) { .derive = cpu_info[cpu].idletime }, DS_TYPE_DERIVE, + now, &cpu_states[cpu]); if (status == 0) { submit_value(cpu, 100 - rate/10000000); } diff --git a/src/xmms.c b/src/xmms.c index 35359950..2ba30827 100644 --- a/src/xmms.c +++ b/src/xmms.c @@ -35,12 +35,9 @@ static gint xmms_session; static void cxmms_submit (const char *type, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "xmms", sizeof (vl.plugin)); diff --git a/src/zfs_arc.c b/src/zfs_arc.c index 8261282a..e2d2da4c 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -138,7 +138,7 @@ static long long get_zfs_value(kstat_t *dummy __attribute__((unused)), } #endif -static void za_submit (const char* type, const char* type_instance, value_t* values, int values_len) +static void za_submit (const char* type, const char* type_instance, value_t* values, size_t values_len) { value_list_t vl = VALUE_LIST_INIT; @@ -155,45 +155,34 @@ static void za_submit (const char* type, const char* type_instance, value_t* val static void za_submit_gauge (const char* type, const char* type_instance, gauge_t value) { - value_t vv; - - vv.gauge = value; - za_submit (type, type_instance, &vv, 1); + za_submit (type, type_instance, &(value_t) { .gauge = value }, 1); } static int za_read_derive (kstat_t *ksp, const char *kstat_value, const char *type, const char *type_instance) { - long long tmp; - value_t v; - - tmp = get_zfs_value (ksp, (char *)kstat_value); + long long tmp = get_zfs_value (ksp, (char *)kstat_value); if (tmp == -1LL) { WARNING ("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value); return (-1); } - v.derive = (derive_t) tmp; - za_submit (type, type_instance, /* values = */ &v, /* values_num = */ 1); + za_submit (type, type_instance, &(value_t) { .derive = (derive_t) tmp }, /* values_num = */ 1); return (0); } static int za_read_gauge (kstat_t *ksp, const char *kstat_value, const char *type, const char *type_instance) { - long long tmp; - value_t v; - - tmp = get_zfs_value (ksp, (char *)kstat_value); + long long tmp = get_zfs_value (ksp, (char *)kstat_value); if (tmp == -1LL) { WARNING ("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value); return (-1); } - v.gauge = (gauge_t) tmp; - za_submit (type, type_instance, /* values = */ &v, /* values_num = */ 1); + za_submit (type, type_instance, &(value_t) { .gauge = (gauge_t) tmp }, /* values_num = */ 1); return (0); } diff --git a/src/zookeeper.c b/src/zookeeper.c index 84174853..7e551918 100644 --- a/src/zookeeper.c +++ b/src/zookeeper.c @@ -66,14 +66,11 @@ static int zookeeper_config(const char *key, const char *value) return 0; } -static void zookeeper_submit_gauge (const char * type, const char * type_inst, gauge_t val) +static void zookeeper_submit_gauge (const char * type, const char * type_inst, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = val; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "zookeeper", sizeof (vl.plugin)); @@ -84,14 +81,11 @@ static void zookeeper_submit_gauge (const char * type, const char * type_inst, g plugin_dispatch_values (&vl); } /* zookeeper_submit_gauge */ -static void zookeeper_submit_derive (const char * type, const char * type_inst, derive_t val) +static void zookeeper_submit_derive (const char * type, const char * type_inst, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = val; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "zookeeper", sizeof (vl.plugin)); -- 2.11.0