diff options
-rw-r--r-- | include/osmocom/core/stats.h | 14 | ||||
-rw-r--r-- | src/stats.c | 51 |
2 files changed, 40 insertions, 25 deletions
diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h index 9ee9f106..beeee16e 100644 --- a/include/osmocom/core/stats.h +++ b/include/osmocom/core/stats.h @@ -23,6 +23,10 @@ #include <osmocom/core/linuxlist.h> struct msgb; +struct stat_item_group; +struct stat_item_desc; +struct rate_ctr_group; +struct rate_ctr_desc; enum stats_reporter_type { STATS_REPORTER_STATSD, @@ -53,6 +57,16 @@ struct stats_reporter { int agg_enabled; struct llist_head list; + int (*open)(struct stats_reporter *srep); + int (*close)(struct stats_reporter *srep); + int (*send_counter)(struct stats_reporter *srep, + const struct rate_ctr_group *ctrg, + const struct rate_ctr_desc *desc, + int64_t value, int64_t delta); + int (*send_item)(struct stats_reporter *srep, + const struct stat_item_group *statg, + const struct stat_item_desc *desc, + int32_t value); }; struct stats_config { diff --git a/src/stats.c b/src/stats.c index 6189cb38..f4c0b623 100644 --- a/src/stats.c +++ b/src/stats.c @@ -60,6 +60,14 @@ static struct osmo_timer_list stats_timer; static int stats_reporter_statsd_open(struct stats_reporter *srep); static int stats_reporter_statsd_close(struct stats_reporter *srep); +static int stats_reporter_statsd_send_counter(struct stats_reporter *srep, + const struct rate_ctr_group *ctrg, + const struct rate_ctr_desc *desc, + int64_t value, int64_t delta); +static int stats_reporter_statsd_send_item(struct stats_reporter *srep, + const struct stat_item_group *statg, + const struct stat_item_desc *desc, int value); + static int stats_reporter_send(struct stats_reporter *srep, const char *data, int data_len); static int stats_reporter_send_buffer(struct stats_reporter *srep); @@ -68,20 +76,20 @@ static int update_srep_config(struct stats_reporter *srep) { int rc = 0; - if (srep->type != STATS_REPORTER_STATSD) { - srep->enabled = 0; - return -ENOTSUP; - } - if (srep->running) { - rc = stats_reporter_statsd_close(srep); + if (srep->close) + rc = srep->close(srep); srep->running = 0; } if (!srep->enabled) return rc; - rc = stats_reporter_statsd_open(srep); + if (srep->open) + rc = srep->open(srep); + else + rc = 0; + if (rc < 0) srep->enabled = 0; else @@ -310,6 +318,11 @@ struct stats_reporter *stats_reporter_create_statsd(const char *name) srep->have_net_config = 1; + srep->open = stats_reporter_statsd_open; + srep->close = stats_reporter_statsd_close; + srep->send_counter = stats_reporter_statsd_send_counter; + srep->send_item = stats_reporter_statsd_send_item; + return srep; } @@ -461,16 +474,10 @@ static int stats_reporter_send_counter(struct stats_reporter *srep, const struct rate_ctr_desc *desc, int64_t value, int64_t delta) { - int rc; - - switch (srep->type) { - case STATS_REPORTER_STATSD: - rc = stats_reporter_statsd_send_counter(srep, ctrg, desc, - value, delta); - break; - } + if (!srep->send_counter) + return 0; - return rc; + return srep->send_counter(srep, ctrg, desc, value, delta); } static int rate_ctr_handler( @@ -511,16 +518,10 @@ static int stats_reporter_send_item(struct stats_reporter *srep, const struct stat_item_desc *desc, int32_t value) { - int rc; - - switch (srep->type) { - case STATS_REPORTER_STATSD: - rc = stats_reporter_statsd_send_item(srep, statg, desc, - value); - break; - } + if (!srep->send_item) + return 0; - return rc; + return srep->send_item(srep, statg, desc, value); } static int stat_item_handler( |