Kea 2.7.1
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
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
31public:
32 DuplicateDurationKey(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) {}
34};
35
37struct DurationKeyTag { };
38
41
51typedef boost::multi_index_container<
52 // It holds pointers to Lease6 objects.
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<
61 // The query packet type
62 boost::multi_index::const_mem_fun<DurationKey, uint8_t,
64 // The response packet type
65 boost::multi_index::const_mem_fun<DurationKey, uint8_t,
67 // The start event label
68 boost::multi_index::const_mem_fun<DurationKey, std::string,
70 // The end event label
71 boost::multi_index::const_mem_fun<DurationKey, std::string,
73 // The subnet id
74 boost::multi_index::const_mem_fun<DurationKey, dhcp::SubnetID,
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,
85 >
86 >
88
90typedef std::vector<MonitoredDurationPtr> MonitoredDurationCollection;
91
93typedef boost::shared_ptr<MonitoredDurationCollection> MonitoredDurationCollectionPtr;
94
103public:
108 explicit MonitoredDurationStore(uint16_t family, const Duration& interval_duration);
109
112
131
140
147
155 void updateDuration(MonitoredDurationPtr& duration);
156
163
168
174
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
212
214 const boost::scoped_ptr<std::mutex> mutex_;
215};
216
217typedef boost::shared_ptr<MonitoredDurationStore> MonitoredDurationStorePtr;
218
219} // end of namespace perfmon
220} // end of namespace isc
221
222#endif
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.
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:117
Exception thrown when an attempt was made to add a duplicate duration to the store.
DuplicateDurationKey(const char *file, size_t line, const char *what)
Houses the composite key that uniquely identifies a duration:
std::string getStartEventLabel() const
Get the start event label.
std::string getStopEventLabel() const
Get the end event label.
uint8_t getResponseType() const
Get the response packet type.
dhcp::SubnetID getSubnetId() const
Get the subnet id.
uint8_t getQueryType() const
Get the query packet type.
Maintains an in-memory store of durations.
MonitoredDurationCollectionPtr getOverdueReports(const Timestamp &since=dhcp::PktEvent::now())
Fetches all durations that are overdue to report.
void deleteDuration(DurationKeyPtr key)
Removes the duration from the store.
~MonitoredDurationStore()=default
Destructor.
MonitoredDurationPtr addDuration(DurationKeyPtr key)
Creates a new duration and adds it to the store.
MonitoredDurationStore(uint16_t family, const Duration &interval_duration)
Constructor.
MonitoredDurationCollectionPtr getAll()
Fetches all of the durations (in order by target)
void clear()
Removes all durations from the store.
MonitoredDurationPtr getReportsNext()
Fetches the duration which is due to report next.
MonitoredDurationPtr getDuration(DurationKeyPtr key)
Fetches a duration from the store for a given key.
MonitoredDurationPtr addDurationSample(DurationKeyPtr key, const Duration &sample)
Adds a sample to a duration in-place.
void updateDuration(MonitoredDurationPtr &duration)
Updates a duration in the store.
Timestamp getCurrentIntervalStart() const
Get the current interval start time.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::posix_time::time_duration Duration
boost::shared_ptr< MonitoredDurationCollection > MonitoredDurationCollectionPtr
Type for a pointer to a collection of MonitoredDurationPtrs.
boost::shared_ptr< DurationKey > DurationKeyPtr
Defines a pointer to a DurationKey instance.
boost::shared_ptr< MonitoredDurationStore > MonitoredDurationStorePtr
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.
boost::posix_time::ptime Timestamp
boost::shared_ptr< MonitoredDuration > MonitoredDurationPtr
std::vector< MonitoredDurationPtr > MonitoredDurationCollection
Type for a collection of MonitoredDurationPtrs.
Defines the logger used by the top-level component of kea-lfc.
Tag for index by primary key (DurationKey).
Tag for index by interval start time.