29using namespace boost::posix_time;
62 }
catch (std::exception& ex) {
64 "PerfMonMgr::configure failed - " << ex.
what());
75 uint16_t query_type = query->getType();
79 uint16_t response_type;
84 response_type = response->getType();
90 auto events = query->getPktEvents();
91 if (events.size() < 2) {
97 SubnetID subnet_id = (subnet ? subnet->getID() : SUBNET_ID_GLOBAL);
101 .arg(query->getLabel())
102 .arg(query->dumpPktEvents());
109 boost::posix_time::ptime start_time;
110 boost::posix_time::ptime prev_time;
111 std::string prev_event_label;
112 bool first_pass =
true;
113 for (
auto const& event : events) {
115 prev_event_label =
event.label_;
116 prev_time =
event.timestamp_;
117 start_time = prev_time;
120 Duration sample =
event.timestamp_ - prev_time;
122 prev_event_label, event.label_, subnet_id));
126 if (subnet_id != SUBNET_ID_GLOBAL) {
127 key->setSubnetId(SUBNET_ID_GLOBAL);
131 prev_event_label =
event.label_;
132 prev_time =
event.timestamp_;
137 Duration sample = prev_time - start_time;
139 "composite",
"total_response", subnet_id));
142 if (subnet_id != SUBNET_ID_GLOBAL) {
143 key->setSubnetId(SUBNET_ID_GLOBAL);
172 auto previous_interval = duration->getPreviousInterval();
173 if (!previous_interval) {
177 auto mean = previous_interval->getMeanDuration();
180 static_cast<int64_t
>(mean.total_microseconds()));
190 std::string label = alarm->getLabel();
191 switch(alarm->getState()) {
194 .arg(alarm->getLabel())
196 .arg(alarm->getLowWater().total_milliseconds());
201 .arg(alarm->getLabel())
204 .arg(alarm->getHighWater().total_milliseconds());
205 alarm->setLastHighWaterReport();
232 std::string txt =
"(missing parameters)";
253 elem =
cmd_args_->get(
"stats-mgr-reporting");
267 }
catch (
const std::exception& ex) {
289 bool result_set_format =
false;
295 result_set_format = elem->boolValue();
301 auto rows = durations->size();
305 if (!result_set_format) {
315 result->set((result_set_format ?
"durations-result-set" :
"durations"), formatted_durations);
317 std::ostringstream oss;
318 oss <<
"perfmon-get-all-durations: " << rows <<
" found";
324 }
catch (
const std::exception& ex) {
341 for (
auto const& d : *durations) {
343 duration_list->add(element);
346 return (duration_list);
359 result_set->set(
"rows", rows);
361 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 processPktEventStack(isc::dhcp::PktPtr query, isc::dhcp::PktPtr response, const isc::dhcp::SubnetPtr subnet)
Processes the event stack of a query packet.
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.
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.
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or Subnet6 object.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
@ DHCP_NOTYPE
Message Type option missing.
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