| Kea 3.0.2-git

isc::stat_cmds::LeaseStatCmdsImpl Class Reference

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

Inheritance diagram for isc::stat_cmds::LeaseStatCmdsImpl:
[legend]

## 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.
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.
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.
Parameters | getParameters (const ConstElementPtr &cmd_args)
| Parses command arguments into stat-leaseX-get parameters.
int64_t | getSubnetStat (const SubnetID &subnet_id, const std::string &name)
| Fetches a single integer statistic for a subnet from StatsMgr.
uint64_t | makeResultSet4 (const ElementPtr &result, const Parameters &params)
| Executes the lease4 query and constructs the outbound result set.
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.
int | statLease4GetHandler (CalloutHandle &handle)
| Provides the implementation for stat-lease4-get, isc::stat_cmds::StatCmds::statLease4GetHandler.
int | statLease6GetHandler (CalloutHandle &handle)
| Provides the implementation for stat-lease6-get, isc::stat_cmds::StatCmds::statLease6GetHandler.

## 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_rows | list of rows to which to add
  [out] | subnet_id | id of the subnet of the new row. This value is also used for fetching the total addresses in the subnet
  | assigned | number of assigned addresses in the subnet
  | declined | number of declined addresses in the subnet

Definition at line 692 of file stat_cmds.cc.

References Element::create(), Element::createList(), and getSubnetStat().

Referenced by makeResultSet4().

Here is the call graph for this function:

## ◆ 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_rows | list of rows to which to add
  [out] | subnet_id | id of the subnet of the new row. This value is also used for fetching the total NAs and PDs in the subnet
  | assigned | number of assigned NAs in the subnet
  | declined | number of declined NAs in the subnet
  | assigned_pds | number of assigned PDs the subnet

Definition at line 704 of file stat_cmds.cc.

References Element::create(), Element::createList(), getBigSubnetStat(), and getSubnetStat().

Referenced by makeResultSet6().

Here is the call graph for this function:

## ◆ 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

  wrapper | Element to which the newly constructed result-set will be added.
  column_labels | list 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 665 of file stat_cmds.cc.

References Element::create(), Element::createList(), Element::createMap(), and isc::util::ptimeToText().

Referenced by makeResultSet4(), and makeResultSet6().

Here is the call graph for this function:

## ◆ getBigSubnetStat()

int128_t isc::stat_cmds::LeaseStatCmdsImpl::getBigSubnetStat | ( | const SubnetID & | subnet_id,
|  | const std::string & | name )

Fetches a single bigint statistic for a subnet from StatsMgr.

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

Parameters

  subnet_id | the subnet ID for the desired statistic
  name | the name of the desired statistic

Definition at line 730 of file stat_cmds.cc.

References isc::stats::StatsMgr::generateName(), and isc::stats::StatsMgr::instance().

Referenced by addValueRow6().

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_args | Element form of command arguments to parse

Exceptions

  BadValue | if 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 322 of file stat_cmds.cc.

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

Referenced by statLease4GetHandler(), and statLease6GetHandler().

## ◆ getSubnetStat()

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

Fetches a single integer statistic for a subnet from StatsMgr.

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

Parameters

  subnet_id | the subnet ID for the desired statistic
  name | the name of the desired statistic

Definition at line 719 of file stat_cmds.cc.

References isc::stats::StatsMgr::generateName(), and isc::stats::StatsMgr::instance().

Referenced by addValueRow4(), and addValueRow6().

Here is the call graph for this function:

## ◆ 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

  result | Element to which the constructed result-set will be added.
  params | Parsed stat-lease4-cmd parameters

Exceptions

  NotFound | if the selection criteria eliminates all known subnets

Definition at line 396 of file stat_cmds.cc.

References addValueRow4(), isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, createResultSet(), 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.

Referenced by statLease4GetHandler().

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

  result | Element to which the constructed result-set will be added.
  params | Parsed stat-lease6-cmd parameters

Exceptions

  NotFound | if the selection criteria eliminates all known subnets

Definition at line 527 of file stat_cmds.cc.

References addValueRow6(), isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, createResultSet(), 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.

Referenced by statLease6GetHandler().

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

  handle | Callout context - which is expected to contain the command JSON text in the "command" argument

Returns
  0 upon success, non-zero otherwise

Definition at line 228 of file stat_cmds.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), Element::createMap(), isc::config::CmdsImpl::extractCommand(), getParameters(), LOG_ERROR, LOG_INFO, makeResultSet4(), isc::config::CmdsImpl::setErrorResponse(), isc::config::CmdsImpl::setResponse(), 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, and isc::stat_cmds::LeaseStatCmdsImpl::Parameters::toText().

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

  handle | Callout context - which is expected to contain the command JSON text in the "command" argument

Returns
  0 upon success, non-zero otherwise

Definition at line 275 of file stat_cmds.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), Element::createMap(), isc::config::CmdsImpl::extractCommand(), getParameters(), LOG_ERROR, LOG_INFO, makeResultSet6(), isc::config::CmdsImpl::setErrorResponse(), isc::config::CmdsImpl::setResponse(), 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, and isc::stat_cmds::LeaseStatCmdsImpl::Parameters::toText().

Here is the call graph for this function:

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

- stat_cmds.cc