This page has been visited 296 times.
Statistics API |
OpenSIPS exposes a statistics API that can be used both from the core or the modules. The statistics are essentially counters that will be internally incremented/decremented by OpenSIPS and that can be fetched by the outside world ( via the MI interface ) for understanding the OpenSIPS load / health status / etc.
The advantages of using the OpenSIPS Statistics API instead of regular counters is :
The most important structures used for extending statistics are exported by statistics.h :
For example, the core stats exported by OpenSIPS are defined in the following array :
As note from the above structure, statistics can either be a simple counter ( eg. rcv_requests ), but it can also be a function. Statistics function might come in handy when the developer needs to do extra processing on the raw counters before providing the final output.
After defining your array of statistics that you want to export, one should use the following for exporting the stats to be accessible by all
Note that register_module_stats will export the statistics, and also allocate them in SHM memory, for them to be accessible by all OpenSIPS processes.
Important to note here that all the above statistics related functions MUST be called in the context of the attendant process before forking is done.
At runtime, the developer has access to the following functions for operating on statistics :
All statistics related code should be guarded by #ifdef STATISTICS , since the statistics are not a mandatory part of the OpenSIPS core ( they can be disabled from within menuconfig ).
For fetching the mynewstat statistic exported by the mynewmod module, one can use the opensipsctl like this :
opensipsctl fifo get_statistics mynewmod mynewstat
For fetching all the statistics exported by the mynewmod module, you can use
opensipsctl fifo get_statistics mynewmod: