From: Thomas Markwalder Date: Wed, 12 Jun 2024 17:57:54 +0000 (-0400) Subject: [#3328] Implemented result set format X-Git-Tag: Kea-2.7.0~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d61188ed8c4fbd5d22026fd2f76e3566d47dea85;p=thirdparty%2Fkea.git [#3328] Implemented result set format /src/hooks/dhcp/perfmon/monitored_duration.* MonitoredDuration::toElement() - add ave-duration-usecs MonitoredDuration::valueRowColumns() MonitoredDuration::toValueRow() - new funcs src/hooks/dhcp/perfmon/perfmon_mgr.cc PerfMonMgr::formatDurationDataAsResultSet() - implemented --- diff --git a/src/hooks/dhcp/perfmon/monitored_duration.cc b/src/hooks/dhcp/perfmon/monitored_duration.cc index 090da75876..b9508711c2 100644 --- a/src/hooks/dhcp/perfmon/monitored_duration.cc +++ b/src/hooks/dhcp/perfmon/monitored_duration.cc @@ -200,11 +200,11 @@ DurationKey::getStatName(const std::string& value_name) const { ElementPtr DurationKey::toElement() const { ElementPtr element = Element::createMap(); - element->set("subnet-id", Element::create(static_cast(subnet_id_))); element->set("query-type", Element::create(getMessageTypeLabel(family_, query_type_))); element->set("response-type", Element::create(getMessageTypeLabel(family_, response_type_))); element->set("start-event", Element::create(start_event_label_)); element->set("stop-event", Element::create(stop_event_label_)); + element->set("subnet-id", Element::create(static_cast(subnet_id_))); return (element); } @@ -333,16 +333,78 @@ MonitoredDuration::toElement() const { element->set("min-duration-usecs", Element::create(previous_interval_->getMinDuration().total_microseconds())); element->set("max-duration-usecs", Element::create(previous_interval_->getMaxDuration().total_microseconds())); element->set("total-duration-usecs", Element::create(previous_interval_->getTotalDuration().total_microseconds())); + element->set("ave-duration-usecs", Element::create(previous_interval_->getAverageDuration().total_microseconds())); } else { element->set("start-time", Element::create("")); element->set("occurrences", Element::create(0)); element->set("min-duration-usecs", Element::create(0)); element->set("max-duration-usecs", Element::create(0)); element->set("total-duration-usecs", Element::create(0)); + element->set("ave-duration-usecs", Element::create(0)); } return (element); } +ConstElementPtr +MonitoredDuration::valueRowColumns() { + static std::list column_labels{ + "query-type", + "response-type", + "start-event", + "end-event", + "subnet-id", + "interval-start", + "occurences", + "min-duration-usecs", + "max-duration-usecs", + "total-duration-usecs" + "ave-duration-usecs" + }; + + static ElementPtr cols; + if (!cols) { + // Create the list of column names and add it to the result set. + cols = Element::createList(); + for (auto const& label : column_labels) { + cols->add(Element::create(label)); + } + } + + return(cols); +} + +ElementPtr +MonitoredDuration::toValueRow() const { + // Create the value row. + ElementPtr row = Element::createList(); + + // Add key values. + row->add(Element::create(getMessageTypeLabel(family_, query_type_))); + row->add(Element::create(getMessageTypeLabel(family_, response_type_))); + row->add(Element::create(start_event_label_)); + row->add(Element::create(stop_event_label_)); + row->add(Element::create(static_cast(subnet_id_))); + + // Add interval data values. + if (previous_interval_) { + row->add(Element::create(ptimeToText(previous_interval_->getStartTime()))); + row->add(Element::create(static_cast(previous_interval_->getOccurrences()))); + row->add(Element::create(previous_interval_->getMinDuration().total_microseconds())); + row->add(Element::create(previous_interval_->getMaxDuration().total_microseconds())); + row->add(Element::create(previous_interval_->getTotalDuration().total_microseconds())); + row->add(Element::create(previous_interval_->getAverageDuration().total_microseconds())); + } else { + row->add(Element::create("")); + row->add(Element::create(0)); + row->add(Element::create(0)); + row->add(Element::create(0)); + row->add(Element::create(0)); + row->add(Element::create(0)); + } + + return (row); +} + } // end of namespace perfmon } // end of namespace isc diff --git a/src/hooks/dhcp/perfmon/monitored_duration.h b/src/hooks/dhcp/perfmon/monitored_duration.h index d7e1a5b19a..258301c86b 100644 --- a/src/hooks/dhcp/perfmon/monitored_duration.h +++ b/src/hooks/dhcp/perfmon/monitored_duration.h @@ -414,7 +414,8 @@ public: /// "occurrences": 105, /// "min-duration-usecs": 5300, /// "max-duration-usecs": 9000, - /// "total-duration-usecs": 786500 + /// "total-duration-usecs": 786500, + /// "ave-duration-usecs": 7490 /// } /// @endcode /// @@ -433,13 +434,60 @@ public: /// "occurrences": 0, /// "min-duration-usecs": 0, /// "max-duration-usecs": 0, - /// "total-duration-usecs": 0 + /// "total-duration-usecs": 0, + /// "ave-duration-usecs": 0 /// } /// @endcode /// /// @return Element::map containing the duration key values. virtual data::ElementPtr toElement() const; + /// @brief Fetches a an Element::list of value row column names + /// + /// The list element includes the name of each column in a value row, in + /// the order the values are stored in a value row. + /// + /// The values in the list in order are: + /// + /// -# "query-type" + /// -# "response-type" + /// -# "start-event" + /// -# "stop-event" + /// -# "subnet-id" + /// -# "start-time" + /// -# "occurrences" + /// -# "min-duration-usecs" + /// -# "max-duration-usecs" + /// -# "total-duration-usecs" + /// -# "ave-duration-usecs" + /// + /// @return Element::map containing the duration key values. + static data::ConstElementPtr valueRowColumns(); + + /// @brief Renders the the duration as an Element::list of values. + /// + /// The list element includes a value for each member of DurationKey + /// and the previous interval. If there is no previous interval value of + /// of "" will be added for start-time and values of 0 for the + /// remaining data values. + /// + /// The values in the list will be in the following order and type: + /// + /// -# query-type Element::string + /// -# response-type Element::string + /// -# start-event Element::string + /// -# stop-event Element::string + /// -# subnet-id Element::int + /// -# start-time Element::string ex: "2024-01-18 10:11:19.498739" or "", + /// -# occurrences Element::int + /// -# min-duration-usecs Element::int + /// -# max-duration-usecs Element::int + /// -# total-duration-usecs Element::int + /// -# ave-duration-usecs Element::int + /// + /// @return Element::map containing the duration key values. + data::ElementPtr toValueRow() const; + private: /// @brief Length of the time of a single data interval. Duration interval_duration_; diff --git a/src/hooks/dhcp/perfmon/perfmon_mgr.cc b/src/hooks/dhcp/perfmon/perfmon_mgr.cc index d7e8dda054..352fb4c760 100644 --- a/src/hooks/dhcp/perfmon/perfmon_mgr.cc +++ b/src/hooks/dhcp/perfmon/perfmon_mgr.cc @@ -343,39 +343,25 @@ PerfMonMgr::formatDurationDataAsElements(MonitoredDurationCollectionPtr duration } ElementPtr -PerfMonMgr::formatDurationDataAsResultSet(MonitoredDurationCollectionPtr /*durations */) const{ - isc_throw (NotImplemented, "Not Implemented - " << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__); -#if 0 +PerfMonMgr::formatDurationDataAsResultSet(MonitoredDurationCollectionPtr durations) const{ // Create the result-set map and add it to the wrapper. ElementPtr result_set = Element::createMap(); - result_wrapper->set("result-set", result_set); // Create the list of column names and add it to the result set. - ElementPtr columns = Element::createList(); - for (auto const& label : column_labels) { - columns->add(Element::create(label)); - } - result_set->set("columns", columns); + result_set->set("columns", MonitoredDuration::valueRowColumns()); - // Create the empty value_rows list, add it and then return it. - ElementPtr value_rows = Element::createList(); - result_set->set("rows", value_rows); - if (durations.empty()) { - return; - } + // Create the rows list and add it to the result set. + ElementPtr rows = Element::createList(); + result_set->set("rows", rows); - return (value_rows); - for (auto const& d : *durations) { - const auto& reported_interval = d->getPreviousInterval(); - if (reported_interval) { - std::string label = d->getLabel(); + for (auto const& d : *durations) { + // Create the value row. + ElementPtr row = d->toValueRow(); + rows->add(row); + } - } -#endif + return (result_set); } - - - } // end of namespace perfmon } // end of namespace isc