22 std::pair<bool, uint32_t>
23 Observation::default_max_sample_count_ = std::make_pair(
true, 20);
25 std::pair<bool, StatsDuration>
26 Observation::default_max_sample_age_ =
27 std::make_pair(
false, StatsDuration::zero());
29 Observation::Observation(
const std::string& name,
const int64_t value) :
30 name_(name), type_(STAT_INTEGER),
31 max_sample_count_(default_max_sample_count_),
32 max_sample_age_(default_max_sample_age_) {
37 name_(name), type_(STAT_FLOAT),
38 max_sample_count_(default_max_sample_count_),
39 max_sample_age_(default_max_sample_age_) {
44 name_(name), type_(STAT_DURATION),
45 max_sample_count_(default_max_sample_count_),
46 max_sample_age_(default_max_sample_age_) {
51 name_(name), type_(STAT_STRING),
52 max_sample_count_(default_max_sample_count_),
53 max_sample_age_(default_max_sample_age_) {
60 setMaxSampleAgeInternal(integer_samples_, duration,
STAT_INTEGER);
64 setMaxSampleAgeInternal(float_samples_, duration,
STAT_FLOAT);
68 setMaxSampleAgeInternal(duration_samples_, duration,
STAT_DURATION);
72 setMaxSampleAgeInternal(string_samples_, duration,
STAT_STRING);
84 setMaxSampleCountInternal(integer_samples_, max_samples,
STAT_INTEGER);
88 setMaxSampleCountInternal(float_samples_, max_samples,
STAT_FLOAT);
92 setMaxSampleCountInternal(duration_samples_, max_samples,
STAT_DURATION);
96 setMaxSampleCountInternal(string_samples_, max_samples,
STAT_STRING);
126 setValueInternal(value, integer_samples_,
STAT_INTEGER);
130 setValueInternal(value, float_samples_,
STAT_FLOAT);
138 setValueInternal(value, string_samples_,
STAT_STRING);
149 size = getSizeInternal(float_samples_,
STAT_FLOAT);
157 size = getSizeInternal(string_samples_,
STAT_STRING);
168 return (max_sample_age_);
172 return (max_sample_count_);
175 template<
typename StorageType>
176 size_t Observation::getSizeInternal(StorageType& storage, Type exp_type)
const {
177 if (type_ != exp_type) {
179 <<
typeToText(exp_type) <<
", but the actual type is "
182 return (storage.size());
187 template<
typename SampleType,
typename StorageType>
188 void Observation::setValueInternal(SampleType value, StorageType& storage,
190 if (type_ != exp_type) {
191 isc_throw(InvalidStatType,
"Invalid statistic type requested: "
192 <<
typeToText(exp_type) <<
", but the actual type is "
196 if (storage.empty()) {
197 storage.push_back(make_pair(value, SampleClock::now()));
200 storage.push_front(make_pair(value, SampleClock::now()));
202 if (max_sample_count_.first) {
205 if (storage.size() > max_sample_count_.second) {
210 storage.front().second - storage.back().second;
213 while (range_of_storage > max_sample_age_.second) {
216 storage.front().second - storage.back().second;
223 return (getValueInternal<IntegerSample>(integer_samples_,
STAT_INTEGER));
227 return (getValueInternal<FloatSample>(float_samples_,
STAT_FLOAT));
231 return (getValueInternal<DurationSample>(duration_samples_,
STAT_DURATION));
235 return (getValueInternal<StringSample>(string_samples_,
STAT_STRING));
238 template<
typename SampleType,
typename Storage>
239 SampleType Observation::getValueInternal(Storage& storage, Type exp_type)
const {
240 if (type_ != exp_type) {
242 <<
typeToText(exp_type) <<
", but the actual type is "
246 if (storage.empty()) {
252 return (*storage.begin());
256 return (getValuesInternal<IntegerSample>(integer_samples_,
STAT_INTEGER));
260 return (getValuesInternal<FloatSample>(float_samples_,
STAT_FLOAT));
264 return (getValuesInternal<DurationSample>(duration_samples_,
STAT_DURATION));
268 return (getValuesInternal<StringSample>(string_samples_,
STAT_STRING));
271 template<
typename SampleType,
typename Storage>
272 std::list<SampleType> Observation::getValuesInternal(Storage& storage,
273 Type exp_type)
const {
274 if (type_ != exp_type) {
276 <<
typeToText(exp_type) <<
", but the actual type is "
280 if (storage.empty()) {
289 template<
typename StorageType>
290 void Observation::setMaxSampleAgeInternal(StorageType& storage,
293 if (type_ != exp_type) {
294 isc_throw(InvalidStatType,
"Invalid statistic type requested: "
295 <<
typeToText(exp_type) <<
", but the actual type is "
299 max_sample_age_.first =
true;
300 max_sample_age_.second = duration;
302 max_sample_count_.first =
false;
305 storage.front().second - storage.back().second;
307 while (range_of_storage > duration) {
310 range_of_storage = storage.front().second - storage.back().second;
314 template<
typename StorageType>
315 void Observation::setMaxSampleCountInternal(StorageType& storage,
316 uint32_t max_samples,
318 if (type_ != exp_type) {
319 isc_throw(InvalidStatType,
"Invalid statistic type requested: "
320 <<
typeToText(exp_type) <<
", but the actual type is "
325 max_sample_count_.first =
true;
326 max_sample_count_.second = max_samples;
328 max_sample_age_.first =
false;
330 while (storage.size() > max_samples) {
338 default_max_sample_age_.second = duration;
342 if (max_samples == 0) {
344 default_max_sample_count_.first =
false;
345 default_max_sample_age_.first =
true;
348 default_max_sample_count_.second = max_samples;
350 default_max_sample_age_.first =
false;
351 default_max_sample_count_.first =
true;
356 return (default_max_sample_age_.second);
360 if (default_max_sample_count_.first) {
361 return (default_max_sample_count_.second);
368 std::stringstream tmp;
386 tmp <<
"(" << type <<
")";
406 for (std::list<IntegerSample>::iterator it = s.begin(); it != s.end(); ++it) {
412 entry->add(timestamp);
423 for (std::list<FloatSample>::iterator it = s.begin(); it != s.end(); ++it) {
429 entry->add(timestamp);
440 for (std::list<DurationSample>::iterator it = s.begin(); it != s.end(); ++it) {
446 entry->add(timestamp);
457 for (std::list<StringSample>::iterator it = s.begin(); it != s.end(); ++it) {
463 entry->add(timestamp);
480 integer_samples_.clear();
485 float_samples_.clear();
490 duration_samples_.clear();
495 string_samples_.clear();
void addValue(const int64_t value)
Records incremental integer observation.
this statistic is unsigned 64-bit integer value
std::pair< double, SampleClock::time_point > FloatSample
Float (implemented as double precision)
this statistic represents a string
std::pair< bool, uint32_t > getMaxSampleCount() const
Returns both values of max_sample_count_ of statistic.
static void setMaxSampleAgeDefault(const StatsDuration &duration)
Determines default maximum age of samples.
std::list< FloatSample > getFloats() const
Returns observed float samples.
DurationSample getDuration() const
Returns observed duration sample.
static uint32_t getMaxSampleCountDefault()
Get default maximum count of samples.
this statistic is a floating point value
boost::shared_ptr< Element > ElementPtr
Observation(const std::string &name, const int64_t value)
Constructor for integer observations.
std::list< IntegerSample > getIntegers() const
Returns observed integer samples.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
std::chrono::system_clock::duration StatsDuration
Defines duration type.
std::string durationToText(boost::posix_time::time_duration dur, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts StatsDuration to text.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
size_t getSize() const
Returns size of observed storage.
void reset()
Resets statistic.
isc::data::ConstElementPtr getJSON() const
Returns as a JSON structure.
std::pair< std::string, SampleClock::time_point > StringSample
String.
A generic exception that is thrown when an unexpected error condition occurs.
boost::shared_ptr< const Element > ConstElementPtr
IntegerSample getInteger() const
Returns observed integer sample.
std::pair< int64_t, SampleClock::time_point > IntegerSample
Integer (implemented as signed 64-bit integer)
this statistic represents time duration
Defines the logger used by the top-level component of kea-dhcp-ddns.
static const StatsDuration & getMaxSampleAgeDefault()
Get default maximum age of samples.
FloatSample getFloat() const
Returns observed float sample.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static void setMaxSampleCountDefault(uint32_t max_samples)
Determines default maximum count of samples.
std::list< DurationSample > getDurations() const
Returns observed duration samples.
std::pair< bool, StatsDuration > getMaxSampleAge() const
Returns both values of max_sample_age_ of statistic.
void setValue(const int64_t value)
@
std::list< StringSample > getStrings() const
Returns observed string samples.
StringSample getString() const
Returns observed string sample.
void setMaxSampleAge(const StatsDuration &duration)
Determines maximum age of samples.
Type
Type of available statistics.
static std::string typeToText(Type type)
Converts statistic type to string.
void setMaxSampleCount(uint32_t max_samples)
Determines how many samples of a given statistic should be kept.
std::string clockToText(std::chrono::system_clock::time_point t, size_t fsecs_precision)
Converts chrono time point structure to text.
Exception thrown if invalid statistic type is used.
std::pair< StatsDuration, SampleClock::time_point > DurationSample
Time Duration.