diff --git a/daemon/mqtt.c b/daemon/mqtt.c index 0e5e84522..d0fa3b28b 100644 --- a/daemon/mqtt.c +++ b/daemon/mqtt.c @@ -479,6 +479,8 @@ static void mqtt_global_stats(JsonBuilder *json) { json_builder_add_int_value(json, m->int_value); else if (m->is_double) json_builder_add_double_value(json, m->double_value); + else if (m->value_raw) + json_builder_add_string_value(json, m->value_raw); else json_builder_add_string_value(json, m->value_short); } diff --git a/daemon/statistics.c b/daemon/statistics.c index 837fd3d18..645ba7e9e 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -227,6 +227,9 @@ static void add_metric(GQueue *ret, const char *label, const char *desc, const c va_start(ap, fmt2); m->value_short = g_strdup_vprintf(fmt1, ap); va_end(ap); + if (m->value_short[0] == '"' && m->value_short[1] != '\0' + && m->value_short[strlen(m->value_short)-1] == '"') + m->value_raw = g_strndup(m->value_short + 1, strlen(m->value_short) - 2); } if (fmt2) { va_start(ap, fmt2); @@ -714,6 +717,7 @@ static void free_stats_metric(void *p) { g_free(m->label); g_free(m->value_long); g_free(m->value_short); + g_free(m->value_raw); g_free(m->prom_label); g_slice_free1(sizeof(*m), m); } @@ -762,15 +766,12 @@ const char *statistics_ng(bencode_item_t *input, bencode_item_t *output) { if (m->is_int) bencode_dictionary_add_integer(dict, bencode_strdup(buf, m->label), m->int_value); - else { - size_t len = strlen(m->value_short); - if (len >= 2 && m->value_short[0] == '"' && m->value_short[len-1] == '"') - bencode_dictionary_add(dict, bencode_strdup(buf, m->label), - bencode_string_len_dup(buf, m->value_short+1, len-2)); - else - bencode_dictionary_add_string_dup(dict, bencode_strdup(buf, m->label), - m->value_short); - } + else if (m->value_raw) + bencode_dictionary_add_string_dup(dict, bencode_strdup(buf, m->label), + m->value_raw); + else + bencode_dictionary_add_string_dup(dict, bencode_strdup(buf, m->label), + m->value_short); continue; } diff --git a/include/statistics.h b/include/statistics.h index d7339dfcc..fb1a19fa0 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -92,6 +92,7 @@ struct stats_metric { char *descr; char *value_short; char *value_long; + char *value_raw; int64_t int_value; double double_value; int is_bracket;