libosmocore 1.11.0.26-c59d.202505072026
Osmocom core library
|
Counters about events and their event rates. More...
Files | |
file | rate_ctr.h |
file | rate_ctr.c |
Data Structures | |
struct | rate_ctr_per_intv |
data we keep for each of the intervals More... | |
struct | rate_ctr |
data we keep for each actual value More... | |
struct | rate_ctr_desc |
rate counter description More... | |
struct | rate_ctr_group_desc |
description of a rate counter group More... | |
struct | rate_ctr_group |
One instance of a counter group class. More... | |
Macros | |
#define | RATE_CTR_INTV_NUM 4 |
Number of rate counter intervals. | |
Typedefs | |
typedef int(* | rate_ctr_handler_t) (struct rate_ctr_group *, struct rate_ctr *, const struct rate_ctr_desc *, void *) |
typedef int(* | rate_ctr_group_handler_t) (struct rate_ctr_group *, void *) |
Enumerations | |
enum | rate_ctr_intv { RATE_CTR_INTV_SEC , RATE_CTR_INTV_MIN , RATE_CTR_INTV_HOUR , RATE_CTR_INTV_DAY } |
Rate counter interval. More... | |
Variables | |
static void * | tall_rate_ctr_ctx |
static struct osmo_fd | rate_ctr_timer = { .fd = -1 } |
static uint64_t | timer_ticks |
Counters about events and their event rates.
As osmo_counter and Statistics value item are concerned only with a single given value that may be increased/decreased, or the difference to one given previous value, this module adds some support for keeping long term information about a given event rate.
A Rate counters keeps information on the amount of events per second, per minute, per hour and per day.
Rate counters come in groups: An application describes a group of counters with their names and identities once in a (typically const) rate_ctr_group_desc.
As objects (such as e.g. a subscriber or a PDP context) are allocated dynamically at runtime, the application calls rate_ctr_group_alloc with a refernce to the rate_ctr_group_desc, which causes the library to allocate one set of rate_ctr: One for each in the group.
The application then uses functions like rate_ctr_add or rate_ctr_inc to increment the value as certain events (e.g. location update) happens.
The library internally keeps a timer once per second which iterates over all registered counters and which updates the per-second, per-minute, per-hour and per-day averages based on the current value.
The counters can be reported using Statistics reporting or by VTY introspection, as well as by any application-specific code accessing the rate_ctr::intv array directly.
#define RATE_CTR_INTV_NUM 4 |
Number of rate counter intervals.
typedef int(* rate_ctr_group_handler_t) (struct rate_ctr_group *, void *) |
typedef int(* rate_ctr_handler_t) (struct rate_ctr_group *, struct rate_ctr *, const struct rate_ctr_desc *, void *) |
References current, intv, rate_ctr_per_intv::last, and rate_ctr_per_intv::rate.
Referenced by rate_ctr_group_intv().
|
static |
References DLGLOBAL, LOGL_NOTICE, LOGP, OSMO_ASSERT, and subsys.
Referenced by rate_ctr_group_desc_mangle().
Increment the counter by inc.
Add a number to the counter.
ctr | Rate counters to increment |
inc | quantity to increment ctr by |
References current, and subsys.
Referenced by rate_ctr_add2(), and rate_ctr_inc().
Increment the counter by inc.
ctrg | rate_ctr_group of counter |
idx | index into ctrg counter group |
inc | quantity to increment ctr by |
References rate_ctr_add(), and rate_ctr_group_get_ctr().
Return the counter difference since the last call to this function.
References current, previous, and subsys.
Referenced by rate_ctr_handler().
int rate_ctr_for_each_counter | ( | struct rate_ctr_group * | ctrg, |
rate_ctr_handler_t | handle_counter, | ||
void * | data | ||
) |
Iterate over each counter in group and call function.
[in] | ctrg | counter group over which to iterate |
[in] | handle_counter | function pointer |
[in] | data | Data to hand transparently to handle_counter() |
References rate_ctr_group::ctr, rate_ctr_group_desc::ctr_desc, data, rate_ctr_group::desc, rate_ctr_group_desc::num_ctr, and subsys.
Referenced by rate_ctr_group_handler().
int rate_ctr_for_each_group | ( | rate_ctr_group_handler_t | handle_group, |
void * | data | ||
) |
Iterate over all counter groups.
[in] | handle_group | function pointer of callback function |
[in] | data | Data to hand transparently to handle_group() |
References data, rate_ctr_group::list, llist_for_each_entry, and subsys.
Referenced by osmo_stats_report().
const struct rate_ctr * rate_ctr_get_by_name | ( | const struct rate_ctr_group * | ctrg, |
const char * | name | ||
) |
Search for counter based on group + name.
[in] | ctrg | pointer to rate_ctr_group |
[in] | name | name of counter inside group |
References rate_ctr_group::ctr, rate_ctr_group_desc::ctr_desc, rate_ctr_group::desc, name, rate_ctr_desc::name, rate_ctr_group_desc::num_ctr, and subsys.
struct rate_ctr_group * rate_ctr_get_group_by_name_idx | ( | const char * | name, |
const unsigned int | idx | ||
) |
Search for counter group based on group name and index.
[in] | name | Name of the counter group you're looking for |
[in] | idx | Index inside the counter group |
References rate_ctr_group::desc, rate_ctr_group_desc::group_name_prefix, rate_ctr_group::idx, rate_ctr_group::list, llist_for_each_entry, name, and subsys.
Referenced by rate_ctr_group_alloc().
Find an unused index for this rate counter group.
[in] | name | Name of the counter group |
References rate_ctr_group::desc, rate_ctr_group_desc::group_name_prefix, rate_ctr_group::idx, rate_ctr_group::list, llist_for_each_entry, name, and subsys.
Referenced by rate_ctr_group_alloc().
struct rate_ctr_group * rate_ctr_group_alloc | ( | void * | ctx, |
const struct rate_ctr_group_desc * | desc, | ||
unsigned int | idx | ||
) |
Allocate a new group of counters according to description.
[in] | ctx | parent talloc context |
[in] | desc | Rate counter group description |
[in] | idx | Index of new counter group |
References DLGLOBAL, rate_ctr_group::idx, llist_add(), LOGL_ERROR, LOGP, rate_ctr_get_group_by_name_idx(), rate_ctr_get_unused_name_idx(), rate_ctr_group_desc_mangle(), rate_ctrl_group_desc_validate(), subsys, and tall_rate_ctr_ctx.
|
static |
References DLGLOBAL, LOGL_ERROR, LOGL_INFO, LOGP, mangle_identifier_ifneeded(), name, OSMO_ASSERT, rate_ctrl_group_desc_validate(), and subsys.
Referenced by rate_ctr_group_alloc().
void rate_ctr_group_free | ( | struct rate_ctr_group * | grp | ) |
Free the memory for the specified group of counters.
References llist_del(), llist_empty(), and subsys.
Get rate counter from group, identified by index idx.
[in] | grp | Rate counter group |
[in] | idx | Index of the counter to retrieve |
References subsys.
Referenced by rate_ctr_add2(), and rate_ctr_inc2().
|
static |
References interval_expired(), RATE_CTR_INTV_DAY, RATE_CTR_INTV_HOUR, RATE_CTR_INTV_MIN, RATE_CTR_INTV_SEC, subsys, and timer_ticks.
Referenced by rate_ctr_timer_cb().
void rate_ctr_group_reset | ( | struct rate_ctr_group * | ctrg | ) |
Reset all counters in a group.
[in] | ctrg | counter group to reset |
References rate_ctr_group::ctr, rate_ctr_group::desc, rate_ctr_group_desc::num_ctr, rate_ctr_reset(), and subsys.
void rate_ctr_group_set_name | ( | struct rate_ctr_group * | grp, |
const char * | name | ||
) |
Set a name for the group of counters be used instead of index value at report time.
[in] | grp | Rate counter group |
[in] | name | Name identifier to assign to the rate counter group |
References name, osmo_talloc_replace_string(), and subsys.
References rate_ctr_group::idx.
Increment the counter by 1.
ctr | Rate counters to increment |
References rate_ctr_add().
Referenced by rate_ctr_inc2().
Increment the counter by 1.
ctrg | rate_ctr_group of counter |
idx | index into ctrg counter group |
References rate_ctr_group_get_ctr(), and rate_ctr_inc().
Initialize the counter module.
Call this once from your application.
[in] | tall_ctx | Talloc context from which rate_ctr_group will be allocated |
References DLGLOBAL, osmo_fd::fd, LOGL_ERROR, LOGP, osmo_fd_is_registered(), osmo_timerfd_schedule(), osmo_timerfd_setup(), rate_ctr_timer, rate_ctr_timer_cb(), subsys, and tall_rate_ctr_ctx.
Reset a rate counter back to zero.
[in] | ctr | counter to reset |
References rate_ctr_group::ctr, and subsys.
Referenced by rate_ctr_group_reset().
References DLGLOBAL, osmo_fd::fd, rate_ctr_group::list, llist_for_each_entry, LOGL_NOTICE, LOGP, OSMO_ASSERT, OSMO_FD_READ, rate_ctr_group_intv(), subsys, and timer_ticks.
Referenced by rate_ctr_init().
|
static |
References DEBUGP, DLGLOBAL, LOGL_ERROR, LOGP, name, osmo_identifier_valid(), and subsys.
Referenced by rate_ctr_group_alloc(), and rate_ctr_group_desc_mangle().
Referenced by rate_ctr_init().
|
static |
Referenced by rate_ctr_group_alloc(), and rate_ctr_init().
|
static |
Referenced by rate_ctr_group_intv(), and rate_ctr_timer_cb().