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
diff --git a/src/stats.c b/src/stats.c
index 4d5a1f5..bdb0fbe 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -254,6 +254,17 @@
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 @@
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 @@
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 @@
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);
}