Kea: alarm.h Source File

| Kea 3.2.0-git

alarm.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 _ALARM_H
8#define _ALARM_H
9
10#include <dhcp/pkt.h>
11#include <dhcpsrv/subnet_id.h>
12#include <monitored_duration.h>
13
14#include <boost/date_time/posix_time/posix_time.hpp>
15
16namespace isc {
17namespace perfmon {
18
20 class Alarm : public DurationKey {
21public:
23 enum State {
24 CLEAR, // Enabled and not currently triggered
25 TRIGGERED, // High water has been exceeded
26 DISABLED // Disabled
27 };
28
40 Alarm(uint16_t family, uint8_t query_type, uint8_t response_type,
41 const std::string& start_event_label, const std::string& stop_event_label,
42 dhcp::SubnetID subnet_id,
43 const Duration& low_water, const Duration& high_water, bool enabled = true);
44
51 Alarm(const DurationKey& key, const Duration& low_water, const Duration& high_water, bool enabled = true);
52
54 virtual ~Alarm() = default;
55
59 Duration getLowWater() const {
60 return (low_water_);
61 }
62
68 void setLowWater(const Duration& low_water);
69
73 Duration getHighWater() const {
74 return (high_water_);
75 }
76
82 void setHighWater(const Duration& high_water);
83
85 State getState() {
86 return (state_);
87 }
88
96 void setState(State state);
97
101 Timestamp getStosTime() {
102 return (stos_time_);
103 }
104
108 Timestamp getLastHighWaterReport() {
109 return (last_high_water_report_);
110 }
111
118 void setLastHighWaterReport(const Timestamp& timestamp = dhcp::PktEvent::now()) {
119 last_high_water_report_ = timestamp;
120 }
121
123 void clear();
124
126 void disable();
127
148 bool checkSample(const Duration& sample, const Duration& report_interval);
149
150private:
152 Duration low_water_;
153
155 Duration high_water_;
156
158 State state_;
159
161 Timestamp stos_time_;
162
164 Timestamp last_high_water_report_;
165};
166
168 typedef boost::shared_ptr<Alarm> AlarmPtr;
169
170} // end of namespace isc::perfmon
171} // end of namespace isc
172
173#endif
isc::dhcp::PktEvent::now
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:117
isc::perfmon::Alarm::setHighWater
void setHighWater(const Duration &high_water)
Set the high water threshold.
Definition alarm.cc:69
isc::perfmon::Alarm::getLastHighWaterReport
Timestamp getLastHighWaterReport()
Get the timestamp of the last high water report.
Definition alarm.h:108
isc::perfmon::Alarm::clear
void clear()
Sets the alarm back to the CLEAR state.
Definition alarm.cc:86
isc::perfmon::Alarm::setState
void setState(State state)
Sets the alarm state.
Definition alarm.cc:79
isc::perfmon::Alarm::~Alarm
virtual ~Alarm()=default
Destructor.
isc::perfmon::Alarm::setLastHighWaterReport
void setLastHighWaterReport(const Timestamp &timestamp=dhcp::PktEvent::now())
Set the timestamp of the last high water report.
Definition alarm.h:118
isc::perfmon::Alarm::checkSample
bool checkSample(const Duration &sample, const Duration &report_interval)
Checks a duration against the high and low water thresholds and calls the appropriate event handler.
Definition alarm.cc:96
isc::perfmon::Alarm::disable
void disable()
Disables the alarm by setting the state to DISABLED.
Definition alarm.cc:91
isc::perfmon::Alarm::getHighWater
Duration getHighWater() const
Get the high water threshold.
Definition alarm.h:73
isc::perfmon::Alarm::setLowWater
void setLowWater(const Duration &low_water)
Set the low water threshold.
Definition alarm.cc:59
isc::perfmon::Alarm::Alarm
Alarm(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 &low_water, const Duration &high_water, bool enabled=true)
Constructor.
Definition alarm.cc:21
isc::perfmon::Alarm::getState
State getState()
Get the alarm's state.
Definition alarm.h:85
isc::perfmon::Alarm::State
State
Defines Alarm states.
Definition alarm.h:23
isc::perfmon::Alarm::DISABLED
@ DISABLED
Definition alarm.h:26
isc::perfmon::Alarm::CLEAR
@ CLEAR
Definition alarm.h:24
isc::perfmon::Alarm::TRIGGERED
@ TRIGGERED
Definition alarm.h:25
isc::perfmon::Alarm::getStosTime
Timestamp getStosTime()
Get the time the current state began.
Definition alarm.h:101
isc::perfmon::Alarm::getLowWater
Duration getLowWater() const
Get the low water threshold.
Definition alarm.h:59
isc::perfmon::DurationKey
Houses the composite key that uniquely identifies a duration:
Definition monitored_duration.h:134
isc::perfmon::DurationKey::DurationKey
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.
Definition monitored_duration.cc:66
isc::util::State
Defines a State within the State Model.
Definition state_model.h:61
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::Timestamp
boost::posix_time::ptime Timestamp
Definition monitored_duration.h:20
isc::perfmon::AlarmPtr
boost::shared_ptr< Alarm > AlarmPtr
Defines a pointer to an Alarm instance.
Definition alarm.h:168
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
pkt.h
subnet_id.h