Kea 1.5.0
observation.h
Go to the documentation of this file.
1// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef OBSERVATION_H
8#define OBSERVATION_H
9
10#include <cc/data.h>
12#include <boost/shared_ptr.hpp>
13#include <boost/date_time/time_duration.hpp>
14#include <boost/date_time/posix_time/posix_time_types.hpp>
15#include <list>
16#include <stdint.h>
17
18namespace isc {
19namespace stats {
20
25class InvalidStatType : public Exception {
26public:
27 InvalidStatType(const char* file, size_t line, const char* what) :
28 isc::Exception(file, line, what) {}
29};
30
33typedef boost::posix_time::time_duration StatsDuration;
34
40
42typedef std::pair<int64_t, boost::posix_time::ptime> IntegerSample;
43
45typedef std::pair<double, boost::posix_time::ptime> FloatSample;
46
48typedef std::pair<StatsDuration, boost::posix_time::ptime> DurationSample;
49
51typedef std::pair<std::string, boost::posix_time::ptime> StringSample;
52
54
72 public:
73
82 enum Type {
87 };
88
93 Observation(const std::string& name, const int64_t value);
94
99 Observation(const std::string& name, const double value);
100
105 Observation(const std::string& name, const StatsDuration& value);
106
111 Observation(const std::string& name, const std::string& value);
112
117 void setValue(const int64_t value);
118
123 void setValue(const double value);
124
129 void setValue(const StatsDuration& value);
130
135 void setValue(const std::string& value);
136
141 void addValue(const int64_t value);
142
147 void addValue(const double value);
148
153 void addValue(const StatsDuration& value);
154
159 void addValue(const std::string& value);
160
164 void reset();
165
168 Type getType() const {
169 return (type_);
170 }
171
176
180 FloatSample getFloat() const;
181
186
190 StringSample getString() const;
191
195
198 static std::string typeToText(Type type);
199
201 std::string getName() const {
202 return (name_);
203 }
204
205private:
218 template<typename SampleType, typename StorageType>
219 void setValueInternal(SampleType value, StorageType& storage,
220 Type exp_type);
221
230 template<typename SampleType, typename Storage>
231 SampleType getValueInternal(Storage& storage, Type exp_type) const;
232
234 std::string name_;
235
237 Type type_;
238
245
247 std::list<IntegerSample> integer_samples_;
248
250 std::list<FloatSample> float_samples_;
251
253 std::list<DurationSample> duration_samples_;
254
256 std::list<StringSample> string_samples_;
258};
259
261typedef boost::shared_ptr<Observation> ObservationPtr;
262
263};
264};
265
266#endif // OBSERVATION_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown if invalid statistic type is used.
Definition: observation.h:25
InvalidStatType(const char *file, size_t line, const char *what)
Definition: observation.h:27
Represents a single observable characteristic (a 'statistic')
Definition: observation.h:71
static std::string typeToText(Type type)
Converts statistic type to string.
Definition: observation.cc:130
void setValue(const int64_t value)
Records absolute integer observation.
Definition: observation.cc:63
Type getType() const
Returns statistic type.
Definition: observation.h:168
void reset()
Resets statistic.
Definition: observation.cc:202
std::string getName() const
Returns observation name.
Definition: observation.h:201
FloatSample getFloat() const
Returns observed float sample.
Definition: observation.cc:101
void addValue(const int64_t value)
Records incremental integer observation.
Definition: observation.cc:43
StringSample getString() const
Returns observed string sample.
Definition: observation.cc:109
Type
Type of available statistics.
Definition: observation.h:82
@ STAT_INTEGER
this statistic is unsinged 64-bit integer value
Definition: observation.h:83
@ STAT_STRING
this statistic represents a string
Definition: observation.h:86
@ STAT_FLOAT
this statistic is a floating point value
Definition: observation.h:84
@ STAT_DURATION
this statistic represents time duration
Definition: observation.h:85
isc::data::ConstElementPtr getJSON() const
Returns as a JSON structure.
Definition: observation.cc:154
IntegerSample getInteger() const
Returns observed integer sample.
Definition: observation.cc:97
DurationSample getDuration() const
Returns observed duration sample.
Definition: observation.cc:105
std::pair< StatsDuration, boost::posix_time::ptime > DurationSample
Time Duration.
Definition: observation.h:48
std::pair< double, boost::posix_time::ptime > FloatSample
Float (implemented as double precision)
Definition: observation.h:45
std::pair< std::string, boost::posix_time::ptime > StringSample
String.
Definition: observation.h:51
std::pair< int64_t, boost::posix_time::ptime > IntegerSample
Integer (implemented as signed 64-bit integer)
Definition: observation.h:42
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::posix_time::time_duration StatsDuration
Defines duration resolution.
Definition: observation.h:33
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
Definition: observation.h:261
Defines the logger used by the top-level component of kea-dhcp-ddns.