16using namespace boost::posix_time;
24 : start_time_(start_time), occurrences_(0),
25 min_duration_(pos_infin), max_duration_(neg_infin),
26 total_duration_(microseconds(0)) {
32 if (duration < min_duration_) {
33 min_duration_ = duration;
36 if (duration > max_duration_) {
37 max_duration_ = duration;
40 total_duration_ += duration;
49 return (total_duration_ / occurrences_);
54 return ((start_time_ == other.start_time_) &&
55 (occurrences_ == other.occurrences_) &&
56 (min_duration_ == other.min_duration_) &&
57 (max_duration_ == other.max_duration_) &&
58 (total_duration_ == other.total_duration_));
65 uint8_t response_type,
66 const std::string& start_event_label,
67 const std::string& stop_event_label,
70 query_type_(query_type),
71 response_type_(response_type),
72 start_event_label_(start_event_label),
73 stop_event_label_(stop_event_label),
74 subnet_id_(subnet_id) {
75 if (family != AF_INET && family != AF_INET6) {
84 if (family == AF_INET) {
125 <<
" not valid for query type: " <<
Pkt4::getName(query_type));
155 <<
" not valid for query type: " <<
Pkt6::getName(query_type));
161 if (family == AF_INET) {
170 std::ostringstream oss;
182 std::ostringstream oss;
192 <<
"." << value_name;
210 return (!(*
this == other));
232 uint8_t response_type,
233 const std::string& start_event_label,
234 const std::string& stop_event_label,
237 :
DurationKey(family, query_type, response_type, start_event_label, stop_event_label, subnet_id),
238 interval_duration_(interval_duration),
239 current_interval_(0),
240 previous_interval_(0) {
242 isc_throw(
BadValue,
"MonitoredDuration - interval_duration " << interval_duration_
243 <<
", is invalid, it must be greater than 0");
250 interval_duration_(interval_duration),
251 current_interval_(0),
252 previous_interval_(0) {
254 isc_throw(
BadValue,
"MonitoredDuration - interval_duration " << interval_duration_
255 <<
", is invalid, it must be greater than 0");
261 interval_duration_(rhs.interval_duration_),
262 current_interval_(0),
263 previous_interval_(0) {
264 if (rhs.current_interval_) {
268 if (rhs.previous_interval_) {
275 return (current_interval_ ? current_interval_->getStartTime()
282 bool do_report =
false;
283 if (!current_interval_) {
285 }
else if ((now - current_interval_->getStartTime()) > interval_duration_) {
286 previous_interval_ = current_interval_;
291 current_interval_->addDuration(sample);
297 if (!current_interval_) {
299 " - no current interval for: " <<
getLabel());
302 previous_interval_ = current_interval_;
303 current_interval_.reset();
308 current_interval_.reset();
309 previous_interval_.reset();
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
const char * getName() const
Returns name of the DHCP message.
const char * getName() const
Returns name of the DHCPv6 message.
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
static boost::posix_time::ptime & MIN_TIME()
Fetches the minimum timestamp.
Embodies a span of time (i.e.
DurationDataInterval(const Timestamp &start_time=dhcp::PktEvent::now())
Constructor.
static const Duration & ZERO_DURATION()
Get a duration of zero.
bool operator==(const DurationDataInterval &other) const
Equality operator.
Duration getAverageDuration() const
Get the average duration for the interval.
void addDuration(const Duration &duration)
Add a duration to the interval.
Houses the composite key that uniquely identifies a duration:
bool operator!=(const DurationKey &other) const
Inequality operator.
isc::dhcp::SubnetID subnet_id_
Subnet ID of the subnet selected during query fulfillment.
static std::string getMessageTypeLabel(uint16_t family, uint16_t msg_type)
Get a label for a family-specific message type (e.g.
uint8_t response_type_
Response message type (e.g. DHCPOFFER, DHCP6_ADVERTISE).
bool operator<(const DurationKey &other) const
Less than operator.
std::string start_event_label_
Label of the start event which begins the duration.
bool operator==(const DurationKey &other) const
Equality operator.
DurationKey(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id)
Constructor.
uint16_t family_
Protocol family AF_INET or AF_INET6.
std::string getStatName(const std::string &value_name) const
Get the StatsMgr formatted compatible name.
static void validateMessagePair(uint16_t family, uint8_t query_type, uint8_t response_type)
Validates that a query and response message type pair is sane.
std::string stop_event_label_
Label of the end event which ends the duration.
std::string getLabel() const
Get a composite label of the member values with text message types.
uint8_t query_type_
Query message type (e.g. DHCPDISCOVER, DHCP6_SOLICIT).
Timestamp getCurrentIntervalStart() const
Get the current interval start time.
bool addSample(const Duration &sample)
Add a sample to the duration's current interval.
void expireCurrentInterval()
Concludes the current interval.
MonitoredDuration(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id, const Duration &interval_duration)
Constructor.
void clear()
Deletes the current and previous intervals.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
@ DHCP_NOTYPE
Message Type option missing.
boost::posix_time::time_duration Duration
boost::posix_time::ptime Timestamp
std::ostream & operator<<(std::ostream &os, const DurationKey &key)
Defines the logger used by the top-level component of kea-lfc.