Kea  1.5.0
isc::stats::Observation Class Reference

Represents a single observable characteristic (a 'statistic') More...

#include <observation.h>

Public Types

enum  Type { STAT_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. More...
 
 Observation (const std::string &name, const int64_t value)
 Constructor for integer observations. More...
 
 Observation (const std::string &name, const StatsDuration &value)
 Constructor for duration observations. More...
 
 Observation (const std::string &name, const std::string &value)
 Constructor for string observations. More...
 
void addValue (const double value)
 Records incremental floating point observation. More...
 
void addValue (const int64_t value)
 Records incremental integer observation. More...
 
void addValue (const StatsDuration &value)
 Records incremental duration observation. More...
 
void addValue (const std::string &value)
 Records incremental string observation. More...
 
DurationSample getDuration () const
 Returns observed duration sample. More...
 
FloatSample getFloat () const
 Returns observed float sample. More...
 
IntegerSample getInteger () const
 Returns observed integer sample. More...
 
isc::data::ConstElementPtr getJSON () const
 Returns as a JSON structure. More...
 
std::string getName () const
 Returns observation name. More...
 
StringSample getString () const
 Returns observed string sample. More...
 
Type getType () const
 Returns statistic type. More...
 
void reset ()
 Resets statistic. More...
 
void setValue (const double value)
 Records absolute floating point observation. More...
 
void setValue (const int64_t value)
 Records absolute integer observation. More...
 
void setValue (const StatsDuration &value)
 Records absolute duration observation. More...
 
void setValue (const std::string &value)
 Records absolute string observation. More...
 

Static Public Member Functions

static std::string typeToText (Type type)
 Converts statistic type to string. More...
 

Detailed Description

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.

Todo:
: Eventually it will be possible to retain multiple samples for the same observation, but that is outside of scope for 0.9.2.

Definition at line 71 of file observation.h.

Member Enumeration Documentation

◆ Type

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.

Enumerator
STAT_INTEGER 

this statistic is unsinged 64-bit integer value

STAT_FLOAT 

this statistic is a floating point value

STAT_DURATION 

this statistic represents time duration

STAT_STRING 

this statistic represents a string

Definition at line 82 of file observation.h.

Constructor & Destructor Documentation

◆ Observation() [1/4]

isc::stats::Observation::Observation ( const std::string &  name,
const int64_t  value 
)

Constructor for integer observations.

Parameters
nameobservation name
valueinteger value observed.

Definition at line 23 of file observation.cc.

References setValue().

+ Here is the call graph for this function:

◆ Observation() [2/4]

isc::stats::Observation::Observation ( const std::string &  name,
const double  value 
)

Constructor for floating point observations.

Parameters
nameobservation name
valuefloating point value observed.

Definition at line 28 of file observation.cc.

References setValue().

+ Here is the call graph for this function:

◆ Observation() [3/4]

isc::stats::Observation::Observation ( const std::string &  name,
const StatsDuration value 
)

Constructor for duration observations.

Parameters
nameobservation name
valueduration observed.

Definition at line 33 of file observation.cc.

References setValue().

+ Here is the call graph for this function:

◆ Observation() [4/4]

isc::stats::Observation::Observation ( const std::string &  name,
const std::string &  value 
)

Constructor for string observations.

Parameters
nameobservation name
valuestring observed.

Definition at line 38 of file observation.cc.

References setValue().

+ Here is the call graph for this function:

Member Function Documentation

◆ addValue() [1/4]

void isc::stats::Observation::addValue ( const double  value)

Records incremental floating point observation.

Parameters
valuefloating point value observed
Exceptions
InvalidStatTypeif statistic is not fp

Definition at line 48 of file observation.cc.

References getFloat(), and setValue().

+ Here is the call graph for this function:

◆ addValue() [2/4]

void isc::stats::Observation::addValue ( const int64_t  value)

Records incremental integer observation.

Parameters
valueinteger value observed
Exceptions
InvalidStatTypeif statistic is not integer

Definition at line 43 of file observation.cc.

References getInteger(), and setValue().

+ Here is the call graph for this function:

◆ addValue() [3/4]

void isc::stats::Observation::addValue ( const StatsDuration value)

Records incremental duration observation.

Parameters
valueduration value observed
Exceptions
InvalidStatTypeif statistic is not time duration

Definition at line 53 of file observation.cc.

References getDuration(), and setValue().

+ Here is the call graph for this function:

◆ addValue() [4/4]

void isc::stats::Observation::addValue ( const std::string &  value)

Records incremental string observation.

Parameters
valuestring value observed
Exceptions
InvalidStatTypeif statistic is not a string

Definition at line 58 of file observation.cc.

References getString(), and setValue().

+ Here is the call graph for this function:

◆ getDuration()

DurationSample isc::stats::Observation::getDuration ( ) const

Returns observed duration sample.

Returns
observed sample (value + timestamp)
Exceptions
InvalidStatTypeif statistic is not time duration

Definition at line 105 of file observation.cc.

References STAT_DURATION.

Referenced by addValue(), and getJSON().

◆ getFloat()

FloatSample isc::stats::Observation::getFloat ( ) const

Returns observed float sample.

Returns
observed sample (value + timestamp)
Exceptions
InvalidStatTypeif statistic is not fp

Definition at line 101 of file observation.cc.

References STAT_FLOAT.

Referenced by addValue(), and getJSON().

◆ getInteger()

IntegerSample isc::stats::Observation::getInteger ( ) const

Returns observed integer sample.

Returns
observed sample (value + timestamp)
Exceptions
InvalidStatTypeif statistic is not integer

Definition at line 97 of file observation.cc.

References STAT_INTEGER.

Referenced by addValue(), and getJSON().

◆ getJSON()

isc::data::ConstElementPtr isc::stats::Observation::getJSON ( ) const

Returns as a JSON structure.

Returns
JSON structures representing all observations
Todo:
: Add support for retrieving more than one sample for a given observation

Definition at line 154 of file observation.cc.

References isc::data::Element::create(), isc::data::Element::createList(), isc::util::durationToText(), getDuration(), getFloat(), getInteger(), getString(), isc_throw, isc::util::ptimeToText(), STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().

+ Here is the call graph for this function:

◆ getName()

std::string isc::stats::Observation::getName ( ) const
inline

Returns observation name.

Definition at line 201 of file observation.h.

◆ getString()

StringSample isc::stats::Observation::getString ( ) const

Returns observed string sample.

Returns
observed sample (value + timestamp)
Exceptions
InvalidStatTypeif statistic is not a string

Definition at line 109 of file observation.cc.

References STAT_STRING.

Referenced by addValue(), and getJSON().

◆ getType()

Type isc::stats::Observation::getType ( ) const
inline

Returns statistic type.

Returns
statistic type

Definition at line 168 of file observation.h.

◆ reset()

void isc::stats::Observation::reset ( )

Resets statistic.

Sets statistic to a neutral (0, 0.0 or "") value.

Definition at line 202 of file observation.cc.

References isc_throw, setValue(), STAT_DURATION, STAT_FLOAT, STAT_INTEGER, STAT_STRING, and typeToText().

+ Here is the call graph for this function:

◆ setValue() [1/4]

void isc::stats::Observation::setValue ( const double  value)

Records absolute floating point observation.

Parameters
valuefloating point value observed
Exceptions
InvalidStatTypeif statistic is not fp

Definition at line 67 of file observation.cc.

References STAT_FLOAT.

◆ setValue() [2/4]

void isc::stats::Observation::setValue ( const int64_t  value)

Records absolute integer observation.

Parameters
valueinteger value observed
Exceptions
InvalidStatTypeif statistic is not integer

Definition at line 63 of file observation.cc.

References STAT_INTEGER.

Referenced by addValue(), Observation(), and reset().

◆ setValue() [3/4]

void isc::stats::Observation::setValue ( const StatsDuration value)

Records absolute duration observation.

Parameters
valueduration value observed
Exceptions
InvalidStatTypeif statistic is not time duration

Definition at line 71 of file observation.cc.

References STAT_DURATION.

◆ setValue() [4/4]

void isc::stats::Observation::setValue ( const std::string &  value)

Records absolute string observation.

Parameters
valuestring value observed
Exceptions
InvalidStatTypeif statistic is not a string

Definition at line 75 of file observation.cc.

References STAT_STRING.

◆ typeToText()

std::string isc::stats::Observation::typeToText ( Type  type)
static

Converts statistic type to string.

Returns
textual name of statistic type

Definition at line 130 of file observation.cc.

References STAT_DURATION, STAT_FLOAT, STAT_INTEGER, and STAT_STRING.

Referenced by getJSON(), and reset().


The documentation for this class was generated from the following files: