12#include <boost/date_time/posix_time/posix_time.hpp>
13#include <boost/date_time/gregorian/gregorian.hpp>
18using namespace boost::posix_time;
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);
79template<
typename SampleType,
typename StorageType>
80void 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));
113template<
typename SampleType,
typename Storage>
114SampleType 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);
A generic exception that is thrown when an unexpected error condition occurs.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Exception thrown if invalid statistic type is used.
static std::string typeToText(Type type)
Converts statistic type to string.
void setValue(const int64_t value)
Records absolute integer observation.
void reset()
Resets statistic.
FloatSample getFloat() const
Returns observed float sample.
void addValue(const int64_t value)
Records incremental integer observation.
StringSample getString() const
Returns observed string sample.
Type
Type of available statistics.
@ STAT_INTEGER
this statistic is unsinged 64-bit integer value
@ STAT_STRING
this statistic represents a string
@ STAT_FLOAT
this statistic is a floating point value
@ STAT_DURATION
this statistic represents time duration
isc::data::ConstElementPtr getJSON() const
Returns as a JSON structure.
IntegerSample getInteger() const
Returns observed integer sample.
Observation(const std::string &name, const int64_t value)
Constructor for integer observations.
DurationSample getDuration() const
Returns observed duration sample.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::pair< StatsDuration, boost::posix_time::ptime > DurationSample
Time Duration.
std::pair< double, boost::posix_time::ptime > FloatSample
Float (implemented as double precision)
std::pair< std::string, boost::posix_time::ptime > StringSample
String.
std::pair< int64_t, boost::posix_time::ptime > IntegerSample
Integer (implemented as signed 64-bit integer)
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::posix_time::time_duration StatsDuration
Defines duration resolution.
std::string ptimeToText(boost::posix_time::ptime t)
Converts ptime structure to text.
std::string durationToText(boost::posix_time::time_duration dur)
Converts StatsDuration to text.
Defines the logger used by the top-level component of kea-dhcp-ddns.