Kea 2.7.6
monitored_duration.h
Go to the documentation of this file.
1// Copyright (C) 2024 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 _MONITORED_DURATION_H
8#define _MONITORED_DURATION_H
9
10#include <cc/data.h>
11#include <cc/cfg_to_element.h>
12#include <dhcp/pkt.h>
13#include <dhcpsrv/subnet_id.h>
14
15#include <boost/date_time/posix_time/posix_time.hpp>
16
17namespace isc {
18namespace perfmon {
19
20typedef boost::posix_time::ptime Timestamp;
21typedef boost::posix_time::time_duration Duration;
22
26public:
30 static const Duration& ZERO_DURATION() {
31 static Duration duration(boost::posix_time::microseconds(0));
32 return (duration);
33 }
34
36 explicit DurationDataInterval(const Timestamp& start_time = dhcp::PktEvent::now());
37
40
49 void addDuration(const Duration& duration);
50
54 const Timestamp& getStartTime() const {
55 return (start_time_);
56 }
57
61 void setStartTime(const Timestamp& start_time) {
62 start_time_ = start_time;
63 }
64
69 uint64_t getOccurrences() const {
70 return (occurrences_);
71 };
72
77 return (min_duration_);
78 }
79
84 return (max_duration_);
85 }
86
91 return (total_duration_);
92 }
93
98
106 bool operator==(const DurationDataInterval& other) const;
107
108private:
110 Timestamp start_time_;
111
113 uint64_t occurrences_;
114
116 Duration min_duration_;
117
119 Duration max_duration_;
120
122 Duration total_duration_;
123};
124
126typedef boost::shared_ptr<DurationDataInterval> DurationDataIntervalPtr;
127
135public:
144 DurationKey(uint16_t family, uint8_t query_type, uint8_t response_type,
145 const std::string& start_event_label, const std::string& stop_event_label,
146 dhcp::SubnetID subnet_id);
147
149 virtual ~DurationKey() = default;
150
154 uint16_t getFamily() {
155 return (family_);
156 }
157
161 uint8_t getQueryType() const {
162 return (query_type_);
163 }
164
168 uint8_t getResponseType() const {
169 return (response_type_);
170 };
171
175 std::string getStartEventLabel() const {
176 return (start_event_label_);
177 }
178
182 std::string getStopEventLabel() const {
183 return (stop_event_label_);
184 }
185
190 return (subnet_id_);
191 }
192
196 void setSubnetId(dhcp::SubnetID subnet_id) {
197 subnet_id_ = subnet_id;
198 }
199
207 static std::string getMessageTypeLabel(uint16_t family, uint16_t msg_type);
208
227 std::string getLabel() const;
228
247 std::string getStatName(const std::string& value_name) const;
248
264 virtual data::ElementPtr toElement() const;
265
274 static void validateMessagePair(uint16_t family, uint8_t query_type, uint8_t response_type);
275
281 bool operator==(const DurationKey& other) const;
282
288 bool operator!=(const DurationKey& other) const;
289
295 bool operator<(const DurationKey& other) const;
296
297protected:
299 uint16_t family_;
300
302 uint8_t query_type_;
303
306
309
311 std::string stop_event_label_;
312
315};
316
317std::ostream&
318operator<<(std::ostream& os, const DurationKey& key);
319
321typedef boost::shared_ptr<DurationKey> DurationKeyPtr;
322
324public:
334 MonitoredDuration(uint16_t family, uint8_t query_type, uint8_t response_type,
335 const std::string& start_event_label, const std::string& stop_event_label,
336 dhcp::SubnetID subnet_id, const Duration& interval_duration);
337
342 MonitoredDuration(const DurationKey& key, const Duration& interval_duration);
343
348
350 virtual ~MonitoredDuration() = default;
351
356 return (interval_duration_);
357 }
358
363 return (previous_interval_);
364 }
365
370 return (current_interval_);
371 }
372
378
389 bool addSample(const Duration& sample);
390
397
399 void clear();
400
444 virtual data::ElementPtr toElement() const;
445
467
491
492private:
494 Duration interval_duration_;
495
497 DurationDataIntervalPtr current_interval_;
498
500 DurationDataIntervalPtr previous_interval_;
501};
502
503typedef boost::shared_ptr<MonitoredDuration> MonitoredDurationPtr;
504
505} // end of namespace isc::perfmon
506} // end of namespace isc
507
508#endif
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:117
Embodies a span of time (i.e.
void setStartTime(const Timestamp &start_time)
Set the interval start time.
Duration getMeanDuration() const
Get the mean duration for the interval.
Duration getMaxDuration() const
Get the maximum duration that has occurred in the interval.
DurationDataInterval(const Timestamp &start_time=dhcp::PktEvent::now())
Constructor.
Duration getTotalDuration() const
Get the total duration in the interval.
static const Duration & ZERO_DURATION()
Get a duration of zero.
bool operator==(const DurationDataInterval &other) const
Equality operator.
const Timestamp & getStartTime() const
Get the start time of the interval.
~DurationDataInterval()=default
Destructor.
uint64_t getOccurrences() const
Get the number of occurrences that have contributed to the interval.
Duration getMinDuration() const
Get the minimum duration that has occurred in 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 getStartEventLabel() const
Get the start event label.
std::string start_event_label_
Label of the start event which begins the duration.
virtual data::ElementPtr toElement() const
Renders the the duration key as an Element.
std::string getStopEventLabel() const
Get the end event label.
bool operator==(const DurationKey &other) const
Equality operator.
uint16_t getFamily()
Get protocol family.
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.
uint8_t getResponseType() const
Get the response packet type.
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.
dhcp::SubnetID getSubnetId() const
Get the subnet id.
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.
uint8_t getQueryType() const
Get the query packet type.
void setSubnetId(dhcp::SubnetID subnet_id)
Set the subnet id.
virtual ~DurationKey()=default
Destructor.
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).
virtual data::ElementPtr toElement() const
Renders the the duration as an Element.
data::ElementPtr toValueRow() const
Renders the the duration as an Element::list of values.
Timestamp getCurrentIntervalStart() const
Get the current interval start time.
virtual ~MonitoredDuration()=default
Destructor.
bool addSample(const Duration &sample)
Add a sample to the duration's current interval.
Duration getIntervalDuration() const
Get the interval duration.
DurationDataIntervalPtr getCurrentInterval() const
Get the 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.
DurationDataIntervalPtr getPreviousInterval() const
Get the previous interval.
static data::ConstElementPtr valueRowColumns()
Fetches a an Element::list of value row column names.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::posix_time::time_duration Duration
boost::shared_ptr< DurationKey > DurationKeyPtr
Defines a pointer to a DurationKey instance.
boost::shared_ptr< DurationDataInterval > DurationDataIntervalPtr
Defines a pointer to a DurationDataInterval instance.
boost::posix_time::ptime Timestamp
std::ostream & operator<<(std::ostream &os, const DurationKey &key)
boost::shared_ptr< MonitoredDuration > MonitoredDurationPtr
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.