-/* $OpenBSD: ometric.c,v 1.3 2022/11/30 10:15:01 claudio Exp $ */
+/* $OpenBSD: ometric.c,v 1.4 2022/12/01 09:14:40 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
* value needs to be freed with olabels_free().
*/
static struct olabels *
-olabels_add_extra(struct olabels *ol, const char *key, const char *value)
+olabels_add_extras(struct olabels *ol, const char **keys, const char **values)
{
- const char *keys[2] = { key, NULL };
- const char *values[2] = { value, NULL };
struct olabels *new;
- if (value == NULL || *value == '\0')
- return ol;
-
new = olabels_new(keys, values);
new->next = olabels_ref(ol);
if (om->type != OMT_INFO)
errx(1, "%s incorrect ometric type", __func__);
- if (keys != NULL) {
- extra = olabels_new(keys, values);
- extra->next = olabels_ref(ol);
- }
+ if (keys != NULL)
+ extra = olabels_add_extras(ol, keys, values);
ometric_set_int_value(om, 1, extra != NULL ? extra : ol);
olabels_free(extra);
void
ometric_set_state(struct ometric *om, const char *state, struct olabels *ol)
{
- struct olabels *extra;
size_t i;
int val;
else
val = 0;
- extra = olabels_add_extra(ol, om->name, om->stateset[i]);
- ometric_set_int_value(om, val, extra);
- olabels_free(extra);
+ ometric_set_int_with_labels(om, val, OKV(om->name),
+ OKV(om->stateset[i]), ol);
}
}
* the value is copied into the extra label.
*/
void
-ometric_set_int_with_label(struct ometric *om, uint64_t val, const char *key,
- const char *value, struct olabels *ol)
+ometric_set_int_with_labels(struct ometric *om, uint64_t val,
+ const char **keys, const char **values, struct olabels *ol)
{
struct olabels *extra;
- extra = olabels_add_extra(ol, key, value);
+ extra = olabels_add_extras(ol, keys, values);
ometric_set_int(om, val, extra);
olabels_free(extra);
}
-/* $OpenBSD: output_ometric.c,v 1.4 2022/11/30 10:15:01 claudio Exp $ */
+/* $OpenBSD: output_ometric.c,v 1.5 2022/12/01 09:14:40 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
ometric_set_int(peer_prefixes_transmit, p->stats.prefix_out_cnt, ol);
ometric_set_int(peer_prefixes_receive, p->stats.prefix_cnt, ol);
- ometric_set_int_with_label(peer_message_transmit,
- p->stats.msg_sent_open, "message", "open", ol);
- ometric_set_int_with_label(peer_message_transmit,
- p->stats.msg_sent_notification, "message", "notification", ol);
- ometric_set_int_with_label(peer_message_transmit,
- p->stats.msg_sent_update, "message", "update", ol);
- ometric_set_int_with_label(peer_message_transmit,
- p->stats.msg_sent_keepalive, "message", "keepalive", ol);
- ometric_set_int_with_label(peer_message_transmit,
- p->stats.msg_sent_rrefresh, "message", "route_refresh", ol);
-
- ometric_set_int_with_label(peer_message_recieve,
- p->stats.msg_rcvd_open, "message", "open", ol);
- ometric_set_int_with_label(peer_message_recieve,
- p->stats.msg_rcvd_notification, "message", "notification", ol);
- ometric_set_int_with_label(peer_message_recieve,
- p->stats.msg_rcvd_update, "message", "update", ol);
- ometric_set_int_with_label(peer_message_recieve,
- p->stats.msg_rcvd_keepalive, "message", "keepalive", ol);
- ometric_set_int_with_label(peer_message_recieve,
- p->stats.msg_rcvd_rrefresh, "message", "route_refresh", ol);
+ ometric_set_int_with_labels(peer_message_transmit,
+ p->stats.msg_sent_open, OKV("messages"), OKV("open"), ol);
+ ometric_set_int_with_labels(peer_message_transmit,
+ p->stats.msg_sent_notification, OKV("messages"),
+ OKV("notification"), ol);
+ ometric_set_int_with_labels(peer_message_transmit,
+ p->stats.msg_sent_update, OKV("messages"), OKV("update"), ol);
+ ometric_set_int_with_labels(peer_message_transmit,
+ p->stats.msg_sent_keepalive, OKV("messages"), OKV("keepalive"), ol);
+ ometric_set_int_with_labels(peer_message_transmit,
+ p->stats.msg_sent_rrefresh, OKV("messages"), OKV("route_refresh"),
+ ol);
+
+ ometric_set_int_with_labels(peer_message_recieve,
+ p->stats.msg_rcvd_open, OKV("messages"), OKV("open"), ol);
+ ometric_set_int_with_labels(peer_message_recieve,
+ p->stats.msg_rcvd_notification, OKV("messages"),
+ OKV("notification"), ol);
+ ometric_set_int_with_labels(peer_message_recieve,
+ p->stats.msg_rcvd_update, OKV("messages"), OKV("update"), ol);
+ ometric_set_int_with_labels(peer_message_recieve,
+ p->stats.msg_rcvd_keepalive, OKV("messages"), OKV("keepalive"), ol);
+ ometric_set_int_with_labels(peer_message_recieve,
+ p->stats.msg_rcvd_rrefresh, OKV("messages"), OKV("route_refresh"),
+ ol);
ometric_set_int(peer_update_transmit, p->stats.prefix_sent_update, ol);
ometric_set_int(peer_update_pending, p->stats.pending_update, ol);
uint64_t refs)
{
if (count != UINT64_MAX)
- ometric_set_int_with_label(rde_mem_count, count, "type", v,
- NULL);
+ ometric_set_int_with_labels(rde_mem_count, count,
+ OKV("type"), OKV(v), NULL);
if (size != UINT64_MAX)
- ometric_set_int_with_label(rde_mem_size, size, "type", v, NULL);
+ ometric_set_int_with_labels(rde_mem_size, size,
+ OKV("type"), OKV(v), NULL);
if (refs != UINT64_MAX)
- ometric_set_int_with_label(rde_mem_ref_count, refs, "type", v,
- NULL);
+ ometric_set_int_with_labels(rde_mem_ref_count, refs,
+ OKV("type"), OKV(v), NULL);
}
static void
stats->attr_data, UINT64_MAX);
ometric_set_int(rde_table_count, stats->aset_cnt, NULL);
- ometric_set_int_with_label(rde_set_size, stats->aset_size,
- "type", "as_set", NULL);
- ometric_set_int_with_label(rde_set_count, stats->aset_nmemb,
- "type", "as_set", NULL);
- ometric_set_int_with_label(rde_set_size, stats->pset_size,
- "type", "prefix_set", NULL);
- ometric_set_int_with_label(rde_set_count, stats->pset_cnt,
- "type", "prefix_set", NULL);
+
+ ometric_set_int_with_labels(rde_set_size, stats->aset_size,
+ OKV("type"), OKV("as_set"), NULL);
+ ometric_set_int_with_labels(rde_set_count, stats->aset_nmemb,
+ OKV("type"), OKV("as_set"), NULL);
+ ometric_set_int_with_labels(rde_set_size, stats->pset_size,
+ OKV("type"), OKV("prefix_set"), NULL);
+ ometric_set_int_with_labels(rde_set_count, stats->pset_cnt,
+ OKV("type"), OKV("prefix_set"), NULL);
ometric_rib_mem_element("set_total", UINT64_MAX,
stats->aset_size + stats->pset_size, UINT64_MAX);
}