From: Florian Forster Date: Thu, 7 Dec 2017 20:51:22 +0000 (+0100) Subject: processes plugin: Make delay metric reporting less repetitive. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=17b81d4fa4eabbb7c029ccf424f43e4d89c27e35;p=collectd.git processes plugin: Make delay metric reporting less repetitive. --- diff --git a/src/processes.c b/src/processes.c index 2e9715dd..26982e4d 100644 --- a/src/processes.c +++ b/src/processes.c @@ -907,34 +907,23 @@ static void ps_submit_proc_list(procstat_t *ps) { * them to a percentage. */ gauge_t const delay_factor = 100.0 / 1000000000.0; - if (!isnan(ps->delay_cpu)) { - sstrncpy(vl.type, "percent", sizeof(vl.type)); - sstrncpy(vl.type_instance, "delay-cpu", sizeof(vl.type_instance)); - vl.values[0].gauge = ps->delay_cpu * delay_factor; - vl.values_len = 1; - plugin_dispatch_values(&vl); - } - - if (!isnan(ps->delay_blkio)) { - sstrncpy(vl.type, "percent", sizeof(vl.type)); - sstrncpy(vl.type_instance, "delay-blkio", sizeof(vl.type_instance)); - vl.values[0].gauge = ps->delay_blkio * delay_factor; - vl.values_len = 1; - plugin_dispatch_values(&vl); - } - - if (!isnan(ps->delay_swapin)) { - sstrncpy(vl.type, "percent", sizeof(vl.type)); - sstrncpy(vl.type_instance, "delay-swapin", sizeof(vl.type_instance)); - vl.values[0].gauge = ps->delay_swapin * delay_factor; - vl.values_len = 1; - plugin_dispatch_values(&vl); - } - - if (!isnan(ps->delay_freepages)) { + struct { + char *type_instance; + gauge_t rate_ns; + } delay_metrics[] = { + {"cpu", ps->delay_cpu}, + {"blkio", ps->delay_blkio}, + {"swapin", ps->delay_swapin}, + {"freepages", ps->delay_freepages}, + }; + for (size_t i = 0; i < STATIC_ARRAY_SIZE(delay_metrics); i++) { + if (isnan(delay_metrics[i].rate_ns)) { + continue; + } sstrncpy(vl.type, "percent", sizeof(vl.type)); - sstrncpy(vl.type_instance, "delay-freepages", sizeof(vl.type_instance)); - vl.values[0].gauge = ps->delay_freepages * delay_factor; + sstrncpy(vl.type_instance, delay_metrics[i].type_instance, + sizeof(vl.type_instance)); + vl.values[0].gauge = delay_metrics[i].rate_ns * delay_factor; vl.values_len = 1; plugin_dispatch_values(&vl); }