24#include <boost/date_time/posix_time/posix_time.hpp>
72 os <<
"[all subnets]";
187 const std::vector<std::string>& column_labels);
197 int64_t assigned, int64_t declined);
208 int64_t assigned, int64_t declined, int64_t assigned_pds);
237 }
catch (
const std::exception& ex) {
248 .arg(params.toText())
250 std::stringstream os;
251 os <<
"stat-lease4-get" << params.toText() <<
": " << rows <<
" rows found";
257 .arg(params.toText())
259 std::stringstream os;
260 os <<
"stat-lease4-get" << params.toText() <<
": no matching data, " << ex.what();
262 }
catch (
const std::exception& ex) {
264 .arg(params.toText())
284 }
catch (
const std::exception& ex) {
295 .arg(params.toText())
297 std::stringstream os;
298 os <<
"stat-lease6-get" << params.toText() <<
": " << rows <<
" rows found";
304 .arg(params.toText())
306 std::stringstream os;
307 os <<
"stat-lease6-get" << params.toText() <<
": no matching data, " << ex.what();
309 }
catch (
const std::exception& ex) {
311 .arg(params.toText())
326 params.first_subnet_id_ = 0;
327 params.last_subnet_id_ = 0;
338 if (cmd_args->contains(
"subnet-id")) {
345 if (value->intValue() <= 0) {
349 params.first_subnet_id_ = value->intValue();
353 if (cmd_args->contains(
"subnet-range")) {
368 if (value->intValue() <= 0) {
372 params.first_subnet_id_ = value->intValue();
374 value = range->get(
"last-subnet-id");
379 if (value->intValue() <= 0) {
383 params.last_subnet_id_ = value->intValue();
385 if (params.last_subnet_id_ < params.first_subnet_id_) {
412 auto lower = idx.begin();
413 auto upper = idx.end();
414 switch (params.select_mode_) {
416 lower = idx.find(params.first_subnet_id_);
418 if (lower == idx.end()) {
420 << params.first_subnet_id_ <<
" does not exist");
423 upper = idx.upper_bound(params.first_subnet_id_);
426 lower = idx.lower_bound(params.first_subnet_id_);
427 upper = idx.upper_bound(params.last_subnet_id_);
434 if (lower == upper) {
436 << params.first_subnet_id_ <<
" through "
437 << params.last_subnet_id_ <<
" includes no known subnets");
442 switch (params.select_mode_) {
448 .startSubnetLeaseStatsQuery4(params.first_subnet_id_);
452 .startSubnetRangeLeaseStatsQuery4(params.first_subnet_id_,
453 params.last_subnet_id_);
461 std::vector<std::string>column_labels = {
"subnet-id",
"total-addresses",
462 "cumulative-assigned-addresses",
463 "assigned-addresses",
464 "declined-addresses" };
469 bool query_eof = !(query->getNextRow(query_row));
472 bool orphaned_stats =
false;
473 for (
auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
474 SubnetID cur_id = (*cur_subnet)->getID();
479 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
480 orphaned_stats =
true;
481 query_eof = !(query->getNextRow(query_row));
488 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
497 int64_t assigned = 0;
498 int64_t declined = 0;
499 bool add_row =
false;
500 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
503 assigned = query_row.state_count_;
506 declined = query_row.state_count_;
510 query_eof = !(query->getNextRow(query_row));
519 if (!(query_eof) || orphaned_stats) {
523 return (value_rows->size());
543 auto lower = idx.begin();
544 auto upper = idx.end();
545 switch (params.select_mode_) {
547 lower = idx.find(params.first_subnet_id_);
549 if (lower == idx.end()) {
551 << params.first_subnet_id_ <<
" does not exist");
554 upper = idx.upper_bound(params.first_subnet_id_);
557 lower = idx.lower_bound(params.first_subnet_id_);
558 upper = idx.upper_bound(params.last_subnet_id_);
565 if (lower == upper) {
567 << params.first_subnet_id_ <<
" through "
568 << params.last_subnet_id_ <<
" includes no known subnets");
573 switch (params.select_mode_) {
579 .startSubnetLeaseStatsQuery6(params.first_subnet_id_);
583 .startSubnetRangeLeaseStatsQuery6(params.first_subnet_id_,
584 params.last_subnet_id_);
592 std::vector<std::string>column_labels = {
"subnet-id",
"total-nas",
593 "cumulative-assigned-nas",
595 "declined-addresses",
"total-pds",
596 "cumulative-assigned-pds",
602 bool query_eof = !(query->getNextRow(query_row));
605 bool orphaned_stats =
false;
606 for (
auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
607 SubnetID cur_id = (*cur_subnet)->getID();
612 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
613 orphaned_stats =
true;
614 query_eof = !(query->getNextRow(query_row));
621 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
630 int64_t assigned = 0;
631 int64_t declined = 0;
632 int64_t assigned_pds = 0;
633 bool add_row =
false;
634 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
638 assigned = query_row.state_count_;
640 assigned_pds = query_row.state_count_;
644 declined = query_row.state_count_;
648 query_eof = !(query->getNextRow(query_row));
652 addValueRow6(value_rows, cur_id, assigned, declined, assigned_pds);
657 if (!(query_eof) || orphaned_stats) {
661 return (value_rows->size());
666 const std::vector<std::string>& column_labels) {
669 result_wrapper->set(
"result-set", result_set);
672 boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
675 result_set->set(
"timestamp", timestamp);
679 for (
auto const& label : column_labels) {
682 result_set->set(
"columns", columns);
686 result_set->set(
"rows", value_rows);
693 int64_t assigned, int64_t declined) {
700 value_rows->add(row);
705 int64_t assigned, int64_t declined, int64_t assigned_pds) {
715 value_rows->add(row);
723 return (stat->getInteger().first);
734 return (stat->getBigInteger().first);
746 return (impl.statLease4GetHandler(handle));
747 }
catch (
const std::exception& ex) {
759 return (impl.statLease6GetHandler(handle));
760 }
catch (
const std::exception& ex) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Base class that command handler implementers may use for common tasks.
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 CfgMgr & instance()
returns a single instance of Configuration Manager
static TrackingLeaseMgr & instance()
Return current lease manager.
SelectMode
Defines the types of selection criteria supported.
Per-packet callout handle.
Wrapper class for stat-leaseX-get command parameters.
SubnetID first_subnet_id_
Specifies the subnet-id for a single subnet, or the first subnet for a subnet range.
LeaseStatsQuery::SelectMode select_mode_
Denotes the query selection mode all, subnet, or subnet range.
std::string toText()
Generate a string version of the contents.
SubnetID last_subnet_id_
Specifies the last subnet for subnet range.
Implements command handling for stat-leaseX-get commands.
uint64_t makeResultSet6(const ElementPtr &result, const Parameters ¶ms)
Executes the lease4 query and constructs the outbound result set This method uses the command paramet...
Parameters getParameters(const ConstElementPtr &cmd_args)
Parses command arguments into stat-leaseX-get parameters.
void addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id, int64_t assigned, int64_t declined, int64_t assigned_pds)
Adds a row of Lease6 stat values to a list of value rows.
int64_t getSubnetStat(const SubnetID &subnet_id, const std::string &name)
Fetches a single integer statistic for a subnet from StatsMgr.
void addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id, int64_t assigned, int64_t declined)
Adds a row of Lease4 stat values to a list of value rows.
uint64_t makeResultSet4(const ElementPtr &result, const Parameters ¶ms)
Executes the lease4 query and constructs the outbound result set.
int statLease6GetHandler(CalloutHandle &handle)
Provides the implementation for stat-lease6-get, isc::stat_cmds::StatCmds::statLease6GetHandler.
ElementPtr createResultSet(const ElementPtr &wrapper, const std::vector< std::string > &column_labels)
Instantiates a new "empty" result-set Element.
int128_t getBigSubnetStat(const SubnetID &subnet_id, const std::string &name)
Fetches a single bigint statistic for a subnet from StatsMgr.
int statLease4GetHandler(CalloutHandle &handle)
Provides the implementation for stat-lease4-get, isc::stat_cmds::StatCmds::statLease4GetHandler.
Exception thrown no subnets fall within the selection criteria This exception is thrown when a valid ...
NotFound(const char *file, size_t line, const char *what)
int statLease4GetHandler(hooks::CalloutHandle &handle)
stat-lease4-get command handler
int statLease6GetHandler(hooks::CalloutHandle &handle)
stat-lease6-get command handler
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
An abstract API for lease database.
#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_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
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet6Collection
A collection of Subnet6 objects.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
isc::log::Logger stat_cmds_logger("stat-cmds-hooks")
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
boost::multiprecision::checked_int128_t int128_t
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 STAT_CMDS_LEASE4_GET_INVALID
const isc::log::MessageID STAT_CMDS_LEASE6_GET_INVALID
const isc::log::MessageID STAT_CMDS_LEASE6_FAILED
const isc::log::MessageID STAT_CMDS_LEASE6_GET
const isc::log::MessageID STAT_CMDS_LEASE4_FAILED
const isc::log::MessageID STAT_CMDS_LEASE6_GET_FAILED
const isc::log::MessageID STAT_CMDS_LEASE4_GET_NO_SUBNETS
const isc::log::MessageID STAT_CMDS_LEASE6_GET_NO_SUBNETS
const isc::log::MessageID STAT_CMDS_LEASE6_ORPHANED_STATS
const isc::log::MessageID STAT_CMDS_LEASE4_GET_FAILED
const isc::log::MessageID STAT_CMDS_LEASE4_ORPHANED_STATS
const isc::log::MessageID STAT_CMDS_LEASE4_GET
Contains a single row of lease statistical data.
static const uint32_t STATE_DEFAULT
A lease in the default state.
static const uint32_t STATE_DECLINED
Declined lease.
@ TYPE_NA
the lease contains non-temporary IPv6 address
Tag for the index for searching by subnet identifier.