 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/date_time/posix_time/posix_time.hpp>
13 #include <boost/date_time/gregorian/gregorian.hpp>
18 using namespace boost::posix_time;
23 Observation::Observation(
const std::string& name,
const int64_t value)
24 :
name_(name), type_(STAT_INTEGER) {
29 :
name_(name), type_(STAT_FLOAT) {
34 :
name_(name), type_(STAT_DURATION) {
39 :
name_(name), type_(STAT_STRING) {
68 setValueInternal(value, float_samples_,
STAT_FLOAT);
76 setValueInternal(value, string_samples_,
STAT_STRING);
79 template<
typename SampleType,
typename StorageType>
80 void Observation::setValueInternal(SampleType value, StorageType& storage,
82 if (type_ != exp_type) {
84 <<
typeToText(exp_type) <<
", but the actual type is "
88 if (storage.empty()) {
89 storage.push_back(make_pair(value, microsec_clock::local_time()));
93 *storage.begin() = make_pair(value, microsec_clock::local_time());
98 return (getValueInternal<IntegerSample>(integer_samples_,
STAT_INTEGER));
102 return (getValueInternal<FloatSample>(float_samples_,
STAT_FLOAT));
106 return (getValueInternal<DurationSample>(duration_samples_,
STAT_DURATION));
110 return (getValueInternal<StringSample>(string_samples_,
STAT_STRING));
113 template<
typename SampleType,
typename Storage>
114 SampleType Observation::getValueInternal(Storage& storage, Type exp_type)
const {
115 if (type_ != exp_type) {
117 <<
typeToText(exp_type) <<
", but the actual type is "
121 if (storage.empty()) {
127 return (*storage.begin());
131 std::stringstream tmp;
149 tmp <<
"(" << type <<
")";
194 entry->add(timestamp);
std::pair< double, boost::posix_time::ptime > FloatSample
Float (implemented as double precision)
std::string ptimeToText(boost::posix_time::ptime t)
Converts ptime structure to text.
A generic exception that is thrown when an unexpected error condition occurs.
@ STAT_STRING
this statistic represents a string
boost::posix_time::time_duration StatsDuration
Defines duration resolution.
std::pair< int64_t, boost::posix_time::ptime > IntegerSample
Integer (implemented as signed 64-bit integer)
@ STAT_INTEGER
this statistic is unsinged 64-bit integer value
void reset()
Resets statistic.
void setValue(const int64_t value)
Records absolute integer observation.
static std::string typeToText(Type type)
Converts statistic type to string.
Defines the logger used by the top-level component of kea-dhcp-ddns.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string durationToText(boost::posix_time::time_duration dur)
Converts StatsDuration to text.
IntegerSample getInteger() const
Returns observed integer sample.
Exception thrown if invalid statistic type is used.
isc::data::ConstElementPtr getJSON() const
Returns as a JSON structure.
std::pair< std::string, boost::posix_time::ptime > StringSample
String.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Observation(const std::string &name, const int64_t value)
Constructor for integer observations.
@ STAT_FLOAT
this statistic is a floating point value
void addValue(const int64_t value)
Records incremental integer observation.
StringSample getString() const
Returns observed string sample.
DurationSample getDuration() const
Returns observed duration sample.
@ STAT_DURATION
this statistic represents time duration
FloatSample getFloat() const
Returns observed float sample.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< const Element > ConstElementPtr
static ElementPtr create(const Position &pos=ZERO_POSITION())
Type
Type of available statistics.
std::pair< StatsDuration, boost::posix_time::ptime > DurationSample
Time Duration.