mirror of https://gerrit.osmocom.org/libosmocore
stat: Explicitly support stat_items without unit
Add OSMO_STAT_ITEM_NO_UNIT for stat items without an unit. The statsd reporter uses gauges ("g") to report them. Sponsored-by: On-Waves ehf [hfreyther: Manually apply change to osmo_stats_reporter_statsd_send_item]
This commit is contained in:
parent
34d770dcfd
commit
70fcbda6dd
|
@ -13,6 +13,7 @@
|
|||
struct osmo_stat_item_desc;
|
||||
|
||||
#define STAT_ITEM_NOVALUE_ID 0
|
||||
#define OSMO_STAT_ITEM_NO_UNIT NULL
|
||||
|
||||
struct osmo_stat_item_value {
|
||||
int32_t id;
|
||||
|
|
12
src/stats.c
12
src/stats.c
|
@ -558,10 +558,20 @@ static int osmo_stats_reporter_statsd_send_item(struct osmo_stats_reporter *srep
|
|||
const struct osmo_stat_item_group *statg,
|
||||
const struct osmo_stat_item_desc *desc, int value)
|
||||
{
|
||||
const char *unit = desc->unit;
|
||||
|
||||
if (unit == OSMO_STAT_ITEM_NO_UNIT) {
|
||||
unit = "g";
|
||||
if (value < 0)
|
||||
osmo_stats_reporter_statsd_send(srep,
|
||||
statg->desc->group_name_prefix,
|
||||
statg->idx,
|
||||
desc->name, 0, unit);
|
||||
}
|
||||
return osmo_stats_reporter_statsd_send(srep,
|
||||
statg->desc->group_name_prefix,
|
||||
statg->idx,
|
||||
desc->name, value, desc->unit);
|
||||
desc->name, value, unit);
|
||||
}
|
||||
|
||||
/*** generic rate counter support ***/
|
||||
|
|
|
@ -87,11 +87,14 @@ static int osmo_stat_item_handler(
|
|||
{
|
||||
struct vty_out_context *vctx = vctx_;
|
||||
struct vty *vty = vctx->vty;
|
||||
const char *unit =
|
||||
item->desc->unit != OSMO_STAT_ITEM_NO_UNIT ?
|
||||
item->desc->unit : "";
|
||||
|
||||
vty_out(vty, " %s%s: %8" PRIi32 " %s%s",
|
||||
vctx->prefix, item->desc->description,
|
||||
osmo_stat_item_get_last(item),
|
||||
item->desc->unit, VTY_NEWLINE);
|
||||
unit, VTY_NEWLINE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue