Kea 2.5.9
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 <dhcp/pkt.h>
11#include <dhcpsrv/subnet_id.h>
12
13#include <boost/date_time/posix_time/posix_time.hpp>
14
15namespace isc {
16namespace perfmon {
17
18typedef boost::posix_time::ptime Timestamp;
19typedef boost::posix_time::time_duration Duration;
20
24public:
28 static const Duration& ZERO_DURATION() {
29 static Duration duration(boost::posix_time::microseconds(0));
30 return (duration);
31 }
32
34 explicit DurationDataInterval(const Timestamp& start_time = dhcp::PktEvent::now());
35
38
47 void addDuration(const Duration& duration);
48
52 const Timestamp& getStartTime() const {
53 return (start_time_);
54 }
55
59 void setStartTime(const Timestamp& start_time) {
60 start_time_ = start_time;
61 }
62
67 uint64_t getOccurrences() const {
68 return (occurrences_);
69 };
70
75 return (min_duration_);
76 }
77
82 return (max_duration_);
83 }
84
89 return (total_duration_);
90 }
91
96
104 bool operator==(const DurationDataInterval& other) const;
105
106private:
108 Timestamp start_time_;
109
111 uint64_t occurrences_;
112
114 Duration min_duration_;
115
117 Duration max_duration_;
118
120 Duration total_duration_;
121};
122
124typedef boost::shared_ptr<DurationDataInterval> DurationDataIntervalPtr;
125
133public:
142 DurationKey(uint16_t family, uint8_t query_type, uint8_t response_type,
143 const std::string& start_event_label, const std::string& stop_event_label,
144 dhcp::SubnetID subnet_id);
145
147 virtual ~DurationKey() = default;
148
152 uint16_t getFamily() {
153 return (family_);
154 }
155
159 uint8_t getQueryType() const {
160 return (query_type_);
161 }
162
166 uint8_t getResponseType() const {
167 return (response_type_);
168 };
169
173 std::string getStartEventLabel() const {
174 return (start_event_label_);
175 }
176
180 std::string getStopEventLabel() const {
181 return (stop_event_label_);
182 }
183
188 return (subnet_id_);
189 }
190
194 void setSubnetId(dhcp::SubnetID subnet_id) {
195 subnet_id_ = subnet_id;
196 }
197
205 static std::string getMessageTypeLabel(uint16_t family, uint16_t msg_type);
206
225 std::string getLabel() const;
226
245 std::string getStatName(const std::string& value_name) const;
246
255 static void validateMessagePair(uint16_t family, uint8_t query_type, uint8_t response_type);
256
262 bool operator==(const DurationKey& other) const;
263
269 bool operator!=(const DurationKey& other) const;
270
276 bool operator<(const DurationKey& other) const;
277
278protected:
280 uint16_t family_;
281
283 uint8_t query_type_;
284
287
290
292 std::string stop_event_label_;
293
296};
297
298std::ostream&
299operator<<(std::ostream& os, const DurationKey& key);
300
302typedef boost::shared_ptr<DurationKey> DurationKeyPtr;
303
305public:
315 MonitoredDuration(uint16_t family, uint8_t query_type, uint8_t response_type,
316 const std::string& start_event_label, const std::string& stop_event_label,
317 dhcp::SubnetID subnet_id, const Duration& interval_duration);
318
323 MonitoredDuration(const DurationKey& key, const Duration& interval_duration);
324
329
331 virtual ~MonitoredDuration() = default;
332
337 return (interval_duration_);
338 }
339
344 return (previous_interval_);
345 }
346
351 return (current_interval_);
352 }
353
359
370 bool addSample(const Duration& sample);
371
378
380 void clear();
381
382private:
384 Duration interval_duration_;
385
387 DurationDataIntervalPtr current_interval_;
388
390 DurationDataIntervalPtr previous_interval_;
391};
392
393typedef boost::shared_ptr<MonitoredDuration> MonitoredDurationPtr;
394
395} // end of namespace isc::perfmon
396} // end of namespace isc
397
398#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 getMaxDuration() const
Get the maximum duration that has occurred in the interval.
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.
Duration getAverageDuration() const
Get the average duration for the interval.
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.
std::string getStopEventLabel() const
Get the end event label.
bool operator==(const DurationKey &other) const
Equality operator.
uint16_t getFamily()
Get protocol family.
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).
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.
void clear()
Deletes the current and previous intervals.
DurationDataIntervalPtr getPreviousInterval() const
Get the previous interval.
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.