Kea 2.5.8
isc::dhcp::MySqlLeaseStatsQuery Class Reference

MySql derivation of the statistical lease data query. More...

+ Inheritance diagram for isc::dhcp::MySqlLeaseStatsQuery:

Public Member Functions

 MySqlLeaseStatsQuery (MySqlConnection &conn, const size_t statement_index, const bool fetch_type, const bool fetch_pool=false)
 Constructor to query for all subnets' stats.
 
 MySqlLeaseStatsQuery (MySqlConnection &conn, const size_t statement_index, const bool fetch_type, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
 Constructor to query for the stats for a range of subnets.
 
 MySqlLeaseStatsQuery (MySqlConnection &conn, const size_t statement_index, const bool fetch_type, const SubnetID &subnet_id)
 Constructor to query for a single subnet's stats.
 
virtual ~MySqlLeaseStatsQuery ()
 Destructor.
 
bool getNextRow (LeaseStatsRow &row)
 Fetches the next row in the result set.
 
void start ()
 Creates the IPv4 lease statistical data result set.
 
- Public Member Functions inherited from isc::dhcp::LeaseStatsQuery
 LeaseStatsQuery (const SelectMode &select_mode=ALL_SUBNETS)
 Constructor to query statistics for all subnets.
 
 LeaseStatsQuery (const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
 Constructor to query for the stats for a range of subnets.
 
 LeaseStatsQuery (const SubnetID &subnet_id)
 Constructor to query for a single subnet's stats.
 
virtual ~LeaseStatsQuery ()
 virtual destructor
 
SubnetID getFirstSubnetID () const
 Returns the value of first subnet ID specified (or zero)
 
SubnetID getLastSubnetID () const
 Returns the value of last subnet ID specified (or zero)
 
virtual bool getNextRow (LeaseStatsRow &row)
 Fetches the next row of data.
 
SelectMode getSelectMode () const
 Returns the selection criteria mode The value returned is based upon the constructor variant used and it indicates which query variant will be executed.
 
virtual void start ()
 Executes the query.
 

Additional Inherited Members

- Public Types inherited from isc::dhcp::LeaseStatsQuery
enum  SelectMode { ALL_SUBNETS , SINGLE_SUBNET , SUBNET_RANGE , ALL_SUBNET_POOLS }
 Defines the types of selection criteria supported. More...
 
- Protected Attributes inherited from isc::dhcp::LeaseStatsQuery
SubnetID first_subnet_id_
 First (or only) subnet_id in the selection criteria.
 
SubnetID last_subnet_id_
 Last subnet_id in the selection criteria when a range is given.
 

Detailed Description

MySql derivation of the statistical lease data query.

This class is used to recalculate lease statistics for MySQL lease storage. It does so by executing a query which returns a result containing one row per monitored state per lease type per subnet, ordered by subnet id in ascending order.

Definition at line 1846 of file mysql_lease_mgr.cc.

Constructor & Destructor Documentation

◆ MySqlLeaseStatsQuery() [1/3]

isc::dhcp::MySqlLeaseStatsQuery::MySqlLeaseStatsQuery ( MySqlConnection conn,
const size_t  statement_index,
const bool  fetch_type,
const bool  fetch_pool = false 
)
inline

Constructor to query for all subnets' stats.

The query created will return statistics for all subnets

Parameters
connAn open connection to the database housing the lease data
statement_indexIndex of the query's prepared statement
fetch_typeIndicates if query supplies lease type
fetch_poolIndicates if query requires pool data
Exceptions
ifstatement index is invalid.

Definition at line 1858 of file mysql_lease_mgr.cc.

◆ MySqlLeaseStatsQuery() [2/3]

isc::dhcp::MySqlLeaseStatsQuery::MySqlLeaseStatsQuery ( MySqlConnection conn,
const size_t  statement_index,
const bool  fetch_type,
const SubnetID subnet_id 
)
inline

Constructor to query for a single subnet's stats.

The query created will return statistics for a single subnet

Parameters
connAn open connection to the database housing the lease data
statement_indexIndex of the query's prepared statement
fetch_typeIndicates if query supplies lease type
subnet_idid of the subnet for which stats are desired
Exceptions
BadValueif subnet_id given is 0 or if statement index is invalid.

Definition at line 1879 of file mysql_lease_mgr.cc.

◆ MySqlLeaseStatsQuery() [3/3]

isc::dhcp::MySqlLeaseStatsQuery::MySqlLeaseStatsQuery ( MySqlConnection conn,
const size_t  statement_index,
const bool  fetch_type,
const SubnetID first_subnet_id,
const SubnetID last_subnet_id 
)
inline

Constructor to query for the stats for a range of subnets.

The query created will return statistics for the inclusive range of subnets described by first and last subnet IDs.

Parameters
connAn open connection to the database housing the lease data
statement_indexIndex of the query's prepared statement
fetch_typeIndicates if query supplies lease type
first_subnet_idfirst subnet in the range of subnets
last_subnet_idlast subnet in the range of subnets
Exceptions
BadValueif either subnet ID is 0 or if last <= first or if statement index is invalid.

Definition at line 1903 of file mysql_lease_mgr.cc.

◆ ~MySqlLeaseStatsQuery()

virtual isc::dhcp::MySqlLeaseStatsQuery::~MySqlLeaseStatsQuery ( )
inlinevirtual

Destructor.

Definition at line 1918 of file mysql_lease_mgr.cc.

Member Function Documentation

◆ getNextRow()

bool isc::dhcp::MySqlLeaseStatsQuery::getNextRow ( LeaseStatsRow row)
inlinevirtual

Fetches the next row in the result set.

Once the internal result set has been populated by invoking the the start() method, this method is used to iterate over the result set rows. Once the last row has been fetched, subsequent calls will return false.

Checks against negative values for the state count and logs once a warning message. Unfortunately not getting the message is not a proof that detailed counters are correct.

Parameters
rowStorage for the fetched row
Returns
True if the fetch succeeded, false if there are no more rows to fetch.

Reimplemented from isc::dhcp::LeaseStatsQuery.

Definition at line 2020 of file mysql_lease_mgr.cc.

References isc::db::MySqlConnection::checkError(), isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MYSQL_NEGATIVE_LEASES_STAT, isc::dhcp::LeaseStatsRow::lease_state_, isc::dhcp::LeaseStatsRow::lease_type_, LOG_WARN, isc::db::MLM_MYSQL_FETCH_SUCCESS, isc::dhcp::LeaseStatsRow::pool_id_, isc::dhcp::LeaseStatsRow::state_count_, and isc::dhcp::LeaseStatsRow::subnet_id_.

+ Here is the call graph for this function:

◆ start()

void isc::dhcp::MySqlLeaseStatsQuery::start ( )
inlinevirtual

Creates the IPv4 lease statistical data result set.

The result set is populated by executing a SQL query against the lease(4/6) table which sums the leases per lease state per lease type (v6 only) per subnet id. This method binds the statement to the output bind array and then executes the statement, and fetches entire result set.

Reimplemented from isc::dhcp::LeaseStatsQuery.

Definition at line 1929 of file mysql_lease_mgr.cc.

References isc::dhcp::LeaseStatsQuery::ALL_SUBNET_POOLS, isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, isc::db::MySqlConnection::checkError(), isc::dhcp::LeaseStatsQuery::first_subnet_id_, isc::dhcp::LeaseStatsQuery::getSelectMode(), isc::dhcp::LeaseStatsQuery::last_subnet_id_, isc::db::MLM_TRUE, isc::db::MysqlExecuteStatement(), isc::dhcp::LeaseStatsQuery::SUBNET_RANGE, and isc::dhcp::Lease::TYPE_NA.

+ Here is the call graph for this function:

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