15#include <boost/foreach.hpp>
16#include <boost/algorithm/string.hpp>
35 : page_size_(page_size) {
41 if (
page_size_ > std::numeric_limits<uint32_t>::max()) {
43 << std::numeric_limits<uint32_t>::max());
49 uint32_t iaid,
SubnetID subnet_id)
const {
54 <<
static_cast<int>(type) <<
", duid "
55 << duid.
toText() <<
", iaid " << iaid
56 <<
" and subnet-id " << subnet_id);
61 return (*col.begin());
66 using namespace stats;
68 StatsMgr& stats_mgr = StatsMgr::instance();
78 stats_mgr.setValue(
"declined-addresses", zero);
79 stats_mgr.setValue(
"reclaimed-declined-addresses", zero);
80 stats_mgr.setValue(
"reclaimed-leases", zero);
87 for (Subnet4Collection::const_iterator subnet = subnets->begin();
88 subnet != subnets->end(); ++subnet) {
89 SubnetID subnet_id = (*subnet)->getID();
90 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
91 "assigned-addresses"),
94 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
95 "declined-addresses"),
98 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
99 "reclaimed-declined-addresses"),
102 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
110 while (query->getNextRow(row)) {
113 stats_mgr.setValue(StatsMgr::generateName(
"subnet", row.
subnet_id_,
114 "assigned-addresses"),
118 stats_mgr.setValue(StatsMgr::generateName(
"subnet", row.
subnet_id_,
119 "declined-addresses"),
123 stats_mgr.addValue(
"declined-addresses", row.
state_count_);
129 : first_subnet_id_(0), last_subnet_id_(0), select_mode_(ALL_SUBNETS) {
133 : first_subnet_id_(subnet_id), last_subnet_id_(0),
134 select_mode_(SINGLE_SUBNET) {
143 : first_subnet_id_(first_subnet_id), last_subnet_id_(last_subnet_id),
144 select_mode_(SUBNET_RANGE) {
156 "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
183 using namespace stats;
185 StatsMgr& stats_mgr = StatsMgr::instance();
198 stats_mgr.setValue(
"declined-addresses", zero);
199 stats_mgr.setValue(
"reclaimed-declined-addresses", zero);
200 stats_mgr.setValue(
"reclaimed-leases", zero);
207 for (Subnet6Collection::const_iterator subnet = subnets->begin();
208 subnet != subnets->end(); ++subnet) {
209 SubnetID subnet_id = (*subnet)->getID();
210 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
214 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
215 "declined-addresses"),
218 stats_mgr.setValue(StatsMgr::
219 generateName(
"subnet", subnet_id,
220 "reclaimed-declined-addresses"),
223 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
227 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
235 while (query->getNextRow(row)) {
240 stats_mgr.setValue(StatsMgr::
246 stats_mgr.setValue(StatsMgr::
248 "declined-addresses"),
252 stats_mgr.addValue(
"declined-addresses", row.
state_count_);
259 stats_mgr.setValue(StatsMgr::
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Multiple lease records found where one expected.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds DUID (DHCPv6 Unique Identifier)
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
virtual Lease6Collection getLeases6() const =0
Returns all IPv6 leases.
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 leases.
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
const size_t page_size_
Holds page size.
LeasePageSize(const size_t page_size)
Constructor.
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.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row of data.
LeaseStatsQuery()
Default constructor The query created will return statistics for all subnets.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
An abstract API for lease database.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > > > > Subnet6Collection
A collection of Subnet6 objects.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > > > > Subnet4Collection
A collection of Subnet4 objects.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Contains a single row of lease statistical data.
int64_t state_count_
state_count The count of leases in the lease state
uint32_t lease_state_
The lease_state to which the count applies.
SubnetID subnet_id_
The subnet ID to which this data applies.
Lease::Type lease_type_
The lease_type to which the count applies.
static const uint32_t STATE_DEFAULT
A lease in the default state.
static const uint32_t STATE_DECLINED
Declined lease.
Type
Type of lease or pool.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address