15 #include <boost/foreach.hpp>
16 #include <boost/algorithm/string.hpp>
36 LeasePageSize::LeasePageSize(
const size_t page_size)
37 : page_size_(page_size) {
43 if (
page_size_ > std::numeric_limits<uint32_t>::max()) {
45 << std::numeric_limits<uint32_t>::max());
51 uint32_t iaid,
SubnetID subnet_id)
const {
56 << static_cast<int>(type) <<
", duid "
57 << duid.
toText() <<
", iaid " << iaid
58 <<
" and subnet-id " << subnet_id);
63 return (*col.begin());
68 using namespace stats;
70 StatsMgr& stats_mgr = StatsMgr::instance();
82 stats_mgr.setValue(
"declined-addresses", zero);
85 if (!stats_mgr.getObservation(
"reclaimed-declined-addresses")) {
86 stats_mgr.setValue(
"reclaimed-declined-addresses", zero);
90 if (!stats_mgr.getObservation(
"reclaimed-leases")) {
91 stats_mgr.setValue(
"reclaimed-leases", zero);
95 if (!stats_mgr.getObservation(
"cumulative-assigned-addresses")) {
96 stats_mgr.setValue(
"cumulative-assigned-addresses", zero);
104 for (Subnet4Collection::const_iterator subnet = subnets->begin();
105 subnet != subnets->end(); ++subnet) {
106 SubnetID subnet_id = (*subnet)->getID();
107 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
108 "assigned-addresses"),
111 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
112 "declined-addresses"),
115 if (!stats_mgr.getObservation(
116 StatsMgr::generateName(
"subnet", subnet_id,
117 "reclaimed-declined-addresses"))) {
119 StatsMgr::generateName(
"subnet", subnet_id,
120 "reclaimed-declined-addresses"),
124 if (!stats_mgr.getObservation(
125 StatsMgr::generateName(
"subnet", subnet_id,
126 "reclaimed-leases"))) {
128 StatsMgr::generateName(
"subnet", subnet_id,
137 while (query->getNextRow(row)) {
140 stats_mgr.addValue(StatsMgr::generateName(
"subnet", row.
subnet_id_,
141 "assigned-addresses"),
145 stats_mgr.setValue(StatsMgr::generateName(
"subnet", row.
subnet_id_,
146 "declined-addresses"),
150 stats_mgr.addValue(
"declined-addresses", row.
state_count_);
154 stats_mgr.addValue(StatsMgr::generateName(
"subnet", row.
subnet_id_,
155 "assigned-addresses"),
162 : first_subnet_id_(0), last_subnet_id_(0), select_mode_(ALL_SUBNETS) {
166 : first_subnet_id_(subnet_id), last_subnet_id_(0),
167 select_mode_(SINGLE_SUBNET) {
176 : first_subnet_id_(first_subnet_id), last_subnet_id_(last_subnet_id),
177 select_mode_(SUBNET_RANGE) {
189 "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
216 using namespace stats;
218 StatsMgr& stats_mgr = StatsMgr::instance();
230 stats_mgr.setValue(
"declined-addresses", zero);
232 if (!stats_mgr.getObservation(
"reclaimed-declined-addresses")) {
233 stats_mgr.setValue(
"reclaimed-declined-addresses", zero);
236 if (!stats_mgr.getObservation(
"reclaimed-leases")) {
237 stats_mgr.setValue(
"reclaimed-leases", zero);
241 if (!stats_mgr.getObservation(
"cumulative-assigned-nas")) {
242 stats_mgr.setValue(
"cumulative-assigned-nas", zero);
246 if (!stats_mgr.getObservation(
"cumulative-assigned-pds")) {
247 stats_mgr.setValue(
"cumulative-assigned-pds", zero);
255 for (Subnet6Collection::const_iterator subnet = subnets->begin();
256 subnet != subnets->end(); ++subnet) {
257 SubnetID subnet_id = (*subnet)->getID();
258 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
262 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
263 "declined-addresses"),
266 if (!stats_mgr.getObservation(
267 StatsMgr::generateName(
"subnet", subnet_id,
268 "reclaimed-declined-addresses"))) {
270 StatsMgr::generateName(
"subnet", subnet_id,
271 "reclaimed-declined-addresses"),
275 stats_mgr.setValue(StatsMgr::generateName(
"subnet", subnet_id,
279 if (!stats_mgr.getObservation(
280 StatsMgr::generateName(
"subnet", subnet_id,
281 "reclaimed-leases"))) {
283 StatsMgr::generateName(
"subnet", subnet_id,
292 while (query->getNextRow(row)) {
297 stats_mgr.addValue(StatsMgr::
303 stats_mgr.setValue(StatsMgr::
305 "declined-addresses"),
309 stats_mgr.addValue(
"declined-addresses", row.
state_count_);
313 stats_mgr.addValue(StatsMgr::
323 stats_mgr.setValue(StatsMgr::
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
A generic exception that is thrown when a function is not implemented.
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 startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
LeaseStatsQuery()
Default constructor The query created will return statistics for all subnets.
An abstract API for lease database.
static CfgMgr & instance()
returns a single instance of Configuration Manager
the lease contains IPv6 prefix (for prefix delegation)
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds DUID (DHCPv6 Unique Identifier)
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
Multiple lease records found where one expected.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Collection getLeases6() const =0
Returns all IPv6 leases.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
const size_t page_size_
Holds page size.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< 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 > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime,&data::BaseStampedElement::getModificationTime > > >> Subnet4Collection
A collection of Subnet4 objects.
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
SubnetID subnet_id_
The subnet ID to which this data applies.
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 leases.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
the lease contains non-temporary IPv6 address
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< 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< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime,&data::BaseStampedElement::getModificationTime > > >> Subnet6Collection
A collection of Subnet6 objects.
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.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
uint32_t lease_state_
The lease_state to which the count applies.
Type
Type of lease or pool.
static const uint32_t STATE_DEFAULT
A lease in the default state.
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
int64_t state_count_
state_count The count of leases in the lease state
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
static const uint32_t STATE_DECLINED
Declined lease.
Contains a single row of lease statistical data.
Lease::Type lease_type_
The lease_type to which the count applies.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row of data.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)