Browse Source

MT#55283 use typed GHashTables for metric_types

Change-Id: I097e9bb471b1559561c7ce631fadfe7f068b5ecc
pull/1776/head
Richard Fuchs 2 years ago
parent
commit
812b627bd8
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      daemon/websocket.c

+ 5
- 3
daemon/websocket.c View File

@ -381,12 +381,14 @@ static const char *websocket_http_ping(struct websocket_message *wm) {
} }
TYPED_GHASHTABLE(metric_types_ht, char, void, g_str_hash, g_str_equal, NULL, NULL)
static const char *websocket_http_metrics(struct websocket_message *wm) { static const char *websocket_http_metrics(struct websocket_message *wm) {
ilogs(http, LOG_DEBUG, "Respoding to GET /metrics"); ilogs(http, LOG_DEBUG, "Respoding to GET /metrics");
g_autoptr(stats_metric_q) metrics = statistics_gather_metrics(NULL); g_autoptr(stats_metric_q) metrics = statistics_gather_metrics(NULL);
g_autoptr(GString) outp = g_string_new(""); g_autoptr(GString) outp = g_string_new("");
g_autoptr(GHashTable) metric_types = g_hash_table_new(g_str_hash, g_str_equal);
g_auto(metric_types_ht) metric_types = metric_types_ht_new();
for (__auto_type l = metrics->head; l; l = l->next) { for (__auto_type l = metrics->head; l; l = l->next) {
stats_metric *m = l->data; stats_metric *m = l->data;
@ -397,14 +399,14 @@ static const char *websocket_http_metrics(struct websocket_message *wm) {
if (!m->prom_name) if (!m->prom_name)
continue; continue;
if (!g_hash_table_lookup(metric_types, m->prom_name)) {
if (!t_hash_table_lookup(metric_types, m->prom_name)) {
if (m->descr) if (m->descr)
g_string_append_printf(outp, "# HELP rtpengine_%s %s\n", g_string_append_printf(outp, "# HELP rtpengine_%s %s\n",
m->prom_name, m->descr); m->prom_name, m->descr);
if (m->prom_type) if (m->prom_type)
g_string_append_printf(outp, "# TYPE rtpengine_%s %s\n", g_string_append_printf(outp, "# TYPE rtpengine_%s %s\n",
m->prom_name, m->prom_type); m->prom_name, m->prom_type);
g_hash_table_insert(metric_types, (void *) m->prom_name, (void *) 0x1);
t_hash_table_insert(metric_types, (void *) m->prom_name, (void *) 0x1);
} }
g_string_append_printf(outp, "rtpengine_%s", m->prom_name); g_string_append_printf(outp, "rtpengine_%s", m->prom_name);


Loading…
Cancel
Save