From: Razvan Becheriu Date: Wed, 5 Aug 2020 13:56:34 +0000 (+0300) Subject: [#1336] updated behavior for reclaimed related counters X-Git-Tag: Kea-1.8.0~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98f3a2fb696b21e3d9b4dcae5745cff0bad857b7;p=thirdparty%2Fkea.git [#1336] updated behavior for reclaimed related counters --- diff --git a/doc/sphinx/arm/dhcp4-srv.rst b/doc/sphinx/arm/dhcp4-srv.rst index ed9040e65b..2802df14ec 100644 --- a/doc/sphinx/arm/dhcp4-srv.rst +++ b/doc/sphinx/arm/dhcp4-srv.rst @@ -5722,9 +5722,16 @@ The DHCPv4 server supports the following statistics: | | | server startup. It is | | | | incremented each time | | | | an expired lease is | - | | | reclaimed and is | - | | | reset when the server | - | | | is reconfigured. | + | | | reclaimed. | + | | | This statistic never | + | | | decreases. It can be | + | | | used as a long-term | + | | | indicator of how many | + | | | actual leases have been | + | | | reclaimed. | + | | | This is a global | + | | | statistic that covers | + | | | all subnets. | +-------------------------------------------+----------------+------------------------------------+ | subnet[id].reclaimed-leases | integer | Number of expired | | | | leases associated | @@ -5735,9 +5742,13 @@ The DHCPv4 server supports the following statistics: | | | server startup. It is | | | | incremented each time | | | | an expired lease is | - | | | reclaimed and is | - | | | reset when the server | - | | | is reconfigured. | + | | | reclaimed. | + | | | The *id* is the | + | | | subnet-id of a | + | | | given subnet. This | + | | | statistic is exposed | + | | | for each subnet | + | | | separately. | +-------------------------------------------+----------------+------------------------------------+ | declined-addresses | integer | Number of IPv4 | | | | addresses that are | diff --git a/doc/sphinx/arm/dhcp6-srv.rst b/doc/sphinx/arm/dhcp6-srv.rst index 04943166ad..2c16ec8fcf 100644 --- a/doc/sphinx/arm/dhcp6-srv.rst +++ b/doc/sphinx/arm/dhcp6-srv.rst @@ -5753,9 +5753,16 @@ The DHCPv6 server supports the following statistics: | | | an expired lease is | | | | reclaimed (counting | | | | both NA and PD | - | | | reclamations) and is | - | | | reset when the server | - | | | is reconfigured. | + | | | reclamations). | + | | | This statistic never | + | | | decreases. It can be | + | | | used as a long-term | + | | | indicator of how many | + | | | actual leases have been| + | | | reclaimed. | + | | | This is a global | + | | | statistic that covers | + | | | all subnets. | +-----------------------------------------+-----------------------+------------------------+ | subnet[id].reclaimed-leases | integer | Number of expired | | | | leases associated | @@ -5768,9 +5775,13 @@ The DHCPv6 server supports the following statistics: | | | an expired lease is | | | | reclaimed (counting | | | | both NA and PD | - | | | reclamations) and is | - | | | reset when the server | - | | | is reconfigured. | + | | | reclamations). | + | | | The *id* is the | + | | | subnet-id of a | + | | | given subnet. This | + | | | statistic is exposed | + | | | for each subnet | + | | | separately. | +-----------------------------------------+-----------------------+------------------------+ | declined-addresses | integer | Number of IPv6 | | | | addresses that are | diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index c1e2f370ad..8f7856974f 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -74,10 +74,20 @@ LeaseMgr::recountLeaseStats4() { } // Zero out the global stats. + // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases", + // "cumulative-assigned-addresses") never gets zeroed. int64_t zero = 0; stats_mgr.setValue("declined-addresses", zero); - stats_mgr.setValue("reclaimed-declined-addresses", zero); - stats_mgr.setValue("reclaimed-leases", zero); + + // Create if it does not exit reclaimed declined leases global stats. + if (!stats_mgr.getObservation("reclaimed-declined-addresses")) { + stats_mgr.setValue("reclaimed-declined-addresses", zero); + } + + // Create if it does not exit reclaimed leases global stats. + if (!stats_mgr.getObservation("reclaimed-leases")) { + stats_mgr.setValue("reclaimed-leases", zero); + } // Create if it does not exit cumulative global stats. if (!stats_mgr.getObservation("cumulative-assigned-addresses")) { @@ -100,13 +110,23 @@ LeaseMgr::recountLeaseStats4() { "declined-addresses"), zero); - stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, - "reclaimed-declined-addresses"), - zero); + if (!stats_mgr.getObservation( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-declined-addresses"))) { + stats_mgr.setValue( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-declined-addresses"), + zero); + } - stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, - "reclaimed-leases"), - zero); + if (!stats_mgr.getObservation( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-leases"))) { + stats_mgr.setValue( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-leases"), + zero); + } } // Get counts per state per subnet. Iterate over the result set @@ -128,6 +148,7 @@ LeaseMgr::recountLeaseStats4() { stats_mgr.addValue("declined-addresses", row.state_count_); // Add to subnet level value. + // Declined leases also count as assigned. stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_, "assigned-addresses"), row.state_count_); @@ -200,20 +221,26 @@ LeaseMgr::recountLeaseStats6() { return; } - // Zero out the global stats. (Ok, so currently there's only one - // that should be cleared. "reclaimed-declined-addresses" never - // gets zeroed. @todo discuss with Tomek the rational of not - // clearing it when we clear the rest. + // Zero out the global stats. + // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases", + // "cumulative-assigned-nas", "cumulative-assigned-pds") never gets zeroed. int64_t zero = 0; stats_mgr.setValue("declined-addresses", zero); - stats_mgr.setValue("reclaimed-declined-addresses", zero); - stats_mgr.setValue("reclaimed-leases", zero); - // Create if it does not exit cumulative global stats. + if (!stats_mgr.getObservation("reclaimed-declined-addresses")) { + stats_mgr.setValue("reclaimed-declined-addresses", zero); + } + + if (!stats_mgr.getObservation("reclaimed-leases")) { + stats_mgr.setValue("reclaimed-leases", zero); + } + + // Create if it does not exit cumulative nas global stats. if (!stats_mgr.getObservation("cumulative-assigned-nas")) { stats_mgr.setValue("cumulative-assigned-nas", zero); } + // Create if it does not exit cumulative pds global stats. if (!stats_mgr.getObservation("cumulative-assigned-pds")) { stats_mgr.setValue("cumulative-assigned-pds", zero); } @@ -234,18 +261,27 @@ LeaseMgr::recountLeaseStats6() { "declined-addresses"), zero); - stats_mgr.setValue(StatsMgr:: - generateName("subnet", subnet_id, - "reclaimed-declined-addresses"), - zero); + if (!stats_mgr.getObservation( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-declined-addresses"))) { + stats_mgr.setValue( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-declined-addresses"), + zero); + } stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, "assigned-pds"), zero); - stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id, - "reclaimed-leases"), - zero); + if (!stats_mgr.getObservation( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-leases"))) { + stats_mgr.setValue( + StatsMgr::generateName("subnet", subnet_id, + "reclaimed-leases"), + zero); + } } // Get counts per state per subnet. Iterate over the result set @@ -271,6 +307,7 @@ LeaseMgr::recountLeaseStats6() { stats_mgr.addValue("declined-addresses", row.state_count_); // Add subnet level value. + // Declined leases also count as assigned. stats_mgr.addValue(StatsMgr:: generateName("subnet", row.subnet_id_, "assigned-nas"),