From bc9d9aced8c174bbb5fc265ec746621d31344be0 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 2 Nov 2015 14:49:35 +0100 Subject: stats: Limit reporting by class id This commit adds class_id fields to the rate_ctr and stat_item group descriptions. The stats reporter code is extended to only process groups whose class_id does not exceed a per reporter max_class level. If the class_id is not set, the code assumes 'global' for groups with idx == 0 and 'subscriber' otherwise. The following vty command is added to config-stats: level (global|peer|subscriber) Set the maximum group level Sponsored-by: On-Waves ehf --- src/stats.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/stats.c') diff --git a/src/stats.c b/src/stats.c index 4d5a1f57..bdb0fbe6 100644 --- a/src/stats.c +++ b/src/stats.c @@ -254,6 +254,17 @@ int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu) return update_srep_config(srep); } +int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, + enum osmo_stats_class class_id) +{ + if (class_id == OSMO_STATS_CLASS_UNKNOWN) + return -EINVAL; + + srep->max_class = class_id; + + return 0; +} + int osmo_stats_set_interval(int interval) { if (interval <= 0) @@ -317,6 +328,16 @@ static int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep) return rc; } +static int osmo_stats_reporter_check_config(struct osmo_stats_reporter *srep, + unsigned int index, int class_id) +{ + if (class_id == OSMO_STATS_CLASS_UNKNOWN) + class_id = index != 0 ? + OSMO_STATS_CLASS_SUBSCRIBER : OSMO_STATS_CLASS_GLOBAL; + + return class_id <= srep->max_class; +} + /*** log reporter ***/ struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name) @@ -559,6 +580,10 @@ static int rate_ctr_handler( if (!srep->running) continue; + if (!osmo_stats_reporter_check_config(srep, + ctrg->idx, ctrg->desc->class_id)) + return 0; + rc = osmo_stats_reporter_send_counter(srep, ctrg, desc, ctr->current, delta); @@ -601,6 +626,10 @@ static int osmo_stat_item_handler( if (!srep->running) continue; + if (!osmo_stats_reporter_check_config(srep, + statg->idx, statg->desc->class_id)) + return 0; + rc = osmo_stats_reporter_send_item(srep, statg, item->desc, value); } -- cgit v1.2.3