Kea 2.7.5
|
Represents a single observable characteristic (a 'statistic') More...
#include <observation.h>
Public Types | |
enum | Type { STAT_INTEGER , STAT_BIG_INTEGER , STAT_FLOAT , STAT_DURATION , STAT_STRING } |
Type of available statistics. More... | |
Public Member Functions | |
Observation (const std::string &name, const double value) | |
Constructor for floating point observations. | |
Observation (const std::string &name, const int64_t value) | |
Constructor for integer observations. | |
Observation (const std::string &name, const isc::util::int128_t &value) | |
Constructor for big integer observations. | |
Observation (const std::string &name, const StatsDuration &value) | |
Constructor for duration observations. | |
Observation (const std::string &name, const std::string &value) | |
Constructor for string observations. | |
void | addValue (const double value) |
Records incremental floating point observation. | |
void | addValue (const int64_t value) |
Records incremental integer observation. | |
void | addValue (const isc::util::int128_t &value) |
Records incremental integer observation. | |
void | addValue (const StatsDuration &value) |
Records incremental duration observation. | |
void | addValue (const std::string &value) |
Records incremental string observation. | |
BigIntegerSample | getBigInteger () const |
Returns observed integer sample. | |
std::list< BigIntegerSample > | getBigIntegers () const |
Returns observed big-integer samples. | |
DurationSample | getDuration () const |
Returns observed duration sample. | |
std::list< DurationSample > | getDurations () const |
Returns observed duration samples. | |
FloatSample | getFloat () const |
Returns observed float sample. | |
std::list< FloatSample > | getFloats () const |
Returns observed float samples. | |
IntegerSample | getInteger () const |
Returns observed integer sample. | |
std::list< IntegerSample > | getIntegers () const |
Returns observed integer samples. | |
isc::data::ConstElementPtr | getJSON () const |
Returns as a JSON structure. | |
std::pair< bool, StatsDuration > | getMaxSampleAge () const |
Returns both values of max_sample_age_ of statistic. | |
std::pair< bool, uint32_t > | getMaxSampleCount () const |
Returns both values of max_sample_count_ of statistic. | |
std::string | getName () const |
Returns observation name. | |
size_t | getSize () const |
Returns size of observed storage. | |
StringSample | getString () const |
Returns observed string sample. | |
std::list< StringSample > | getStrings () const |
Returns observed string samples. | |
Type | getType () const |
Returns statistic type. | |
void | reset () |
Resets statistic. | |
void | setMaxSampleAge (const StatsDuration &duration) |
Determines maximum age of samples. | |
void | setMaxSampleCount (uint32_t max_samples) |
Determines how many samples of a given statistic should be kept. | |
void | setValue (const double value) |
Records absolute floating point observation. | |
void | setValue (const int64_t value) |
@ | |
void | setValue (const isc::util::int128_t &value) |
Records big integer observation. | |
void | setValue (const StatsDuration &value) |
Records absolute duration observation. | |
void | setValue (const std::string &value) |
Records absolute string observation. | |
Static Public Member Functions | |
static const StatsDuration & | getMaxSampleAgeDefault () |
Get default maximum age of samples. | |
static uint32_t | getMaxSampleCountDefault () |
Get default maximum count of samples. | |
static void | setMaxSampleAgeDefault (const StatsDuration &duration) |
Determines default maximum age of samples. | |
static void | setMaxSampleCountDefault (uint32_t max_samples) |
Determines default maximum count of samples. | |
static std::string | typeToText (Type type) |
Converts statistic type to string. | |
Represents a single observable characteristic (a 'statistic')
Currently it supports one of four types: integer (implemented as signed 64 bit integer), float (implemented as double), time duration (implemented with millisecond precision) and string. Absolute (setValue) and incremental (addValue) modes are supported. Statistic type is determined during its first use. Once type is set, any additional observations recorded must be of the same type. Attempting to set or extract information about other types will result in InvalidStateType exception.
Observation can be retrieved in one of getInteger, getFloat, getDuration, getString (appropriate type must be used) or getJSON, which is generic and can be used for all types.
Since Kea 1.6 multiple samples are stored for the same observation.
Definition at line 91 of file observation.h.
Type of available statistics.
Note that those will later be exposed using control socket. Therefore an easy to understand names were chosen (integer instead of uint64). To avoid confusion, we will support only one type of integer and only one type of floating points. Initially, these are represented by int64_t and double. If convincing use cases appear to change them to something else, we may change the underlying type.
Definition at line 102 of file observation.h.
isc::stats::Observation::Observation | ( | const std::string & | name, |
const int64_t | value ) |
Constructor for integer observations.
name | observation name |
value | integer value observed. |
Definition at line 31 of file observation.cc.
References setValue().
isc::stats::Observation::Observation | ( | const std::string & | name, |
const isc::util::int128_t & | value ) |
Constructor for big integer observations.
name | observation name |
value | integer value observed. |
Definition at line 38 of file observation.cc.
References setValue().
isc::stats::Observation::Observation | ( | const std::string & | name, |
const double | value ) |
Constructor for floating point observations.
name | observation name |
value | floating point value observed. |
Definition at line 45 of file observation.cc.
References setValue().
isc::stats::Observation::Observation | ( | const std::string & | name, |
const StatsDuration & | value ) |
Constructor for duration observations.
name | observation name |
value | duration observed. |
Definition at line 52 of file observation.cc.
References setValue().
isc::stats::Observation::Observation | ( | const std::string & | name, |
const std::string & | value ) |
Constructor for string observations.
name | observation name |
value | string observed. |
Definition at line 59 of file observation.cc.
References setValue().
void isc::stats::Observation::addValue | ( | const double | value | ) |
Records incremental floating point observation.
value | floating point value observed |
InvalidStatType | if statistic is not fp |
Definition at line 132 of file observation.cc.
References getFloat(), and setValue().
void isc::stats::Observation::addValue | ( | const int64_t | value | ) |
Records incremental integer observation.
value | integer value observed |
InvalidStatType | if statistic is not integer |
Definition at line 122 of file observation.cc.
References getInteger(), and setValue().
void isc::stats::Observation::addValue | ( | const isc::util::int128_t & | value | ) |
Records incremental integer observation.
value | integer value observed |
InvalidStatType | if statistic is not integer |
Definition at line 127 of file observation.cc.
References getBigInteger(), and setValue().
void isc::stats::Observation::addValue | ( | const StatsDuration & | value | ) |
Records incremental duration observation.
value | duration value observed |
InvalidStatType | if statistic is not time duration |
Definition at line 137 of file observation.cc.
References getDuration(), and setValue().
void isc::stats::Observation::addValue | ( | const std::string & | value | ) |
Records incremental string observation.
value | string value observed |
InvalidStatType | if statistic is not a string |
Definition at line 142 of file observation.cc.
References getString(), and setValue().
BigIntegerSample isc::stats::Observation::getBigInteger | ( | ) | const |
Returns observed integer sample.
InvalidStatType | if statistic is not integer |
Definition at line 256 of file observation.cc.
References STAT_BIG_INTEGER.
Referenced by addValue().
std::list< BigIntegerSample > isc::stats::Observation::getBigIntegers | ( | ) | const |
Returns observed big-integer samples.
InvalidStatType | if statistic is not integer |
Definition at line 293 of file observation.cc.
References STAT_BIG_INTEGER.
Referenced by getJSON().
DurationSample isc::stats::Observation::getDuration | ( | ) | const |
Returns observed duration sample.
InvalidStatType | if statistic is not time duration |
Definition at line 264 of file observation.cc.
References STAT_DURATION.
Referenced by addValue().
std::list< DurationSample > isc::stats::Observation::getDurations | ( | ) | const |
Returns observed duration samples.
InvalidStatType | if statistic is not time duration |
Definition at line 301 of file observation.cc.
References STAT_DURATION.
Referenced by getJSON().
FloatSample isc::stats::Observation::getFloat | ( | ) | const |
Returns observed float sample.
InvalidStatType | if statistic is not fp |
Definition at line 260 of file observation.cc.
References STAT_FLOAT.
Referenced by addValue().
std::list< FloatSample > isc::stats::Observation::getFloats | ( | ) | const |
Returns observed float samples.
InvalidStatType | if statistic is not fp |
Definition at line 297 of file observation.cc.
References STAT_FLOAT.
Referenced by getJSON().
IntegerSample isc::stats::Observation::getInteger | ( | ) | const |
Returns observed integer sample.
InvalidStatType | if statistic is not integer |
Definition at line 252 of file observation.cc.
References STAT_INTEGER.
Referenced by addValue().
std::list< IntegerSample > isc::stats::Observation::getIntegers | ( | ) | const |
Returns observed integer samples.
InvalidStatType | if statistic is not integer |
Definition at line 289 of file observation.cc.
References STAT_INTEGER.
Referenced by getJSON().
isc::data::ConstElementPtr isc::stats::Observation::getJSON | ( | ) | const |
Returns as a JSON structure.
Definition at line 432 of file observation.cc.
References isc::util::clockToText(), isc::data::Element::create(), isc::data::Element::createList(), isc::util::durationToText(), getBigIntegers(), getDurations(), getFloats(), getIntegers(), getStrings(), isc_throw, STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().
std::pair< bool, StatsDuration > isc::stats::Observation::getMaxSampleAge | ( | ) | const |
Returns both values of max_sample_age_ of statistic.
Definition at line 197 of file observation.cc.
|
static |
Get default maximum age of samples.
Definition at line 393 of file observation.cc.
std::pair< bool, uint32_t > isc::stats::Observation::getMaxSampleCount | ( | ) | const |
Returns both values of max_sample_count_ of statistic.
Definition at line 201 of file observation.cc.
|
static |
Get default maximum count of samples.
Definition at line 397 of file observation.cc.
|
inline |
Returns observation name.
Definition at line 341 of file observation.h.
size_t isc::stats::Observation::getSize | ( | ) | const |
Returns size of observed storage.
Definition at line 167 of file observation.cc.
References isc_throw, STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().
StringSample isc::stats::Observation::getString | ( | ) | const |
Returns observed string sample.
InvalidStatType | if statistic is not a string |
Definition at line 268 of file observation.cc.
References STAT_STRING.
Referenced by addValue().
std::list< StringSample > isc::stats::Observation::getStrings | ( | ) | const |
Returns observed string samples.
InvalidStatType | if statistic is not a string |
Definition at line 305 of file observation.cc.
References STAT_STRING.
Referenced by getJSON().
|
inline |
void isc::stats::Observation::reset | ( | ) |
Resets statistic.
Sets statistic to a neutral (0, 0.0 or "") value and clears the underlying storage.
Definition at line 534 of file observation.cc.
References isc_throw, setValue(), STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().
void isc::stats::Observation::setMaxSampleAge | ( | const StatsDuration & | duration | ) |
Determines maximum age of samples.
Specifies that statistic name should be stored not as a single value, but rather as a set of values. The duration determines the timespan. Samples older than duration will be discarded. This is time-constrained approach. For sample count constrained approach, see setMaxSampleCount() below.
duration | determines maximum age of samples Example: To set a statistic to keep observations for the last 5 minutes, call: setMaxSampleAge(std::chrono::minutes(5)); To revert statistic to a single value, call: setMaxSampleAge(StatsDuration::zero()); |
Definition at line 66 of file observation.cc.
References isc_throw, STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().
|
static |
Determines default maximum age of samples.
duration | default maximum age of samples to keep. |
Definition at line 374 of file observation.cc.
void isc::stats::Observation::setMaxSampleCount | ( | uint32_t | max_samples | ) |
Determines how many samples of a given statistic should be kept.
Specifies that statistic name should be stored not as a single value, but rather as a set of values. In this form, at most max_samples will be kept. When adding max_samples + 1 sample, the oldest sample will be discarded.
max_samples | how many samples of a given statistic should be kept Example: To set a statistic to keep the last 100 observations, call: setMaxSampleCount(100); |
Definition at line 94 of file observation.cc.
References isc_throw, STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().
|
static |
Determines default maximum count of samples.
max_samples | default maximum count of samples to keep. (0 means to disable count limit and enable age limit) |
Definition at line 379 of file observation.cc.
void isc::stats::Observation::setValue | ( | const double | value | ) |
Records absolute floating point observation.
value | floating point value observed |
InvalidStatType | if statistic is not fp |
Definition at line 155 of file observation.cc.
References STAT_FLOAT.
void isc::stats::Observation::setValue | ( | const int64_t | value | ) |
@
Records absolute integer observation
value | integer value observed |
InvalidStatType | if statistic is not integer |
Definition at line 147 of file observation.cc.
References STAT_INTEGER.
Referenced by Observation(), Observation(), Observation(), Observation(), Observation(), addValue(), addValue(), addValue(), addValue(), addValue(), and reset().
void isc::stats::Observation::setValue | ( | const isc::util::int128_t & | value | ) |
Records big integer observation.
value | integer value observed |
InvalidStatType | if statistic is not integer |
Definition at line 151 of file observation.cc.
References STAT_BIG_INTEGER.
void isc::stats::Observation::setValue | ( | const StatsDuration & | value | ) |
Records absolute duration observation.
value | duration value observed |
InvalidStatType | if statistic is not time duration |
Definition at line 159 of file observation.cc.
References STAT_DURATION.
void isc::stats::Observation::setValue | ( | const std::string & | value | ) |
Records absolute string observation.
value | string value observed |
InvalidStatType | if statistic is not a string |
Definition at line 163 of file observation.cc.
References STAT_STRING.
|
static |
Converts statistic type to string.
Definition at line 405 of file observation.cc.
References STAT_BIG_INTEGER, STAT_DURATION, STAT_FLOAT, STAT_INTEGER, and STAT_STRING.
Referenced by getJSON(), getSize(), reset(), setMaxSampleAge(), and setMaxSampleCount().