24#include <boost/date_time/posix_time/posix_time.hpp>
71 case LeaseStatsQuery::ALL_SUBNETS:
72 os <<
"[all subnets]";
74 case LeaseStatsQuery::SINGLE_SUBNET:
77 case LeaseStatsQuery::SUBNET_RANGE:
185 const std::vector<std::string>& column_labels);
195 int64_t assigned, int64_t declined);
206 int64_t assigned, int64_t declined, int64_t assigned_pds);
227 }
catch (
const std::exception& ex) {
240 std::stringstream os;
241 os <<
"stat-lease4-get" << params.
toText() <<
": " << rows <<
" rows found";
249 std::stringstream os;
250 os <<
"stat-lease4-get" << params.
toText() <<
": no matching data, " << ex.what();
252 }
catch (
const std::exception& ex) {
274 }
catch (
const std::exception& ex) {
287 std::stringstream os;
288 os <<
"stat-lease6-get" << params.
toText() <<
": " << rows <<
" rows found";
296 std::stringstream os;
297 os <<
"stat-lease6-get" << params.
toText() <<
": no matching data, " << ex.what();
299 }
catch (
const std::exception& ex) {
323 if (cmd_args->getType() != Element::map) {
328 if (cmd_args->contains(
"subnet-id")) {
331 if (value->getType() != Element::integer) {
335 if (value->intValue() <= 0) {
343 if (cmd_args->contains(
"subnet-range")) {
344 if (params.
select_mode_ == LeaseStatsQuery::SINGLE_SUBNET) {
349 if (range->getType() != Element::map) {
354 if (!value || value->getType() != Element::integer) {
358 if (value->intValue() <= 0) {
364 value = range->get(
"last-subnet-id");
365 if (!value || value->getType() != Element::integer) {
369 if (value->intValue() <= 0) {
396 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
402 auto lower = idx.begin();
403 auto upper = idx.end();
405 case LeaseStatsQuery::SINGLE_SUBNET:
408 if (lower == idx.end()) {
415 case LeaseStatsQuery::SUBNET_RANGE:
424 if (lower == upper) {
433 case LeaseStatsQuery::ALL_SUBNETS:
434 query = LeaseMgrFactory::instance().startLeaseStatsQuery4();
436 case LeaseStatsQuery::SINGLE_SUBNET:
437 query = LeaseMgrFactory::instance()
440 case LeaseStatsQuery::SUBNET_RANGE:
441 query = LeaseMgrFactory::instance()
449 std::vector<std::string>column_labels = {
"subnet-id",
"total-addresses",
450 "cumulative-assigned-addresses",
451 "assigned-addresses",
452 "declined-addresses" };
457 bool query_eof = !(query->getNextRow(query_row));
460 bool orphaned_stats =
false;
461 for (
auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
462 SubnetID cur_id = (*cur_subnet)->getID();
467 while ((cur_id > query_row.
subnet_id_) && (!query_eof)) {
468 orphaned_stats =
true;
469 query_eof = !(query->getNextRow(query_row));
476 if ((cur_id < query_row.
subnet_id_) || (query_eof)) {
485 int64_t assigned = 0;
486 int64_t declined = 0;
487 bool add_row =
false;
488 while (!query_eof && (query_row.
subnet_id_ == cur_id)) {
492 }
else if (query_row.
lease_state_ == Lease::STATE_DECLINED) {
498 query_eof = !(query->getNextRow(query_row));
507 if (!(query_eof) || orphaned_stats) {
511 return (value_rows->size());
525 CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
531 auto lower = idx.begin();
532 auto upper = idx.end();
534 case LeaseStatsQuery::SINGLE_SUBNET:
537 if (lower == idx.end()) {
544 case LeaseStatsQuery::SUBNET_RANGE:
553 if (lower == upper) {
562 case LeaseStatsQuery::ALL_SUBNETS:
563 query = LeaseMgrFactory::instance().startLeaseStatsQuery6();
565 case LeaseStatsQuery::SINGLE_SUBNET:
566 query = LeaseMgrFactory::instance()
569 case LeaseStatsQuery::SUBNET_RANGE:
570 query = LeaseMgrFactory::instance()
578 std::vector<std::string>column_labels = {
"subnet-id",
"total-nas",
579 "cumulative-assigned-nas",
581 "declined-nas",
"total-pds",
582 "cumulative-assigned-pds",
588 bool query_eof = !(query->getNextRow(query_row));
591 bool orphaned_stats =
false;
592 for (
auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
593 SubnetID cur_id = (*cur_subnet)->getID();
598 while ((cur_id > query_row.
subnet_id_) && (!query_eof)) {
599 orphaned_stats =
true;
600 query_eof = !(query->getNextRow(query_row));
607 if ((cur_id < query_row.
subnet_id_) || (query_eof)) {
616 int64_t assigned = 0;
617 int64_t declined = 0;
618 int64_t assigned_pds = 0;
619 bool add_row =
false;
620 while (!query_eof && (query_row.
subnet_id_ == cur_id)) {
628 }
else if (query_row.
lease_state_ == Lease::STATE_DECLINED) {
634 query_eof = !(query->getNextRow(query_row));
638 addValueRow6(value_rows, cur_id, assigned, declined, assigned_pds);
643 if (!(query_eof) || orphaned_stats) {
647 return (value_rows->size());
652 const std::vector<std::string>& column_labels) {
655 result_wrapper->set(
"result-set", result_set);
658 boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
661 result_set->set(
"timestamp", timestamp);
665 for (
auto label = column_labels.begin(); label != column_labels.end(); ++label) {
666 columns->add(Element::create(*label));
668 result_set->set(
"columns", columns);
671 ElementPtr value_rows = Element::createList();
672 result_set->set(
"rows", value_rows);
679 int64_t assigned, int64_t declined) {
681 row->add(Element::create(
static_cast<int64_t
>(subnet_id)));
682 row->add(Element::create(
getSubnetStat(subnet_id,
"total-addresses")));
683 row->add(Element::create(
getSubnetStat(subnet_id,
"cumulative-assigned-addresses")));
684 row->add(Element::create(assigned));
685 row->add(Element::create(declined));
686 value_rows->add(row);
691 int64_t assigned, int64_t declined, int64_t assigned_pds) {
693 row->add(Element::create(
static_cast<int64_t
>(subnet_id)));
694 row->add(Element::create(
getSubnetStat(subnet_id,
"total-nas")));
695 row->add(Element::create(
getSubnetStat(subnet_id,
"cumulative-assigned-nas")));
696 row->add(Element::create(assigned));
697 row->add(Element::create(declined));
698 row->add(Element::create(
getSubnetStat(subnet_id,
"total-pds")));
699 row->add(Element::create(
getSubnetStat(subnet_id,
"cumulative-assigned-pds")));
700 row->add(Element::create(assigned_pds));
701 value_rows->add(row);
707 getObservation(StatsMgr::generateName(
"subnet", subnet_id, name));
709 return (stat->getInteger().first);
722 return (
impl.statLease4GetHandler(handle));
723 }
catch (
const std::exception& ex) {
736 return (
impl.statLease6GetHandler(handle));
737 }
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.
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 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.
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
RAII class creating a critical section.
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(const int status_code, const std::string &text, const ConstElementPtr &arg)
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.
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.
int64_t state_count_
state_count The count of leases in the lease state
uint32_t lease_state_
The lease_state to which the count applies.
SubnetID subnet_id_
The subnet ID to which this data applies.
Lease::Type lease_type_
The lease_type to which the count applies.
Tag for the index for searching by subnet identifier.