Kea: monitored_duration_store.h Source File

| Kea 3.0.0

monitored_duration_store.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_STORE_H
8#define MONITORED_DURATION_STORE_H
9
10#include <exceptions/exceptions.h>
11#include <monitored_duration.h>
12
13#include <boost/multi_index/indexed_by.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/multi_index/mem_fun.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index_container.hpp>
18#include <boost/multi_index/composite_key.hpp>
19#include <boost/multi_index/sequenced_index.hpp>
20#include <boost/multi_index/identity.hpp>
21#include <boost/scoped_ptr.hpp>
22
23#include <string>
24
25namespace isc {
26namespace perfmon {
27
30 class DuplicateDurationKey : public Exception {
31public:
32 DuplicateDurationKey(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) {}
34};
35
37 struct DurationKeyTag { };
38
40 struct IntervalStartTag { };
41
51typedef boost::multi_index_container<
52 // It holds pointers to Lease6 objects.
53 MonitoredDurationPtr,
54 boost::multi_index::indexed_by<
55 // Specification of the first index starts here.
56 // This index sorts using composite key
57 boost::multi_index::ordered_unique<
58 boost::multi_index::tag<DurationKeyTag>,
59 boost::multi_index::composite_key<
60 MonitoredDuration,
61 // The query packet type
62 boost::multi_index::const_mem_fun<DurationKey, uint8_t,
63 &DurationKey::getQueryType>,
64 // The response packet type
65 boost::multi_index::const_mem_fun<DurationKey, uint8_t,
66 &DurationKey::getResponseType>,
67 // The start event label
68 boost::multi_index::const_mem_fun<DurationKey, std::string,
69 &DurationKey::getStartEventLabel>,
70 // The end event label
71 boost::multi_index::const_mem_fun<DurationKey, std::string,
72 &DurationKey::getStopEventLabel>,
73 // The subnet id
74 boost::multi_index::const_mem_fun<DurationKey, dhcp::SubnetID,
75 &DurationKey::getSubnetId>
76 >
77 >,
78
79 // Specification of the second index starts here.
80 // This index sorts durations by current interval start time.
81 boost::multi_index::ordered_non_unique<
82 boost::multi_index::tag<IntervalStartTag>,
83 boost::multi_index::const_mem_fun<MonitoredDuration, Timestamp,
84 &MonitoredDuration::getCurrentIntervalStart>
85 >
86 >
87> MonitoredDurationContainer;
88
90 typedef std::vector<MonitoredDurationPtr> MonitoredDurationCollection;
91
93 typedef boost::shared_ptr<MonitoredDurationCollection> MonitoredDurationCollectionPtr;
94
102 class MonitoredDurationStore {
103public:
108 explicit MonitoredDurationStore(uint16_t family, const Duration& interval_duration);
109
111 ~MonitoredDurationStore() = default;
112
130 MonitoredDurationPtr addDurationSample(DurationKeyPtr key, const Duration& sample);
131
139 MonitoredDurationPtr addDuration(DurationKeyPtr key);
140
146 MonitoredDurationPtr getDuration(DurationKeyPtr key);
147
155 void updateDuration(MonitoredDurationPtr& duration);
156
162 void deleteDuration(DurationKeyPtr key);
163
167 MonitoredDurationCollectionPtr getAll();
168
173 MonitoredDurationPtr getReportsNext();
174
181 MonitoredDurationCollectionPtr getOverdueReports(const Timestamp& since = dhcp::PktEvent::now());
182
184 void clear();
185
189 uint16_t getFamily() {
190 return (family_);
191 }
192
193private:
201 void validateKey(const std::string& label, DurationKeyPtr key) const;
202
204 uint16_t family_;
205
208 Duration interval_duration_;
209
211 MonitoredDurationContainer durations_;
212
214 const boost::scoped_ptr<std::mutex> mutex_;
215};
216
217 typedef boost::shared_ptr<MonitoredDurationStore> MonitoredDurationStorePtr;
218
219} // end of namespace perfmon
220} // end of namespace isc
221
222#endif
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::dhcp::PktEvent::now
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:117
isc::perfmon::DuplicateDurationKey::DuplicateDurationKey
DuplicateDurationKey(const char *file, size_t line, const char *what)
Definition monitored_duration_store.h:32
isc::perfmon::DurationKey
Houses the composite key that uniquely identifies a duration:
Definition monitored_duration.h:134
isc::perfmon::DurationKey::getStartEventLabel
std::string getStartEventLabel() const
Get the start event label.
Definition monitored_duration.h:175
isc::perfmon::DurationKey::getStopEventLabel
std::string getStopEventLabel() const
Get the end event label.
Definition monitored_duration.h:182
isc::perfmon::DurationKey::getResponseType
uint8_t getResponseType() const
Get the response packet type.
Definition monitored_duration.h:168
isc::perfmon::DurationKey::getSubnetId
dhcp::SubnetID getSubnetId() const
Get the subnet id.
Definition monitored_duration.h:189
isc::perfmon::DurationKey::getQueryType
uint8_t getQueryType() const
Get the query packet type.
Definition monitored_duration.h:161
isc::perfmon::MonitoredDurationStore::getOverdueReports
MonitoredDurationCollectionPtr getOverdueReports(const Timestamp &since=dhcp::PktEvent::now())
Fetches all durations that are overdue to report.
Definition monitored_duration_store.cc:215
isc::perfmon::MonitoredDurationStore::deleteDuration
void deleteDuration(DurationKeyPtr key)
Removes the duration from the store.
Definition monitored_duration_store.cc:166
isc::perfmon::MonitoredDurationStore::~MonitoredDurationStore
~MonitoredDurationStore()=default
Destructor.
isc::perfmon::MonitoredDurationStore::addDuration
MonitoredDurationPtr addDuration(DurationKeyPtr key)
Creates a new duration and adds it to the store.
Definition monitored_duration_store.cc:101
isc::perfmon::MonitoredDurationStore::MonitoredDurationStore
MonitoredDurationStore(uint16_t family, const Duration &interval_duration)
Constructor.
Definition monitored_duration_store.cc:21
isc::perfmon::MonitoredDurationStore::getAll
MonitoredDurationCollectionPtr getAll()
Fetches all of the durations (in order by target)
Definition monitored_duration_store.cc:187
isc::perfmon::MonitoredDurationStore::clear
void clear()
Removes all durations from the store.
Definition monitored_duration_store.cc:199
isc::perfmon::MonitoredDurationStore::getReportsNext
MonitoredDurationPtr getReportsNext()
Fetches the duration which is due to report next.
Definition monitored_duration_store.cc:205
isc::perfmon::MonitoredDurationStore::getFamily
uint16_t getFamily()
Get protocol family.
Definition monitored_duration_store.h:189
isc::perfmon::MonitoredDurationStore::getDuration
MonitoredDurationPtr getDuration(DurationKeyPtr key)
Fetches a duration from the store for a given key.
Definition monitored_duration_store.cc:129
isc::perfmon::MonitoredDurationStore::addDurationSample
MonitoredDurationPtr addDurationSample(DurationKeyPtr key, const Duration &sample)
Adds a sample to a duration in-place.
Definition monitored_duration_store.cc:52
isc::perfmon::MonitoredDurationStore::updateDuration
void updateDuration(MonitoredDurationPtr &duration)
Updates a duration in the store.
Definition monitored_duration_store.cc:145
isc::perfmon::MonitoredDuration
Definition monitored_duration.h:323
isc::perfmon::MonitoredDuration::getCurrentIntervalStart
Timestamp getCurrentIntervalStart() const
Get the current interval start time.
Definition monitored_duration.cc:288
exceptions.h
monitored_duration.h
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::perfmon
Definition alarm.cc:19
isc::perfmon::Duration
boost::posix_time::time_duration Duration
Definition monitored_duration.h:21
isc::perfmon::MonitoredDurationCollectionPtr
boost::shared_ptr< MonitoredDurationCollection > MonitoredDurationCollectionPtr
Type for a pointer to a collection of MonitoredDurationPtrs.
Definition monitored_duration_store.h:93
isc::perfmon::DurationKeyPtr
boost::shared_ptr< DurationKey > DurationKeyPtr
Defines a pointer to a DurationKey instance.
Definition monitored_duration.h:321
isc::perfmon::MonitoredDurationStorePtr
boost::shared_ptr< MonitoredDurationStore > MonitoredDurationStorePtr
Definition monitored_duration_store.h:217
isc::perfmon::MonitoredDurationContainer
boost::multi_index_container< MonitoredDurationPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< DurationKeyTag >, boost::multi_index::composite_key< MonitoredDuration, boost::multi_index::const_mem_fun< DurationKey, uint8_t, &DurationKey::getQueryType >, boost::multi_index::const_mem_fun< DurationKey, uint8_t, &DurationKey::getResponseType >, boost::multi_index::const_mem_fun< DurationKey, std::string, &DurationKey::getStartEventLabel >, boost::multi_index::const_mem_fun< DurationKey, std::string, &DurationKey::getStopEventLabel >, boost::multi_index::const_mem_fun< DurationKey, dhcp::SubnetID, &DurationKey::getSubnetId > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< IntervalStartTag >, boost::multi_index::const_mem_fun< MonitoredDuration, Timestamp, &MonitoredDuration::getCurrentIntervalStart > > > > MonitoredDurationContainer
A multi index container holding pointers to durations.
Definition monitored_duration_store.h:87
isc::perfmon::Timestamp
boost::posix_time::ptime Timestamp
Definition monitored_duration.h:20
isc::perfmon::MonitoredDurationPtr
boost::shared_ptr< MonitoredDuration > MonitoredDurationPtr
Definition monitored_duration.h:503
isc::perfmon::MonitoredDurationCollection
std::vector< MonitoredDurationPtr > MonitoredDurationCollection
Type for a collection of MonitoredDurationPtrs.
Definition monitored_duration_store.h:90
isc::util::file
Definition filesystem.cc:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
isc::perfmon::DurationKeyTag
Tag for index by primary key (DurationKey).
Definition monitored_duration_store.h:37
isc::perfmon::IntervalStartTag
Tag for index by interval start time.
Definition monitored_duration_store.h:40