Kea 2.5.8
isc::dhcp::PgSqlLeaseStatsQuery Class Reference

Base PgSql derivation of the statistical lease data query. More...

+ Inheritance diagram for isc::dhcp::PgSqlLeaseStatsQuery:

Public Member Functions

 PgSqlLeaseStatsQuery (PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const bool fetch_pool=false)
 Constructor to query for all subnets' stats.
 
 PgSqlLeaseStatsQuery (PgSqlConnection &conn, PgSqlTaggedStatement &statement, 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.
 
 PgSqlLeaseStatsQuery (PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const SubnetID &subnet_id)
 Constructor to query for a single subnet's stats.
 
virtual ~PgSqlLeaseStatsQuery ()
 Destructor.
 
bool getNextRow (LeaseStatsRow &row)
 Fetches the next row in the result set.
 
void start ()
 Creates the 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.
 

Protected Attributes

PgSqlConnectionconn_
 Database connection to use to execute the query.
 
bool fetch_pool_
 Indicates if query requires pool data.
 
bool fetch_type_
 Indicates if query supplies lease type.
 
uint32_t next_row_
 Index of the next row to fetch.
 
boost::shared_ptr< PgSqlResultresult_set_
 The result set returned by Postgres.
 
PgSqlTaggedStatementstatement_
 The query's prepared statement.
 
- 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.
 

Static Protected Attributes

static bool negative_count_ = false
 Received negative state count showing a problem.
 

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...
 

Detailed Description

Base PgSql derivation of the statistical lease data query.

This class provides the functionality such as results storage and row fetching common to fulfilling the statistical lease data query.

Definition at line 1342 of file pgsql_lease_mgr.cc.

Constructor & Destructor Documentation

◆ PgSqlLeaseStatsQuery() [1/3]

isc::dhcp::PgSqlLeaseStatsQuery::PgSqlLeaseStatsQuery ( PgSqlConnection conn,
PgSqlTaggedStatement statement,
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
connA open connection to the database housing the lease data
statementThe lease data SQL prepared statement to execute
fetch_typeIndicates whether or not lease_type should be fetched from the result set
fetch_poolIndicates if query requires pool data

Definition at line 1354 of file pgsql_lease_mgr.cc.

◆ PgSqlLeaseStatsQuery() [2/3]

isc::dhcp::PgSqlLeaseStatsQuery::PgSqlLeaseStatsQuery ( PgSqlConnection conn,
PgSqlTaggedStatement statement,
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
connA open connection to the database housing the lease data
statementThe lease data SQL prepared statement to execute
fetch_typeIndicates if query supplies lease type
subnet_idid of the subnet for which stats are desired

Definition at line 1368 of file pgsql_lease_mgr.cc.

◆ PgSqlLeaseStatsQuery() [3/3]

isc::dhcp::PgSqlLeaseStatsQuery::PgSqlLeaseStatsQuery ( PgSqlConnection conn,
PgSqlTaggedStatement statement,
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
connA open connection to the database housing the lease data
statementThe lease data SQL prepared statement to execute
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

Definition at line 1384 of file pgsql_lease_mgr.cc.

◆ ~PgSqlLeaseStatsQuery()

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

Destructor.

Definition at line 1392 of file pgsql_lease_mgr.cc.

Member Function Documentation

◆ getNextRow()

bool isc::dhcp::PgSqlLeaseStatsQuery::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.

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 1445 of file pgsql_lease_mgr.cc.

References isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_NEGATIVE_LEASES_STAT, fetch_pool_, fetch_type_, isc::db::PgSqlExchange::getColumnValue(), isc::dhcp::LeaseStatsRow::lease_state_, isc::dhcp::LeaseStatsRow::lease_type_, LOG_WARN, negative_count_, next_row_, isc::dhcp::LeaseStatsRow::pool_id_, result_set_, isc::dhcp::LeaseStatsRow::state_count_, isc::dhcp::LeaseStatsRow::subnet_id_, and isc::dhcp::Lease::TYPE_NA.

+ Here is the call graph for this function:

◆ start()

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

Creates the lease statistical data result set.

The result set is populated by executing a prepared SQL query against the database fetches the lease count per lease state per (per least type - v6 only) per subnet id.

Depending upon the selection mode, the query will have either no parameters (for all subnets), a subnet id for a single subnet, or a first and last subnet id for a subnet range.

Reimplemented from isc::dhcp::LeaseStatsQuery.

Definition at line 1403 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::addTempString(), isc::dhcp::LeaseStatsQuery::ALL_SUBNET_POOLS, isc::dhcp::LeaseStatsQuery::ALL_SUBNETS, isc::db::PgSqlConnection::checkStatementError(), conn_, isc::db::PsqlBindArray::formats_, isc::dhcp::LeaseStatsQuery::getFirstSubnetID(), isc::dhcp::LeaseStatsQuery::getLastSubnetID(), isc::dhcp::LeaseStatsQuery::getSelectMode(), isc::db::PsqlBindArray::lengths_, isc::db::PgSqlTaggedStatement::name, result_set_, isc::db::PsqlBindArray::size(), statement_, isc::dhcp::LeaseStatsQuery::SUBNET_RANGE, and isc::db::PsqlBindArray::values_.

+ Here is the call graph for this function:

Member Data Documentation

◆ conn_

PgSqlConnection& isc::dhcp::PgSqlLeaseStatsQuery::conn_
protected

Database connection to use to execute the query.

Definition at line 1502 of file pgsql_lease_mgr.cc.

Referenced by start().

◆ fetch_pool_

bool isc::dhcp::PgSqlLeaseStatsQuery::fetch_pool_
protected

Indicates if query requires pool data.

Definition at line 1517 of file pgsql_lease_mgr.cc.

Referenced by getNextRow().

◆ fetch_type_

bool isc::dhcp::PgSqlLeaseStatsQuery::fetch_type_
protected

Indicates if query supplies lease type.

Definition at line 1514 of file pgsql_lease_mgr.cc.

Referenced by getNextRow().

◆ negative_count_

bool isc::dhcp::PgSqlLeaseStatsQuery::negative_count_ = false
staticprotected

Received negative state count showing a problem.

Definition at line 1520 of file pgsql_lease_mgr.cc.

Referenced by getNextRow().

◆ next_row_

uint32_t isc::dhcp::PgSqlLeaseStatsQuery::next_row_
protected

Index of the next row to fetch.

Definition at line 1511 of file pgsql_lease_mgr.cc.

Referenced by getNextRow().

◆ result_set_

boost::shared_ptr<PgSqlResult> isc::dhcp::PgSqlLeaseStatsQuery::result_set_
protected

The result set returned by Postgres.

Definition at line 1508 of file pgsql_lease_mgr.cc.

Referenced by getNextRow(), and start().

◆ statement_

PgSqlTaggedStatement& isc::dhcp::PgSqlLeaseStatsQuery::statement_
protected

The query's prepared statement.

Definition at line 1505 of file pgsql_lease_mgr.cc.

Referenced by start().


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