]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1065] updated stats
authorRazvan Becheriu <razvan@isc.org>
Mon, 27 Jul 2020 09:49:11 +0000 (12:49 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 12 Aug 2020 06:56:43 +0000 (09:56 +0300)
src/hooks/dhcp/lease_cmds/lease_cmds.cc

index 1e250e992d48c81115dbe16917be3610bfbd450d..e67eb766374bd2ba2ed3b6109148d12881897ed9 100644 (file)
@@ -367,38 +367,39 @@ public:
     IOAddress getAddressParam(ConstElementPtr params, const std::string name,
                               short family = AF_INET) const;
 
-private:
     /// @brief Update stats when adding lease.
     ///
     /// @param lease4 Added lease.
-    void updateStatsOnAdd(const Lease4Ptr& lease4);
+    static void updateStatsOnAdd(const Lease4Ptr& lease4);
 
     /// @brief Update stats when adding lease.
     ///
     /// @param lease6 Added lease.
-    void updateStatsOnAdd(const Lease6Ptr& lease6);
+    static void updateStatsOnAdd(const Lease6Ptr& lease6);
 
     /// @brief Update stats when updating lease.
     ///
     /// @param lease4 Lease data before update.
     /// @param lease Lease data after update.
-    void updateStatsOnUpdate(const Lease4Ptr& lease4);
+    static void updateStatsOnUpdate(const Lease4Ptr& lease4,
+                                    const Lease4Ptr& lease);
 
     /// @brief Update stats when updating lease.
     ///
     /// @param lease6 Lease data before update.
     /// @param lease Lease data after update.
-    void updateStatsOnUpdate(const Lease6Ptr& lease6);
+    static void updateStatsOnUpdate(const Lease6Ptr& lease6,
+                                    const Lease6Ptr& lease);
 
     /// @brief Update stats when deleting lease.
     ///
     /// @param lease4 Deleted lease.
-    void updateStatsOnDelete(const Lease4Ptr& lease4);
+    static void updateStatsOnDelete(const Lease4Ptr& lease4);
 
     /// @brief Update stats when deleting lease.
     ///
     /// @param lease6 Deleted lease.
-    void updateStatsOnDelete(const Lease6Ptr& lease6);
+    static void updateStatsOnDelete(const Lease6Ptr& lease6);
 };
 
 void
@@ -740,7 +741,7 @@ LeaseCmdsImpl::leaseAddHandler(CalloutHandle& handle) {
                 if (!success) {
                     isc_throw(db::DuplicateEntry, "IPv4 lease already exists.");
                 }
-                updateStatsOnAdd(lease4);
+                LeaseCmdsImpl::updateStatsOnAdd(lease4);
                 resp << "Lease for address " << lease4->addr_.toText()
                      << ", subnet-id " << lease4->subnet_id_ << " added.";
             }
@@ -775,7 +776,7 @@ LeaseCmdsImpl::leaseAddHandler(CalloutHandle& handle) {
                 if (!success) {
                     isc_throw(db::DuplicateEntry, "IPv6 lease already exists.");
                 }
-                updateStatsOnAdd(lease6);
+                LeaseCmdsImpl::updateStatsOnAdd(lease6);
                 if (lease6->type_ == Lease::TYPE_NA) {
                     resp << "Lease for address " << lease6->addr_.toText()
                          << ", subnet-id " << lease6->subnet_id_ << " added.";
@@ -1489,7 +1490,7 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
 
         if (LeaseMgrFactory::instance().deleteLease(lease4)) {
             setSuccessResponse(handle, "IPv4 lease deleted.");
-            updateStatsOnDelete(lease4);
+            LeaseCmdsImpl::updateStatsOnDelete(lease4);
         } else {
             setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
         }
@@ -1515,14 +1516,14 @@ void updateOrAdd(Lease6Ptr lease) {
             LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
         // Try to update.
         LeaseMgrFactory::instance().updateLease6(lease);
-        updateStatsOnUpdate(lease6, lease);
+        LeaseCmdsImpl::updateStatsOnUpdate(lease6, lease);
     } catch (const NoSuchLease& ex) {
         // Lease to be updated not found, so add it.
         if (!LeaseMgrFactory::instance().addLease(lease)) {
             isc_throw(db::DuplicateEntry,
                       "lost race between calls to update and add");
         }
-        updateStatsOnAdd(lease);
+        LeaseCmdsImpl::updateStatsOnAdd(lease);
     }
 }
 
@@ -1615,7 +1616,7 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
                         // leases.
                         if (LeaseMgrFactory::instance().deleteLease(lease)) {
                             ++success_count;
-                            updateStatsOnDelete(lease);
+                            LeaseCmdsImpl::updateStatsOnDelete(lease);
 
                         } else {
                             // Lazy creation of the list of leases which failed to delete.
@@ -1778,7 +1779,7 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) {
 
         if (LeaseMgrFactory::instance().deleteLease(lease6)) {
             setSuccessResponse(handle, "IPv6 lease deleted.");
-            updateStatsOnDelete(lease6);
+            LeaseCmdsImpl::updateStatsOnDelete(lease6);
         } else {
             setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
         }
@@ -1806,11 +1807,11 @@ bool addOrUpdate4(Lease4Ptr lease, bool force_create) {
             isc_throw(db::DuplicateEntry,
                       "lost race between calls to get and add");
         }
-        updateStatsOnAdd(lease);
+        LeaseCmdsImpl::updateStatsOnAdd(lease);
         return (true);
     }
     LeaseMgrFactory::instance().updateLease4(lease);
-    updateStatsOnUpdate(lease4, lease);
+    LeaseCmdsImpl::updateStatsOnUpdate(lease4, lease);
     return (false);
 }
 
@@ -1880,11 +1881,11 @@ bool addOrUpdate6(Lease6Ptr lease, bool force_create) {
             isc_throw(db::DuplicateEntry,
                       "lost race between calls to get and add");
         }
-        updateStatsOnAdd(lease);
+        LeaseCmdsImpl::updateStatsOnAdd(lease);
         return (true);
     }
     LeaseMgrFactory::instance().updateLease6(lease);
-    updateStatsOnUpdate(lease6, lease);
+    LeaseCmdsImpl::updateStatsOnUpdate(lease6, lease);
     return (false);
 }
 
@@ -1965,10 +1966,10 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
             num = LeaseMgrFactory::instance().wipeLeases4(id);
             ids << " " << id;
 
-            int32_t previous_reclaimed = StatsMgr::instance().getObservation(
+            int64_t previous_reclaimed = StatsMgr::instance().getObservation(
                 StatsMgr::generateName("subnet", id, "reclaimed-leases"))->getInteger().first;
 
-            int32_t previous_declined = StatsMgr::instance().getObservation(
+            int64_t previous_declined = StatsMgr::instance().getObservation(
                 StatsMgr::generateName("subnet", id, "declined-addresses"))->getInteger().first;
 
             StatsMgr::instance().setValue(
@@ -2054,10 +2055,10 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
             num = LeaseMgrFactory::instance().wipeLeases6(id);
             ids << " " << id;
 
-            int32_t previous_reclaimed = StatsMgr::instance().getObservation(
+            int64_t previous_reclaimed = StatsMgr::instance().getObservation(
                 StatsMgr::generateName("subnet", id, "reclaimed-leases"))->getInteger().first;
 
-            int32_t previous_declined = StatsMgr::instance().getObservation(
+            int64_t previous_declined = StatsMgr::instance().getObservation(
                 StatsMgr::generateName("subnet", id, "declined-addresses"))->getInteger().first;
 
             StatsMgr::instance().setValue(