Kea  2.1.2-git
isc::stat_cmds::LeaseStatCmdsImpl Class Reference

Implements command handling for stat-leaseX-get commands. More...

+ Inheritance diagram for isc::stat_cmds::LeaseStatCmdsImpl:

Classes

class  Parameters
 Wrapper class for stat-leaseX-get command parameters. More...
 

Public Member Functions

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. More...
 
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. More...
 
ElementPtr createResultSet (const ElementPtr &wrapper, const std::vector< std::string > &column_labels)
 Instantiates a new "empty" result-set Element. More...
 
Parameters getParameters (const ConstElementPtr &cmd_args)
 Parses command arguments into stat-leaseX-get parameters. More...
 
int64_t getSubnetStat (const SubnetID &subnet_id, const std::string &name)
 Fetches a single statistic for a subnet from StatsMgr. More...
 
uint64_t makeResultSet4 (const ElementPtr &result, const Parameters &params)
 Executes the lease4 query and constructs the outbound result set. More...
 
uint64_t makeResultSet6 (const ElementPtr &result, const Parameters &params)
 Executes the lease4 query and constructs the outbound result set This method uses the command parameters to identify the range of configured subnets. More...
 
int statLease4GetHandler (CalloutHandle &handle)
 Provides the implementation for stat-lease4-get, isc::stat_cmds::StatCmds::statLease4GetHandler. More...
 
int statLease6GetHandler (CalloutHandle &handle)
 Provides the implementation for stat-lease6-get, isc::stat_cmds::StatCmds::statLease6GetHandler. More...
 

Detailed Description

Implements command handling for stat-leaseX-get commands.

Definition at line 50 of file stat_cmds.cc.

Member Function Documentation

◆ addValueRow4()

void isc::stat_cmds::LeaseStatCmdsImpl::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.

Parameters
[out]value_rowslist of rows to which to add
[out]subnet_idid of the subnet of the new row. This value is also used for fetching the total addresses in the subnet
assignednumber of assigned addresses in the subnet
declinednumber of declined addresses in the subnet

Definition at line 678 of file stat_cmds.cc.

◆ addValueRow6()

void isc::stat_cmds::LeaseStatCmdsImpl::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.

Parameters
[out]value_rowslist of rows to which to add
[out]subnet_idid of the subnet of the new row. This value is also used for fetching the total NAs and PDs in the subnet
assignednumber of assigned NAs in the subnet
declinednumber of declined NAs in the subnet
assigned_pdsnumber of assigned PDs the subnet

Definition at line 690 of file stat_cmds.cc.

◆ createResultSet()

ElementPtr isc::stat_cmds::LeaseStatCmdsImpl::createResultSet ( const ElementPtr wrapper,
const std::vector< std::string > &  column_labels 
)

Instantiates a new "empty" result-set Element.

Constructs a ElementPtr tree of an empty result set for holding rows of the given column labels. In JSON it appears as follows:

