![]() |
Kea
1.5.0
|
Statistics Manager class. More...
#include <stats_mgr.h>
Inheritance diagram for isc::stats::StatsMgr:Public Member Functions | |
| void | addObservation (const ObservationPtr &stat) |
| Adds a new observation. More... | |
| void | addValue (const std::string &name, const int64_t value) |
| Records incremental integer observation. More... | |
| void | addValue (const std::string &name, const double value) |
| Records incremental floating point observation. More... | |
| void | addValue (const std::string &name, const StatsDuration &value) |
| Records incremental duration observation. More... | |
| void | addValue (const std::string &name, const std::string &value) |
| Records incremental string observation. More... | |
| template<typename DataType > | |
| void | addValueInternal (const std::string &name, DataType value) |
| Adds specified value to a given statistic (internal version). More... | |
| size_t | count () const |
| Returns number of available statistics. More... | |
| bool | del (const std::string &name) |
| Removes specified statistic. More... | |
| isc::data::ConstElementPtr | get (const std::string &name) const |
| Returns a single statistic as a JSON structure. More... | |
| isc::data::ConstElementPtr | getAll () const |
| Returns all statistics as a JSON structure. More... | |
| ObservationPtr | getObservation (const std::string &name) const |
| Returns an observation. More... | |
| void | removeAll () |
| Removes all collected statistics. More... | |
| bool | reset (const std::string &name) |
| Resets specified statistic. More... | |
| void | resetAll () |
| Resets all collected statistics back to zero. More... | |
| void | setMaxSampleAge (const std::string &name, const StatsDuration &duration) |
| Determines maximum age of samples. More... | |
| void | setMaxSampleCount (const std::string &name, uint32_t max_samples) |
| Determines how many samples of a given statistic should be kept. More... | |
| void | setValue (const std::string &name, const int64_t value) |
| Records absolute integer observation. More... | |
| void | setValue (const std::string &name, const double value) |
| Records absolute floating point observation. More... | |
| void | setValue (const std::string &name, const StatsDuration &value) |
| Records absolute duration observation. More... | |
| void | setValue (const std::string &name, const std::string &value) |
| Records absolute string observation. More... | |
| template<typename DataType > | |
| void | setValueInternal (const std::string &name, DataType value) |
| Sets a given statistic to specified value (internal version). More... | |
Static Public Member Functions | |
| template<typename Type > | |
| static std::string | generateName (const std::string &context, Type index, const std::string &stat_name) |
| Generates statistic name in a given context. More... | |
| static StatsMgr & | instance () |
| Statistics Manager accessor method. More... | |
| static isc::data::ConstElementPtr | statisticGetAllHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-get-all command. More... | |
| static isc::data::ConstElementPtr | statisticGetHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-get command. More... | |
| static isc::data::ConstElementPtr | statisticRemoveAllHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-remove-all command. More... | |
| static isc::data::ConstElementPtr | statisticRemoveHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-remove command. More... | |
| static isc::data::ConstElementPtr | statisticResetAllHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-reset-all command. More... | |
| static isc::data::ConstElementPtr | statisticResetHandler (const std::string &name, const isc::data::ConstElementPtr ¶ms) |
| Handles statistic-reset command. More... | |
Statistics Manager class.
StatsMgr is a singleton class that represents a subsystem that manages collection, storage and reporting of various types of statistics. It is also the intended API for both core code and hooks.
As of May 2015, Tomek ran performance benchmarks (see unit-tests in stats_mgr_unittest.cc with performance in their names) and it seems the code is able to register ~2.5-3 million observations per second, even with 1000 different statistics recorded. That seems sufficient for now, so there is no immediate need to develop any multi-threading solutions for now. However, should this decision be revised in the future, the best place for it would to be modify addObservation method here. It's the common code point that all new observations must pass through. One possible way to enable multi-threading would be to run a separate thread handling collection. The main thread would call addValue and setValue methods that would end up calling addObservation. That method would pass the data to separate thread to be collected and would immediately return. Further processing would be mostly as it is today, except happening in a separate thread. One unsolved issue in this approach is how to extract data, but that will remain unsolvable until we get the control socket implementation.
Statistics Manager does not use logging by design. The reasons are:
If this decision is revisited in the future, the most universal places for adding logging have been marked in addValueInternal and setValueInternal.
Definition at line 61 of file lib/stats/stats_mgr.h.
| void isc::stats::StatsMgr::addObservation | ( | const ObservationPtr & | stat | ) |
Adds a new observation.
That's an utility method used by public setValue() and addValue() methods.
| stat | observation |
Definition at line 68 of file stats_mgr.cc.
Referenced by setValueInternal().
|
inline |
Adds specified value to a given statistic (internal version).
This template method adds specified value to a given statistic (identified by name to a value). This internal method is used by public setValue methods.
| DataType | one of int64_t, double, StatsDuration or string |
| name | name of the statistic |
| value | specified statistic will be set to this value |
| InvalidStatType | is statistic exists and has a different type. |
Definition at line 375 of file lib/stats/stats_mgr.h.
References getObservation(), and setValue().
Referenced by addValue().
Here is the call graph for this function:
|
inlinestatic |
Generates statistic name in a given context.
Example:
will return subnet[123].received-packets. Any printable type can be used as index.
| Type | any type that can be used to index contexts |
| context | name of the context (e.g. 'subnet') |
| index | value used for indexing contexts (e.g. subnet_id) |
| stat_name | name of the statistic |
Definition at line 225 of file lib/stats/stats_mgr.h.
| ObservationPtr isc::stats::StatsMgr::getObservation | ( | const std::string & | name | ) | const |
Returns an observation.
Used in testing only. Production code should use get() method.
| name | name of the statistic |
Definition at line 62 of file stats_mgr.cc.
Referenced by addValueInternal(), get(), reset(), and setValueInternal().
|
static |
Statistics Manager accessor method.
Definition at line 21 of file stats_mgr.cc.
Referenced by isc::ha::HAImpl::buffer4Receive(), isc::ha::HAImpl::buffer6Receive(), isc::dhcp::Dhcpv4Srv::processPacket(), isc::dhcp::Dhcpv4Srv::processStatsReceived(), isc::dhcp::Dhcpv4Srv::processStatsSent(), statisticGetAllHandler(), statisticGetHandler(), statisticRemoveAllHandler(), statisticRemoveHandler(), statisticResetAllHandler(), and statisticResetHandler().
|
inline |
Sets a given statistic to specified value (internal version).
This template method sets statistic identified by name to a value specified by value. This internal method is used by public setValue methods.
| DataType | one of int64_t, double, StatsDuration or string |
| name | name of the statistic |
| value | specified statistic will be set to this value |
| InvalidStatType | is statistic exists and has a different type. |
Definition at line 350 of file lib/stats/stats_mgr.h.
References addObservation(), and getObservation().
Referenced by setValue().
Here is the call graph for this function: