Kea  2.1.7-git
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)
 Constructor to query for all subnets' stats. More...
 
 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. More...
 
 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. More...
 
virtual ~MySqlLeaseStatsQuery ()
 Destructor. More...
 
bool getNextRow (LeaseStatsRow &row)
 Fetches the next row in the result set. More...
 
void start ()
 Creates the IPv4 lease statistical data result set. More...
 
- Public Member Functions inherited from isc::dhcp::LeaseStatsQuery
 LeaseStatsQuery ()
 Default constructor The query created will return statistics for all subnets. More...
 
 LeaseStatsQuery (const SubnetID &subnet_id)
 Constructor to query for a single subnet's stats. More...
 
 LeaseStatsQuery (const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
 Constructor to query for the stats for a range of subnets. More...
 
virtual ~LeaseStatsQuery ()
 virtual destructor More...
 
SubnetID getFirstSubnetID () const
 Returns the value of first subnet ID specified (or zero) More...
 
SubnetID getLastSubnetID () const
 Returns the value of last subnet ID specified (or zero) More...
 
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. More...
 

Additional Inherited Members

- Public Types inherited from isc::dhcp::LeaseStatsQuery
enum  SelectMode { ALL_SUBNETS, SINGLE_SUBNET, SUBNET_RANGE }
 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. More...
 
SubnetID last_subnet_id_
 Last subnet_id in the selection criteria when a range is given. More...
 

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 1513 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 
)
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
Exceptions
ifstatement index is invalid.

Definition at line 1524 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 1544 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 1567 of file mysql_lease_mgr.cc.

◆ ~MySqlLeaseStatsQuery()

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

Destructor.

Definition at line 1580 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 1673 of file mysql_lease_mgr.cc.

References isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MYSQL_NEGATIVE_LEASES_STAT, isc_throw, isc::dhcp::LeaseStatsRow::lease_state_, isc::dhcp::LeaseStatsRow::lease_type_, LOG_WARN, isc::db::MLM_MYSQL_FETCH_SUCCESS, isc::dhcp::LeaseStatsRow::state_count_, and isc::dhcp::LeaseStatsRow::subnet_id_.

◆ 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 1591 of file mysql_lease_mgr.cc.

References isc::db::MLM_TRUE, and isc::db::MysqlExecuteStatement().

+ Here is the call graph for this function:

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