16using namespace boost::posix_time;
24 interval_duration_(interval_duration),
26 mutex_(new std::mutex) {
27 if (family != AF_INET && family_ != AF_INET6) {
29 << family_ <<
", must be AF_INET or AF_INET6");
34 << interval_duration_ <<
", must be greater than zero");
39MonitoredDurationStore::validateKey(
const std::string& label,
DurationKeyPtr key)
const {
44 if (key->getFamily() != family_) {
46 <<
" - family mismatch, key is " << (family_ == AF_INET ?
47 "v6, store is v4" :
"v4, store is v6"));
53 validateKey(
"addDurationSample", key);
58 auto duration_iter = index.find(boost::make_tuple(key->getQueryType(),
59 key->getResponseType(),
60 key->getStartEventLabel(),
61 key->getStopEventLabel(),
64 if (duration_iter != index.end()) {
65 bool should_report =
false;
68 bool modified = index.modify(duration_iter,
70 should_report = mond->addSample(sample);
76 "MonitoredDurationStore::addDurationSample - modify failed for: "
87 static_cast<void>(mond->addSample(sample));
88 auto ret = durations_.insert(mond);
89 if (ret.second ==
false) {
92 "MonitoredDurationStore::addDurationSample: duration already exists for: "
102 validateKey(
"addDuration", key);
108 }
catch (
const std::exception& ex) {
109 isc_throw(
BadValue,
"MonitoredDurationStore::addDuration failed: " << ex.what());
115 auto ret = durations_.insert(mond);
116 if (ret.second ==
false) {
118 "MonitoredDurationStore::addDuration: duration already exists for: "
119 << mond->getLabel());
130 validateKey(
"getDuration", key);
134 auto duration_iter = index.find(boost::make_tuple(key->getQueryType(),
135 key->getResponseType(),
136 key->getStartEventLabel(),
137 key->getStopEventLabel(),
138 key->getSubnetId()));
146 validateKey(
"updateDuration", duration);
150 auto duration_iter = index.find(boost::make_tuple(duration->getQueryType(),
151 duration->getResponseType(),
152 duration->getStartEventLabel(),
153 duration->getStopEventLabel(),
154 duration->getSubnetId()));
156 if (duration_iter == index.end()) {
158 << duration->getLabel());
167 validateKey(
"deleteDuration", key);
171 auto duration_iter = index.find(boost::make_tuple(key->getQueryType(),
172 key->getResponseType(),
173 key->getStartEventLabel(),
174 key->getStopEventLabel(),
175 key->getSubnetId()));
177 if (duration_iter == index.end()) {
183 durations_.erase(duration_iter);
191 for (
auto const& mond : index) {
223 auto lower_limit = index.lower_bound(lower_limit_time);
224 auto upper_limit = index.upper_bound(since - interval_duration_);
227 for (
auto duration_iter = lower_limit; duration_iter != upper_limit; ++duration_iter) {
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.
A generic exception that is thrown when an unexpected error condition occurs.
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.
Exception thrown when an attempt was made to add a duplicate duration to the store.
static const Duration & ZERO_DURATION()
Get a duration of zero.
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.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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::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.
RAII lock object to protect the code in the same scope with a mutex.