summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/stat_item.h68
-rw-r--r--include/osmocom/core/stats.h60
-rw-r--r--include/osmocom/gprs/gprs_ns.h2
-rw-r--r--include/osmocom/vty/misc.h2
-rw-r--r--include/osmocom/vty/stats.h2
-rw-r--r--src/gb/gprs_ns.c8
-rw-r--r--src/stat_item.c62
-rw-r--r--src/stats.c214
-rw-r--r--src/vty/stats_vty.c80
-rw-r--r--src/vty/utils.c16
-rw-r--r--tests/stats/stats_test.c110
11 files changed, 312 insertions, 312 deletions
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index 0786a3ba..40474958 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -1,6 +1,6 @@
#pragma once
-/*! \defgroup stat_item Statistics value item
+/*! \defgroup osmo_stat_item Statistics value item
* @{
*/
@@ -10,28 +10,28 @@
#include <osmocom/core/linuxlist.h>
-struct stat_item_desc;
+struct osmo_stat_item_desc;
#define STAT_ITEM_NOVALUE_ID 0
-struct stat_item_value {
+struct osmo_stat_item_value {
int32_t id;
int32_t value;
};
/*! \brief data we keep for each actual value */
-struct stat_item {
- const struct stat_item_desc *desc;
+struct osmo_stat_item {
+ const struct osmo_stat_item_desc *desc;
/*! \brief the index of the freshest value */
int32_t last_value_index;
/*! \brief offset to the freshest value in the value fifo */
int16_t last_offs;
/*! \brief value fifo */
- struct stat_item_value values[0];
+ struct osmo_stat_item_value values[0];
};
/*! \brief statistics value description */
-struct stat_item_desc {
+struct osmo_stat_item_desc {
const char *name; /*!< \brief name of the item */
const char *description;/*!< \brief description of the item */
const char *unit; /*!< \brief unit of a value */
@@ -40,7 +40,7 @@ struct stat_item_desc {
};
/*! \brief description of a statistics value group */
-struct stat_item_group_desc {
+struct osmo_stat_item_group_desc {
/*! \brief The prefix to the name of all values in this group */
const char *group_name_prefix;
/*! \brief The human-readable description of the group */
@@ -48,80 +48,80 @@ struct stat_item_group_desc {
/*! \brief The number of values in this group */
const unsigned int num_items;
/*! \brief Pointer to array of value names */
- const struct stat_item_desc *item_desc;
+ const struct osmo_stat_item_desc *item_desc;
};
/*! \brief One instance of a counter group class */
-struct stat_item_group {
+struct osmo_stat_item_group {
/*! \brief Linked list of all value groups in the system */
struct llist_head list;
/*! \brief Pointer to the counter group class */
- const struct stat_item_group_desc *desc;
+ const struct osmo_stat_item_group_desc *desc;
/*! \brief The index of this value group within its class */
unsigned int idx;
/*! \brief Actual counter structures below */
- struct stat_item *items[0];
+ struct osmo_stat_item *items[0];
};
-struct stat_item_group *stat_item_group_alloc(
+struct osmo_stat_item_group *osmo_stat_item_group_alloc(
void *ctx,
- const struct stat_item_group_desc *desc,
+ const struct osmo_stat_item_group_desc *desc,
unsigned int idx);
-void stat_item_group_free(struct stat_item_group *statg);
+void osmo_stat_item_group_free(struct osmo_stat_item_group *statg);
-void stat_item_set(struct stat_item *item, int32_t value);
+void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
-int stat_item_init(void *tall_ctx);
+int osmo_stat_item_init(void *tall_ctx);
-struct stat_item_group *stat_item_get_group_by_name_idx(
+struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
const char *name, const unsigned int idx);
-const struct stat_item *stat_item_get_by_name(
- const struct stat_item_group *statg, const char *name);
+const struct osmo_stat_item *osmo_stat_item_get_by_name(
+ const struct osmo_stat_item_group *statg, const char *name);
-/*! \brief Retrieve the next value from the stat_item object.
+/*! \brief Retrieve the next value from the osmo_stat_item object.
* If a new value has been set, it is returned. The idx is used to decide
* which value to return.
* On success, *idx is updated to refer to the next unread value. If
* values have been missed due to FIFO overflow, *idx is incremented by
* (1 + num_lost).
- * This way, the stat_item object can be kept stateless from the reader's
+ * This way, the osmo_stat_item object can be kept stateless from the reader's
* perspective and therefore be used by several backends simultaneously.
*
- * \param val the stat_item object
+ * \param val the osmo_stat_item object
* \param idx identifies the next value to be read
* \param value a pointer to store the value
* \returns the increment of the index (0: no value has been read,
* 1: one value has been taken,
* (1+n): n values have been skipped, one has been taken)
*/
-int stat_item_get_next(const struct stat_item *item, int32_t *idx, int32_t *value);
+int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value);
/*! \brief Get the last (freshest) value */
-static int32_t stat_item_get_last(const struct stat_item *item);
+static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
/*! \brief Skip all values of the item and update idx accordingly */
-int stat_item_discard(const struct stat_item *item, int32_t *idx);
+int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx);
/*! \brief Skip all values of all items and update idx accordingly */
-int stat_item_discard_all(int32_t *idx);
+int osmo_stat_item_discard_all(int32_t *idx);
-typedef int (*stat_item_handler_t)(
- struct stat_item_group *, struct stat_item *, void *);
+typedef int (*osmo_stat_item_handler_t)(
+ struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
-typedef int (*stat_item_group_handler_t)(struct stat_item_group *, void *);
+typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
/*! \brief Iteate over all items
* \param[in] handle_item Call-back function, aborts if rc < 0
* \param[in] data Private data handed through to \a handle_item
*/
-int stat_item_for_each_item(struct stat_item_group *statg,
- stat_item_handler_t handle_item, void *data);
+int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg,
+ osmo_stat_item_handler_t handle_item, void *data);
-int stat_item_for_each_group(stat_item_group_handler_t handle_group, void *data);
+int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data);
-static inline int32_t stat_item_get_last(const struct stat_item *item)
+static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
{
return item->values[item->last_offs].value;
}
diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h
index 68c2e016..7b3d0211 100644
--- a/include/osmocom/core/stats.h
+++ b/include/osmocom/core/stats.h
@@ -23,18 +23,18 @@
#include <osmocom/core/linuxlist.h>
struct msgb;
-struct stat_item_group;
-struct stat_item_desc;
+struct osmo_stat_item_group;
+struct osmo_stat_item_desc;
struct rate_ctr_group;
struct rate_ctr_desc;
-enum stats_reporter_type {
- STATS_REPORTER_STATSD,
- STATS_REPORTER_LOG,
+enum osmo_stats_reporter_type {
+ OSMO_STATS_REPORTER_STATSD,
+ OSMO_STATS_REPORTER_LOG,
};
-struct stats_reporter {
- enum stats_reporter_type type;
+struct osmo_stats_reporter {
+ enum osmo_stats_reporter_type type;
char *name;
unsigned int have_net_config : 1;
@@ -58,43 +58,43 @@ 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,
+ int (*open)(struct osmo_stats_reporter *srep);
+ int (*close)(struct osmo_stats_reporter *srep);
+ int (*send_counter)(struct osmo_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,
+ int (*send_item)(struct osmo_stats_reporter *srep,
+ const struct osmo_stat_item_group *statg,
+ const struct osmo_stat_item_desc *desc,
int32_t value);
};
-struct stats_config {
+struct osmo_stats_config {
int interval;
};
-extern struct stats_config *stats_config;
+extern struct osmo_stats_config *osmo_stats_config;
-void stats_init(void *ctx);
-int stats_report();
+void osmo_stats_init(void *ctx);
+int osmo_stats_report();
-int stats_set_interval(int interval);
+int osmo_stats_set_interval(int interval);
-struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type,
+struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
const char *name);
-void stats_reporter_free(struct stats_reporter *srep);
+void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
-struct stats_reporter *stats_reporter_create_statsd(const char *name);
-struct stats_reporter *stats_reporter_create_log(const char *name);
+struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
+struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
-struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
+struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
const char *name);
-int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr);
-int stats_reporter_set_remote_port(struct stats_reporter *srep, int port);
-int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr);
-int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu);
-int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix);
-int stats_reporter_enable(struct stats_reporter *srep);
-int stats_reporter_disable(struct stats_reporter *srep);
+int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
+int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
+int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
+int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
+int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
+int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
+int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
diff --git a/include/osmocom/gprs/gprs_ns.h b/include/osmocom/gprs/gprs_ns.h
index 42e0d884..7c3b23c1 100644
--- a/include/osmocom/gprs/gprs_ns.h
+++ b/include/osmocom/gprs/gprs_ns.h
@@ -126,7 +126,7 @@ struct gprs_nsvc {
unsigned int nsvci_is_valid:1;
struct rate_ctr_group *ctrg;
- struct stat_item_group *statg;
+ struct osmo_stat_item_group *statg;
/*! \brief which link-layer are we based on? */
enum gprs_ns_ll ll;
diff --git a/include/osmocom/vty/misc.h b/include/osmocom/vty/misc.h
index 99c2ee68..f3b46dbd 100644
--- a/include/osmocom/vty/misc.h
+++ b/include/osmocom/vty/misc.h
@@ -14,7 +14,7 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix,
struct rate_ctr_group *ctrg);
void vty_out_stat_item_group(struct vty *vty, const char *prefix,
- struct stat_item_group *statg);
+ struct osmo_stat_item_group *statg);
void vty_out_statistics_full(struct vty *vty, const char *prefix);
diff --git a/include/osmocom/vty/stats.h b/include/osmocom/vty/stats.h
index eaf854e5..3851b4df 100644
--- a/include/osmocom/vty/stats.h
+++ b/include/osmocom/vty/stats.h
@@ -1,3 +1,3 @@
#pragma once
-void stats_vty_add_cmds();
+void osmo_stats_vty_add_cmds();
diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c
index afc62497..5025d575 100644
--- a/src/gb/gprs_ns.c
+++ b/src/gb/gprs_ns.c
@@ -135,11 +135,11 @@ enum ns_stat {
NS_STAT_ALIVE_DELAY,
};
-static const struct stat_item_desc nsvc_stat_description[] = {
+static const struct osmo_stat_item_desc nsvc_stat_description[] = {
{ "alive.delay", "ALIVE reponse time ", "ms", 16, 0 },
};
-static const struct stat_item_group_desc nsvc_statg_desc = {
+static const struct osmo_stat_item_group_desc nsvc_statg_desc = {
.group_name_prefix = "ns.nsvc",
.group_description = "NSVC Peer Statistics",
.num_items = ARRAY_SIZE(nsvc_stat_description),
@@ -238,7 +238,7 @@ struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
nsvc->timer.cb = gprs_ns_timer_cb;
nsvc->timer.data = nsvc;
nsvc->ctrg = rate_ctr_group_alloc(nsvc, &nsvc_ctrg_desc, nsvci);
- nsvc->statg = stat_item_group_alloc(nsvc, &nsvc_statg_desc, nsvci);
+ nsvc->statg = osmo_stat_item_group_alloc(nsvc, &nsvc_statg_desc, nsvci);
llist_add(&nsvc->list, &nsi->gprs_nsvcs);
@@ -1306,7 +1306,7 @@ int gprs_ns_process_msg(struct gprs_ns_inst *nsi, struct msgb *msg,
break;
case NS_PDUT_ALIVE_ACK:
if ((*nsvc)->timer_mode == NSVC_TIMER_TNS_ALIVE)
- stat_item_set((*nsvc)->statg->items[NS_STAT_ALIVE_DELAY],
+ osmo_stat_item_set((*nsvc)->statg->items[NS_STAT_ALIVE_DELAY],
nsvc_timer_elapsed_ms(*nsvc));
/* stop Tns-alive and start Tns-test */
nsvc_start_timer(*nsvc, NSVC_TIMER_TNS_TEST);
diff --git a/src/stat_item.c b/src/stat_item.c
index 525a94b9..0545ea0d 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -21,7 +21,7 @@
*
*/
-/*! \addtogroup stat_item
+/*! \addtogroup osmo_stat_item
* @{
*/
@@ -37,7 +37,7 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/stat_item.h>
-static LLIST_HEAD(stat_item_groups);
+static LLIST_HEAD(osmo_stat_item_groups);
static int32_t global_value_id = 0;
static void *tall_stat_item_ctx;
@@ -47,8 +47,8 @@ static void *tall_stat_item_ctx;
* \param[in] desc Statistics item group description
* \param[in] idx Index of new stat item group
*/
-struct stat_item_group *stat_item_group_alloc(void *ctx,
- const struct stat_item_group_desc *desc,
+struct osmo_stat_item_group *osmo_stat_item_group_alloc(void *ctx,
+ const struct osmo_stat_item_group_desc *desc,
unsigned int idx)
{
unsigned int group_size;
@@ -56,10 +56,10 @@ struct stat_item_group *stat_item_group_alloc(void *ctx,
unsigned int item_idx;
void *items;
- struct stat_item_group *group;
+ struct osmo_stat_item_group *group;
- group_size = sizeof(struct stat_item_group) +
- desc->num_items * sizeof(struct stat_item *);
+ group_size = sizeof(struct osmo_stat_item_group) +
+ desc->num_items * sizeof(struct osmo_stat_item *);
if (!ctx)
ctx = tall_stat_item_ctx;
@@ -74,8 +74,8 @@ struct stat_item_group *stat_item_group_alloc(void *ctx,
/* Get combined size of all items */
for (item_idx = 0; item_idx < desc->num_items; item_idx++) {
unsigned int size;
- size = sizeof(struct stat_item) +
- sizeof(struct stat_item_value) *
+ size = sizeof(struct osmo_stat_item) +
+ sizeof(struct osmo_stat_item_value) *
desc->item_desc[item_idx].num_values;
/* Align to pointer size */
size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
@@ -94,7 +94,7 @@ struct stat_item_group *stat_item_group_alloc(void *ctx,
/* Update item pointers */
for (item_idx = 0; item_idx < desc->num_items; item_idx++) {
- struct stat_item *item = (struct stat_item *)
+ struct osmo_stat_item *item = (struct osmo_stat_item *)
((uint8_t *)items + (int)group->items[item_idx]);
unsigned int i;
@@ -109,19 +109,19 @@ struct stat_item_group *stat_item_group_alloc(void *ctx,
}
}
- llist_add(&group->list, &stat_item_groups);
+ llist_add(&group->list, &osmo_stat_item_groups);
return group;
}
/*! \brief Free the memory for the specified group of counters */
-void stat_item_group_free(struct stat_item_group *grp)
+void osmo_stat_item_group_free(struct osmo_stat_item_group *grp)
{
llist_del(&grp->list);
talloc_free(grp);
}
-void stat_item_set(struct stat_item *item, int32_t value)
+void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value)
{
item->last_offs += 1;
if (item->last_offs >= item->desc->num_values)
@@ -135,11 +135,11 @@ void stat_item_set(struct stat_item *item, int32_t value)
item->values[item->last_offs].id = global_value_id;
}
-int stat_item_get_next(const struct stat_item *item, int32_t *next_idx,
+int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx,
int32_t *value)
{
- const struct stat_item_value *next_value;
- const struct stat_item_value *item_value = NULL;
+ const struct osmo_stat_item_value *next_value;
+ const struct osmo_stat_item_value *item_value = NULL;
int idx_delta;
int next_offs;
@@ -173,7 +173,7 @@ int stat_item_get_next(const struct stat_item *item, int32_t *next_idx,
}
/*! \brief Skip all values of this item and update idx accordingly */
-int stat_item_discard(const struct stat_item *item, int32_t *idx)
+int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx)
{
int discarded = item->values[item->last_offs].id + 1 - *idx;
*idx = item->values[item->last_offs].id + 1;
@@ -182,7 +182,7 @@ int stat_item_discard(const struct stat_item *item, int32_t *idx)
}
/*! \brief Skip all values of all items and update idx accordingly */
-int stat_item_discard_all(int32_t *idx)
+int osmo_stat_item_discard_all(int32_t *idx)
{
int discarded = global_value_id + 1 - *idx;
*idx = global_value_id + 1;
@@ -191,7 +191,7 @@ int stat_item_discard_all(int32_t *idx)
}
/*! \brief Initialize the stat item module */
-int stat_item_init(void *tall_ctx)
+int osmo_stat_item_init(void *tall_ctx)
{
tall_stat_item_ctx = tall_ctx;
@@ -199,12 +199,12 @@ int stat_item_init(void *tall_ctx)
}
/*! \brief Search for item group based on group name and index */
-struct stat_item_group *stat_item_get_group_by_name_idx(
+struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
const char *name, const unsigned int idx)
{
- struct stat_item_group *statg;
+ struct osmo_stat_item_group *statg;
- llist_for_each_entry(statg, &stat_item_groups, list) {
+ llist_for_each_entry(statg, &osmo_stat_item_groups, list) {
if (!statg->desc)
continue;
@@ -216,11 +216,11 @@ struct stat_item_group *stat_item_get_group_by_name_idx(
}
/*! \brief Search for item group based on group name */
-const struct stat_item *stat_item_get_by_name(
- const struct stat_item_group *statg, const char *name)
+const struct osmo_stat_item *osmo_stat_item_get_by_name(
+ const struct osmo_stat_item_group *statg, const char *name)
{
int i;
- const struct stat_item_desc *item_desc;
+ const struct osmo_stat_item_desc *item_desc;
if (!statg->desc)
return NULL;
@@ -235,14 +235,14 @@ const struct stat_item *stat_item_get_by_name(
return NULL;
}
-int stat_item_for_each_item(struct stat_item_group *statg,
- stat_item_handler_t handle_item, void *data)
+int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg,
+ osmo_stat_item_handler_t handle_item, void *data)
{
int rc = 0;
int i;
for (i = 0; i < statg->desc->num_items; i++) {
- struct stat_item *item = statg->items[i];
+ struct osmo_stat_item *item = statg->items[i];
rc = handle_item(statg, item, data);
if (rc < 0)
return rc;
@@ -251,12 +251,12 @@ int stat_item_for_each_item(struct stat_item_group *statg,
return rc;
}
-int stat_item_for_each_group(stat_item_group_handler_t handle_group, void *data)
+int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data)
{
- struct stat_item_group *statg;
+ struct osmo_stat_item_group *statg;
int rc = 0;
- llist_for_each_entry(statg, &stat_item_groups, list) {
+ llist_for_each_entry(statg, &osmo_stat_item_groups, list) {
rc = handle_group(statg, data);
if (rc < 0)
return rc;
diff --git a/src/stats.c b/src/stats.c
index 5027a621..155f8a2c 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -46,41 +46,41 @@
#define STATS_DEFAULT_INTERVAL 5 /* secs */
#define STATS_DEFAULT_STATSD_BUFLEN 256
-static LLIST_HEAD(stats_reporter_list);
-static void *stats_ctx = NULL;
+static LLIST_HEAD(osmo_stats_reporter_list);
+static void *osmo_stats_ctx = NULL;
static int is_initialised = 0;
static int32_t current_stat_item_index = 0;
-static struct stats_config s_stats_config = {
+static struct osmo_stats_config s_stats_config = {
.interval = STATS_DEFAULT_INTERVAL,
};
-struct stats_config *stats_config = &s_stats_config;
+struct osmo_stats_config *osmo_stats_config = &s_stats_config;
-static struct osmo_timer_list stats_timer;
+static struct osmo_timer_list osmo_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,
+static int osmo_stats_reporter_statsd_open(struct osmo_stats_reporter *srep);
+static int osmo_stats_reporter_statsd_close(struct osmo_stats_reporter *srep);
+static int osmo_stats_reporter_statsd_send_counter(struct osmo_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 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);
-static int stats_reporter_log_send_counter(struct stats_reporter *srep,
+static int osmo_stats_reporter_log_send_counter(struct osmo_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_log_send_item(struct stats_reporter *srep,
- const struct stat_item_group *statg,
- const struct stat_item_desc *desc, int value);
+static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep,
+ const struct osmo_stat_item_group *statg,
+ const struct osmo_stat_item_desc *desc, int value);
-static int stats_reporter_send(struct stats_reporter *srep, const char *data,
+static int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
int data_len);
-static int stats_reporter_send_buffer(struct stats_reporter *srep);
+static int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
-static int update_srep_config(struct stats_reporter *srep)
+static int update_srep_config(struct osmo_stats_reporter *srep)
{
int rc = 0;
@@ -106,14 +106,14 @@ static int update_srep_config(struct stats_reporter *srep)
return rc;
}
-static void stats_timer_cb(void *data)
+static void osmo_stats_timer_cb(void *data)
{
- int interval = stats_config->interval;
+ int interval = osmo_stats_config->interval;
- if (!llist_empty(&stats_reporter_list))
- stats_report();
+ if (!llist_empty(&osmo_stats_reporter_list))
+ osmo_stats_report();
- osmo_timer_schedule(&stats_timer, interval, 0);
+ osmo_timer_schedule(&osmo_stats_timer, interval, 0);
}
static int start_timer()
@@ -121,49 +121,49 @@ static int start_timer()
if (!is_initialised)
return -ESRCH;
- stats_timer.cb = stats_timer_cb;
- osmo_timer_schedule(&stats_timer, 0, 1);
+ osmo_stats_timer.cb = osmo_stats_timer_cb;
+ osmo_timer_schedule(&osmo_stats_timer, 0, 1);
return 0;
}
-struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type,
+struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
const char *name)
{
- struct stats_reporter *srep;
- srep = talloc_zero(stats_ctx, struct stats_reporter);
+ struct osmo_stats_reporter *srep;
+ srep = talloc_zero(osmo_stats_ctx, struct osmo_stats_reporter);
OSMO_ASSERT(srep);
srep->type = type;
if (name)
srep->name = talloc_strdup(srep, name);
srep->fd = -1;
- llist_add(&srep->list, &stats_reporter_list);
+ llist_add(&srep->list, &osmo_stats_reporter_list);
return srep;
}
-void stats_reporter_free(struct stats_reporter *srep)
+void osmo_stats_reporter_free(struct osmo_stats_reporter *srep)
{
- stats_reporter_disable(srep);
+ osmo_stats_reporter_disable(srep);
llist_del(&srep->list);
talloc_free(srep);
}
-void stats_init(void *ctx)
+void osmo_stats_init(void *ctx)
{
- stats_ctx = ctx;
- stat_item_discard_all(&current_stat_item_index);
+ osmo_stats_ctx = ctx;
+ osmo_stat_item_discard_all(&current_stat_item_index);
is_initialised = 1;
start_timer();
}
-struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
+struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
const char *name)
{
- struct stats_reporter *srep;
- llist_for_each_entry(srep, &stats_reporter_list, list) {
+ struct osmo_stats_reporter *srep;
+ llist_for_each_entry(srep, &osmo_stats_reporter_list, list) {
if (srep->type != type)
continue;
if (srep->name != name) {
@@ -176,7 +176,7 @@ struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
return NULL;
}
-int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr)
+int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr)
{
int rc;
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr;
@@ -201,7 +201,7 @@ int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr
return update_srep_config(srep);
}
-int stats_reporter_set_remote_port(struct stats_reporter *srep, int port)
+int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port)
{
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr;
@@ -214,7 +214,7 @@ int stats_reporter_set_remote_port(struct stats_reporter *srep, int port)
return update_srep_config(srep);
}
-int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr)
+int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr)
{
int rc;
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->bind_addr;
@@ -241,7 +241,7 @@ int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr)
return update_srep_config(srep);
}
-int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu)
+int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu)
{
if (!srep->have_net_config)
return -ENOTSUP;
@@ -254,19 +254,19 @@ int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu)
return update_srep_config(srep);
}
-int stats_set_interval(int interval)
+int osmo_stats_set_interval(int interval)
{
if (interval <= 0)
return -EINVAL;
- stats_config->interval = interval;
+ osmo_stats_config->interval = interval;
if (is_initialised)
start_timer();
return 0;
}
-int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix)
+int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
{
talloc_free(srep->name_prefix);
srep->name_prefix = prefix ? talloc_strdup(srep, prefix) : NULL;
@@ -274,21 +274,21 @@ int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *pref
return update_srep_config(srep);
}
-int stats_reporter_enable(struct stats_reporter *srep)
+int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep)
{
srep->enabled = 1;
return update_srep_config(srep);
}
-int stats_reporter_disable(struct stats_reporter *srep)
+int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
{
srep->enabled = 0;
return update_srep_config(srep);
}
-static int stats_reporter_send(struct stats_reporter *srep, const char *data,
+static int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
int data_len)
{
int rc;
@@ -302,14 +302,14 @@ static int stats_reporter_send(struct stats_reporter *srep, const char *data,
return rc;
}
-static int stats_reporter_send_buffer(struct stats_reporter *srep)
+static int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep)
{
int rc;
if (!srep->buffer || msgb_length(srep->buffer) == 0)
return 0;
- rc = stats_reporter_send(srep,
+ rc = osmo_stats_reporter_send(srep,
(const char *)msgb_data(srep->buffer), msgb_length(srep->buffer));
msgb_trim(srep->buffer, 0);
@@ -319,20 +319,20 @@ static int stats_reporter_send_buffer(struct stats_reporter *srep)
/*** log reporter ***/
-struct stats_reporter *stats_reporter_create_log(const char *name)
+struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name)
{
- struct stats_reporter *srep;
- srep = stats_reporter_alloc(STATS_REPORTER_LOG, name);
+ struct osmo_stats_reporter *srep;
+ srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_LOG, name);
srep->have_net_config = 0;
- srep->send_counter = stats_reporter_log_send_counter;
- srep->send_item = stats_reporter_log_send_item;
+ srep->send_counter = osmo_stats_reporter_log_send_counter;
+ srep->send_item = osmo_stats_reporter_log_send_item;
return srep;
}
-static int stats_reporter_log_send(struct stats_reporter *srep,
+static int osmo_stats_reporter_log_send(struct osmo_stats_reporter *srep,
const char *type,
const char *name1, int index1, const char *name2, int value,
const char *unit)
@@ -347,56 +347,56 @@ static int stats_reporter_log_send(struct stats_reporter *srep,
}
-static int stats_reporter_log_send_counter(struct stats_reporter *srep,
+static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep,
const struct rate_ctr_group *ctrg,
const struct rate_ctr_desc *desc,
int64_t value, int64_t delta)
{
if (ctrg)
- return stats_reporter_log_send(srep, "c",
+ return osmo_stats_reporter_log_send(srep, "c",
ctrg->desc->group_name_prefix,
ctrg->idx,
desc->name, value, NULL);
else
- return stats_reporter_log_send(srep, "c",
+ return osmo_stats_reporter_log_send(srep, "c",
NULL, -1,
desc->name, value, NULL);
}
-static int stats_reporter_log_send_item(struct stats_reporter *srep,
- const struct stat_item_group *statg,
- const struct stat_item_desc *desc, int value)
+static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep,
+ const struct osmo_stat_item_group *statg,
+ const struct osmo_stat_item_desc *desc, int value)
{
- return stats_reporter_log_send(srep, "i",
+ return osmo_stats_reporter_log_send(srep, "i",
statg->desc->group_name_prefix, statg->idx,
desc->name, value, desc->unit);
}
/*** statsd reporter ***/
-struct stats_reporter *stats_reporter_create_statsd(const char *name)
+struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name)
{
- struct stats_reporter *srep;
- srep = stats_reporter_alloc(STATS_REPORTER_STATSD, name);
+ struct osmo_stats_reporter *srep;
+ srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_STATSD, 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;
+ srep->open = osmo_stats_reporter_statsd_open;
+ srep->close = osmo_stats_reporter_statsd_close;
+ srep->send_counter = osmo_stats_reporter_statsd_send_counter;
+ srep->send_item = osmo_stats_reporter_statsd_send_item;
return srep;
}
-static int stats_reporter_statsd_open(struct stats_reporter *srep)
+static int osmo_stats_reporter_statsd_open(struct osmo_stats_reporter *srep)
{
int sock;
int rc;
int buffer_size = STATS_DEFAULT_STATSD_BUFLEN;
if (srep->fd != -1)
- stats_reporter_statsd_close(srep);
+ osmo_stats_reporter_statsd_close(srep);
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
@@ -426,13 +426,13 @@ failed:
return rc;
}
-static int stats_reporter_statsd_close(struct stats_reporter *srep)
+static int osmo_stats_reporter_statsd_close(struct osmo_stats_reporter *srep)
{
int rc;
if (srep->fd == -1)
return -EBADF;
- stats_reporter_send_buffer(srep);
+ osmo_stats_reporter_send_buffer(srep);
rc = close(srep->fd);
srep->fd = -1;
@@ -441,7 +441,7 @@ static int stats_reporter_statsd_close(struct stats_reporter *srep)
return rc == -1 ? -errno : 0;
}
-static int stats_reporter_statsd_send(struct stats_reporter *srep,
+static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,
const char *name1, int index1, const char *name2, int value,
const char *unit)
{
@@ -482,7 +482,7 @@ static int stats_reporter_statsd_send(struct stats_reporter *srep,
/* Restore original buffer (without trailing LF) */
msgb_trim(srep->buffer, old_len);
/* Send it */
- rc = stats_reporter_send_buffer(srep);
+ rc = osmo_stats_reporter_send_buffer(srep);
/* Try again */
buf = (char *)msgb_put(srep->buffer, 0);
@@ -500,39 +500,39 @@ static int stats_reporter_statsd_send(struct stats_reporter *srep,
msgb_trim(srep->buffer, msgb_length(srep->buffer) + nchars);
if (!srep->agg_enabled)
- rc = stats_reporter_send_buffer(srep);
+ rc = osmo_stats_reporter_send_buffer(srep);
return rc;
}
-static int stats_reporter_statsd_send_counter(struct stats_reporter *srep,
+static int osmo_stats_reporter_statsd_send_counter(struct osmo_stats_reporter *srep,
const struct rate_ctr_group *ctrg,
const struct rate_ctr_desc *desc,
int64_t value, int64_t delta)
{
if (ctrg)
- return stats_reporter_statsd_send(srep,
+ return osmo_stats_reporter_statsd_send(srep,
ctrg->desc->group_name_prefix,
ctrg->idx,
desc->name, delta, "c");
else
- retur