diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-11-27 18:54:58 +0100 |
---|---|---|
committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-12-08 10:33:04 +0100 |
commit | af5bad5ed00f0d21617c34f0e4e96eb2fd977a02 (patch) | |
tree | b7b6a76fa48438df508a457887816fa4048a875a /src | |
parent | 90e614f7ccb0902e6ddb510bb10f78eb14a13d94 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/stats_statsd.c | 12 | ||||
-rw-r--r-- | src/vty/utils.c | 5 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/stats_statsd.c b/src/stats_statsd.c index c76f8f69..b93d90a7 100644 --- a/src/stats_statsd.c +++ b/src/stats_statsd.c @@ -151,8 +151,18 @@ 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) { + 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); } diff --git a/src/vty/utils.c b/src/vty/utils.c index b15c8d84..3a0f138b 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -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; } |