"result-set": { "timestamp": "2018-03-22 09:43:30.815371", "columns": ["<label-1>, <label-2>, ... ], "rows": [] }

And then adds it to the given wrapper element.

Parameters
wrapperElement to which the newly constructed result-set will be added.
column_labelslist of the column labels in the order the values for each column will appear in the result-set rows
Returns
A reference to the writable list of rows of the result-set

Definition at line 651 of file stat_cmds.cc.

References isc::util::ptimeToText().

+ Here is the call graph for this function:

◆ getParameters()

LeaseStatCmdsImpl::Parameters isc::stat_cmds::LeaseStatCmdsImpl::getParameters ( const ConstElementPtr cmd_args)

Parses command arguments into stat-leaseX-get parameters.

Parameters
cmd_argsElement form of command arguments to parse
Exceptions
BadValueif any of the following rules are broken:
  1. If subnet-id is specified it must be an integer > 0
  2. If subnet-range is specified it must contain both first-subnet-id and last-subnet-id and their values must fulfill: 0 < first-subnet-id < last-subnet-id
  3. subnet-id and subnet-range are mutually exclusive

Definition at line 312 of file stat_cmds.cc.

References isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::first_subnet_id_, isc_throw, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::last_subnet_id_, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::select_mode_, isc::dhcp::LeaseStatsQuery::SINGLE_SUBNET, and isc::dhcp::LeaseStatsQuery::SUBNET_RANGE.

◆ getSubnetStat()

int64_t isc::stat_cmds::LeaseStatCmdsImpl::getSubnetStat ( const SubnetID subnet_id,
const std::string &  name 
)

Fetches a single statistic for a subnet from StatsMgr.

Uses the given id and name to query the StatsMgr for the desired value.

Parameters
subnet_idid of the desired subnet
namename of the desired statistic

Definition at line 705 of file stat_cmds.cc.

◆ makeResultSet4()

uint64_t isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet4 ( const ElementPtr result,
const Parameters params 
)

Executes the lease4 query and constructs the outbound result set.

This method uses the command parameters to identify the range of configured subnets. If the range contains no known subnets then a NotFound exception is thrown. Having determined the range to be valid, it then executes the appropriate Lease4 stats query via the LeaseMgr.

Lastly, it iterates over the qualifying subnets adding a row of statistics for each one to the result-set. Each row combines the totals from StatsMgr with the type and state counts from the query results. For subnets with no query data (i.e. no leases), their rows have non-zero values for totals only.

Parameters
resultElement to which the constructed result-set will be added.
paramsParsed stat-lease4-cmd parameters
Exceptions
NotFoundif the selection criteria eliminates all known subnets

Definition at line 386 of file stat_cmds.cc.

References isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, isc::log::DBGLVL_TRACE_BASIC, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::first_subnet_id_, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), isc::dhcp::LeaseMgrFactory::instance(), isc_throw, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::last_subnet_id_, isc::dhcp::LeaseStatsRow::lease_state_, LOG_DEBUG, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::select_mode_, isc::dhcp::LeaseStatsQuery::SINGLE_SUBNET, isc::dhcp::LeaseMgr::startLeaseStatsQuery4(), isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery4(), isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery4(), STAT_CMDS_LEASE4_ORPHANED_STATS, isc::stat_cmds::stat_cmds_logger, isc::dhcp::LeaseStatsRow::state_count_, isc::dhcp::Lease::STATE_DECLINED, isc::dhcp::Lease::STATE_DEFAULT, isc::dhcp::LeaseStatsRow::subnet_id_, and isc::dhcp::LeaseStatsQuery::SUBNET_RANGE.

+ Here is the call graph for this function:

◆ makeResultSet6()

uint64_t isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet6 ( const ElementPtr result,
const Parameters params 
)

Executes the lease4 query and constructs the outbound result set This method uses the command parameters to identify the range of configured subnets.

If the range contains no known subnets then a NotFound exception is thrown. Having determined the range to be valid, it then executes the appropriate Lease6 stats query via the LeaseMgr.

Lastly, it iterates over the qualifying subnets adding a row of statistics for each one to the result-set. Each row combines the totals from StatsMgr with the type and state counts from the query results. For subnets with no query data (i.e. no leases), their rows have non-zero values for totals only.

Parameters
resultElement to which the constructed result-set will be added.
paramsParsed stat-lease6-cmd parameters
Exceptions
NotFoundif the selection criteria eliminates all known subnets

Definition at line 515 of file stat_cmds.cc.

References isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, isc::log::DBGLVL_TRACE_BASIC, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::first_subnet_id_, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), isc::dhcp::LeaseMgrFactory::instance(), isc_throw, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::last_subnet_id_, isc::dhcp::LeaseStatsRow::lease_state_, isc::dhcp::LeaseStatsRow::lease_type_, LOG_DEBUG, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::select_mode_, isc::dhcp::LeaseStatsQuery::SINGLE_SUBNET, isc::dhcp::LeaseMgr::startLeaseStatsQuery6(), isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery6(), isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery6(), STAT_CMDS_LEASE6_ORPHANED_STATS, isc::stat_cmds::stat_cmds_logger, isc::dhcp::LeaseStatsRow::state_count_, isc::dhcp::Lease::STATE_DECLINED, isc::dhcp::Lease::STATE_DEFAULT, isc::dhcp::LeaseStatsRow::subnet_id_, isc::dhcp::LeaseStatsQuery::SUBNET_RANGE, and isc::dhcp::Lease::TYPE_NA.

+ Here is the call graph for this function:

◆ statLease4GetHandler()

int isc::stat_cmds::LeaseStatCmdsImpl::statLease4GetHandler ( CalloutHandle handle)

Provides the implementation for stat-lease4-get, isc::stat_cmds::StatCmds::statLease4GetHandler.

It parses the command arguments, and then invokes makeResult4() to fulfil the lease4 statistics fetch. It then constructs the outbound response based on those results. If a NotFound exception is caught, a CONTROL_RESULT_EMTPY response is generated.

Parameters
handleCallout context - which is expected to contain the command JSON text in the "command" argument
Returns
0 upon success, non-zero otherwise

Definition at line 218 of file stat_cmds.cc.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), LOG_ERROR, LOG_INFO, STAT_CMDS_LEASE4_GET, STAT_CMDS_LEASE4_GET_FAILED, STAT_CMDS_LEASE4_GET_INVALID, STAT_CMDS_LEASE4_GET_NO_SUBNETS, isc::stat_cmds::stat_cmds_logger, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::toText(), and isc::Exception::what().

Referenced by isc::stat_cmds::StatCmds::statLease4GetHandler().

+ Here is the call graph for this function:

◆ statLease6GetHandler()

int isc::stat_cmds::LeaseStatCmdsImpl::statLease6GetHandler ( CalloutHandle handle)

Provides the implementation for stat-lease6-get, isc::stat_cmds::StatCmds::statLease6GetHandler.

It parses the command arguments, and then invokes makeResult6() to fulfil the lease6 statistics fetch. It then constructs the outbound response based on those results. If a NotFound exception is caught, a CONTROL_RESULT_EMTPY response is generated.

Parameters
handleCallout context - which is expected to contain the command JSON text in the "command" argument
Returns
0 upon success, non-zero otherwise

Definition at line 265 of file stat_cmds.cc.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), LOG_ERROR, LOG_INFO, STAT_CMDS_LEASE6_GET, STAT_CMDS_LEASE6_GET_FAILED, STAT_CMDS_LEASE6_GET_INVALID, STAT_CMDS_LEASE6_GET_NO_SUBNETS, isc::stat_cmds::stat_cmds_logger, isc::stat_cmds::LeaseStatCmdsImpl::Parameters::toText(), and isc::Exception::what().

Referenced by isc::stat_cmds::StatCmds::statLease6GetHandler().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: