From 7dd66e29b6ee0792733bab79e039aff85a12f341 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Luis=20Sanmart=C3=ADn=20Rozada?= Date: Thu, 21 Jan 2021 00:49:57 +0100 Subject: [PATCH] [collectd 6] protocols: migration to v6.0 --- src/protocols.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/protocols.c b/src/protocols.c index 7bfa663c2..a94bdd5a5 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -53,23 +53,31 @@ static ignorelist_t *values_list; */ static void submit(const char *protocol_name, const char *str_key, const char *str_value) { - value_t value; - value_list_t vl = VALUE_LIST_INIT; - int status; + char fam_name[128]; + ssnprintf(fam_name, sizeof(fam_name), "protocols_%s_%s_total", protocol_name, + str_key); - status = parse_value(str_value, &value, DS_TYPE_DERIVE); + metric_family_t fam; + fam.type = METRIC_TYPE_COUNTER; + fam.name = fam_name; + + value_t value; + int status = parse_value(str_value, &value, DS_TYPE_COUNTER); if (status != 0) { return; } - vl.values = &value; - vl.values_len = 1; - sstrncpy(vl.plugin, "protocols", sizeof(vl.plugin)); - sstrncpy(vl.plugin_instance, protocol_name, sizeof(vl.plugin_instance)); - sstrncpy(vl.type, "protocol_counter", sizeof(vl.type)); - sstrncpy(vl.type_instance, str_key, sizeof(vl.type_instance)); + metric_family_metric_append(&fam, (metric_t){ + .value.counter = value.counter, + }); + + status = plugin_dispatch_metric_family(&fam); + if (status != 0) { + ERROR("protocols plugin: plugin_dispatch_metric_family failed: %s", + STRERROR(status)); + } - plugin_dispatch_values(&vl); + metric_family_metric_reset(&fam); } /* void submit */ static int read_file(const char *path) { -- 2.47.2