29using namespace boost::posix_time;
62 }
catch (std::exception& ex) {
64 "PerfMonMgr::configure failed - " << ex.
what());
76 uint16_t query_type = query->getType();
80 uint16_t response_type;
85 response_type = response->getType();
91 auto events = query->getPktEvents();
92 if (events.size() < 2) {
98 SubnetID subnet_id = (subnet ? subnet->getID() : SUBNET_ID_GLOBAL);
102 .arg(query->getLabel())
103 .arg(query->dumpPktEvents());
110 boost::posix_time::ptime start_time;
111 boost::posix_time::ptime prev_time;
112 std::string prev_event_label;
113 bool first_pass =
true;
114 for (
auto const& event : events) {
116 prev_event_label =
event.label_;
117 prev_time =
event.timestamp_;
118 start_time = prev_time;
121 Duration sample =
event.timestamp_ - prev_time;
123 prev_event_label, event.label_, subnet_id));
127 if (subnet_id != SUBNET_ID_GLOBAL) {
128 key->setSubnetId(SUBNET_ID_GLOBAL);
132 prev_event_label =
event.label_;
133 prev_time =
event.timestamp_;
138 Duration sample = prev_time - start_time;
140 "composite",
"total_response", subnet_id));
143 if (subnet_id != SUBNET_ID_GLOBAL) {
144 key->setSubnetId(SUBNET_ID_GLOBAL);
173 auto previous_interval = duration->getPreviousInterval();
174 if (!previous_interval) {
178 auto mean = previous_interval->getMeanDuration();
181 static_cast<int64_t
>(mean.total_microseconds()));
191 std::string label = alarm->getLabel();
192 switch(alarm->getState()) {
195 .arg(alarm->getLabel())
197 .arg(alarm->getLowWater().total_milliseconds());
202 .arg(alarm->getLabel())
205 .arg(alarm->getHighWater().total_milliseconds());
206 alarm->setLastHighWaterReport();
233 std::string txt =
"(missing parameters)";
254 elem =
cmd_args_->get(
"stats-mgr-reporting");
268 }
catch (
const std::exception& ex) {
290 bool result_set_format =
false;
296 result_set_format = elem->boolValue();
302 auto rows = durations->size();
306 if (!result_set_format) {
316 result->set((result_set_format ?
"durations-result-set" :
"durations"), formatted_durations);
318 std::ostringstream oss;
319 oss <<
"perfmon-get-all-durations: " << rows <<
" found";
325 }
catch (
const std::exception& ex) {
342 for (
auto const& d : *durations) {
344 duration_list->add(element);
347 return (duration_list);
360 result_set->set(
"rows", rows);
362 for (
auto const& d : *durations) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown when an unexpected error condition occurs.
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
To be removed. Please use ConfigError instead.
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Per-packet callout handle.
Houses the composite key that uniquely identifies a duration:
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.
Maintains an in-memory store of durations.
static data::ConstElementPtr valueRowColumns()
Fetches a an Element::list of value row column names.
Houses the PerfMon configuration parameters for a single scope (e.g.
uint32_t interval_width_secs_
Number of seconds a duration accumulates samples until reporting.
uint32_t alarm_report_secs_
Number of seconds between reports of a raised alarm.
void setEnableMonitoring(bool value)
Sets the value of enable-monitoring.
uint16_t family_
Protocol family AF_INET or AF_INET6.
bool getStatsMgrReporting() const
Fetches the value of stats-mgr-reporting.
void parse(data::ConstElementPtr config)
Extracts member values from an Element::map.
AlarmStorePtr alarm_store_
Stores the configured alarms.
std::atomic< bool > stats_mgr_reporting_
If true durations report to StatsMgr at the end of each interval.
uint32_t getIntervalWidthSecs() const
Fetches the value of interval-width-secs.
std::atomic< bool > enable_monitoring_
If true, performance data is processed/reported.
void reportTimerExpired()
Handler invoked when the report timer expires.
Duration interval_duration_
Length of time a MonitoredDuration accumulates samples until reporting.
int perfmonGetAllDurationsHandler(hooks::CalloutHandle &handle)
perfmon-get-all-durations handler
void setNextReportExpiration()
Updates the report timer.
void addDurationSample(DurationKeyPtr key, const Duration &sample)
Adds a duration sample to a MonitoredDuration.
data::ElementPtr formatDurationDataAsElements(MonitoredDurationCollectionPtr durations) const
Renders a list of MonitoredDurations as a map of individual Elements.
void processPktEventStack(isc::dhcp::PktPtr query, isc::dhcp::PktPtr response, const isc::dhcp::ConstSubnetPtr subnet)
Processes the event stack of a query packet.
int perfmonControlHandler(hooks::CalloutHandle &handle)
perfmon-control command handler
PerfMonMgr(uint16_t family)
Constructor.
Duration reportToStatsMgr(MonitoredDurationPtr duration)
Emits an entry to StatsMgr for a given duration.
void configure(const isc::data::ConstElementPtr ¶ms)
Parses the hook library 'parameters' element.
MonitoredDurationStorePtr duration_store_
In-memory store of MonitoredDurations.
data::ElementPtr formatDurationDataAsResultSet(MonitoredDurationCollectionPtr durations) const
Renders a list of MonitoredDurations as a result set.
Duration alarm_report_interval_
Length of time between raised Alarm reports.
virtual void init()
Sets convenience values and (re)creates the duration store.
void reportAlarm(AlarmPtr alarm, const Duration &mean)
Emits a report for a given alarm.
static StatsMgr & instance()
Statistics Manager accessor method.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
@ DHCP_NOTYPE
Message Type option missing.
boost::shared_ptr< const Subnet > ConstSubnetPtr
A generic pointer to either const Subnet4 or const Subnet6 object.
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
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< MonitoredDuration > MonitoredDurationPtr
boost::shared_ptr< Alarm > AlarmPtr
Defines a pointer to an Alarm instance.
isc::log::Logger perfmon_logger("perfmon-hooks")
std::string ptimeToText(boost::posix_time::ptime t, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts ptime structure to text.
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID PERFMON_ALARM_CLEARED
const isc::log::MessageID PERFMON_CMDS_GET_ALL_DURATIONS_OK
const isc::log::MessageID PERFMON_CMDS_CONTROL_OK
const isc::log::MessageID PERFMON_ALARM_TRIGGERED
const isc::log::MessageID PERFMON_DHCP4_PKT_EVENTS
const isc::log::MessageID PERFMON_CMDS_GET_ALL_DURATIONS_ERROR
const isc::log::MessageID PERFMON_DHCP6_PKT_EVENTS
const isc::log::MessageID PERFMON_CMDS_CONTROL_ERROR