2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 14:05:33 +00:00

[#1065] lease commands update statistics

This commit is contained in:
Razvan Becheriu
2020-07-24 17:10:03 +03:00
parent acd3ede7c5
commit eb0396056a

View File

@@ -1207,34 +1207,84 @@ void updateOrAdd(Lease6Ptr lease) {
LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_); LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
// Try to update. // Try to update.
LeaseMgrFactory::instance().updateLease6(lease); LeaseMgrFactory::instance().updateLease6(lease);
bool update = lease6->stateExpiredReclaimed(); if (!lease6->stateExpiredReclaimed()) {
if (lease6->subnet_id_ != lease->subnet_id_) { // old lease is non expired-reclaimed
StatsMgr::instance().addValue( if (lease6->subnet_id_ != lease->subnet_id_) {
StatsMgr::generateName("subnet", lease6->subnet_id_, StatsMgr::instance().addValue(
lease->type_ == Lease::TYPE_NA ? StatsMgr::generateName("subnet", lease6->subnet_id_,
"assigned-nas" : "assigned-pds"), lease->type_ == Lease::TYPE_NA ?
int64_t(-1)); "assigned-nas" : "assigned-pds"),
update = true; int64_t(-1));
} }
if (update) { if (!lease->stateExpiredReclaimed()) {
StatsMgr::instance().addValue( // new lease is non expired-reclaimed
StatsMgr::generateName("subnet", lease->subnet_id_, StatsMgr::instance().addValue(
lease->type_ == Lease::TYPE_NA ? StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-nas" : "assigned-pds"), lease->type_ == Lease::TYPE_NA ?
int64_t(1)); "assigned-nas" : "assigned-pds"),
} int64_t(1));
} else {
// new lease is expired-reclaimed
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
} else {
// old lease is expired-reclaimed
if (lease->stateExpiredReclaimed()) {
// new lease is non expired-reclaimed
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease6->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
} else {
// new lease is expired-reclaimed
if (lease6->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease6->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
}
}
}
} catch (const NoSuchLease& ex) { } catch (const NoSuchLease& ex) {
// Lease to be updated not found, so add it. // Lease to be updated not found, so add it.
if (!LeaseMgrFactory::instance().addLease(lease)) { if (!LeaseMgrFactory::instance().addLease(lease)) {
isc_throw(db::DuplicateEntry, isc_throw(db::DuplicateEntry,
"lost race between calls to update and add"); "lost race between calls to update and add");
} }
StatsMgr::instance().addValue( if (!lease->stateExpiredReclaimed()) {
StatsMgr::generateName("subnet", lease->subnet_id_, // adding a non expired-reclaimed lease
lease->type_ == Lease::TYPE_NA ? StatsMgr::instance().addValue(
"assigned-nas" : "assigned-pds"), StatsMgr::generateName("subnet", lease->subnet_id_,
int64_t(1)); lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
int64_t(1));
} else {
// adding an expired-reclaimed lease
// Increase total number of reclaimed leases.
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
// Increase number of reclaimed leases for a subnet.
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
} }
} }
@@ -1521,30 +1571,81 @@ namespace { // anonymous namepace.
bool addOrUpdate4(Lease4Ptr lease, bool force_create) { bool addOrUpdate4(Lease4Ptr lease, bool force_create) {
Lease4Ptr lease4 = LeaseMgrFactory::instance().getLease4(lease->addr_); Lease4Ptr lease4 = LeaseMgrFactory::instance().getLease4(lease->addr_);
if (force_create && !lease4) { if (force_create && !lease4) {
// lease does not exist
if (!LeaseMgrFactory::instance().addLease(lease)) { if (!LeaseMgrFactory::instance().addLease(lease)) {
isc_throw(db::DuplicateEntry, isc_throw(db::DuplicateEntry,
"lost race between calls to get and add"); "lost race between calls to get and add");
} }
StatsMgr::instance().addValue( if (!lease->stateExpiredReclaimed()) {
StatsMgr::generateName("subnet", lease->subnet_id_, // adding a non expired-reclaimed lease
"assigned-addresses"), StatsMgr::instance().addValue(
int64_t(1)); StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
int64_t(1));
} else {
// adding an expired-reclaimed lease
// Increase total number of reclaimed leases.
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
// Increase number of reclaimed leases for a subnet.
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
return (true); return (true);
} }
LeaseMgrFactory::instance().updateLease4(lease); LeaseMgrFactory::instance().updateLease4(lease);
bool update = lease4->stateExpiredReclaimed(); if (!lease4->stateExpiredReclaimed()) {
if (lease4->subnet_id_ != lease->subnet_id_) { // old lease is non expired-reclaimed
StatsMgr::instance().addValue( if (lease4->subnet_id_ != lease->subnet_id_) {
StatsMgr::generateName("subnet", lease4->subnet_id_, StatsMgr::instance().addValue(
"assigned-addresses"), StatsMgr::generateName("subnet", lease4->subnet_id_,
int64_t(-1)); "assigned-addresses"),
update = true; int64_t(-1));
} }
if (update) { if (!lease->stateExpiredReclaimed()) {
StatsMgr::instance().addValue( // new lease is non expired-reclaimed
StatsMgr::generateName("subnet", lease->subnet_id_, StatsMgr::instance().addValue(
"assigned-addresses"), StatsMgr::generateName("subnet", lease->subnet_id_,
int64_t(1)); "assigned-addresses"),
int64_t(1));
} else {
// new lease is expired-reclaimed
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
} else {
// old lease is expired-reclaimed
if (lease->stateExpiredReclaimed()) {
// new lease is non expired-reclaimed
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-addresses"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease4->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
} else {
// new lease is expired-reclaimed
if (lease4->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease4->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
}
}
} }
return (false); return (false);
} }
@@ -1610,33 +1711,85 @@ bool addOrUpdate6(Lease6Ptr lease, bool force_create) {
Lease6Ptr lease6 = Lease6Ptr lease6 =
LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_); LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
if (force_create && !lease6) { if (force_create && !lease6) {
// lease does not exist
if (!LeaseMgrFactory::instance().addLease(lease)) { if (!LeaseMgrFactory::instance().addLease(lease)) {
isc_throw(db::DuplicateEntry, isc_throw(db::DuplicateEntry,
"lost race between calls to get and add"); "lost race between calls to get and add");
} }
StatsMgr::instance().addValue( if (!lease->stateExpiredReclaimed()) {
StatsMgr::generateName("subnet", lease->subnet_id_, // adding a non expired-reclaimed lease
lease->type_ == Lease::TYPE_NA ? StatsMgr::instance().addValue(
"assigned-nas" : "assigned-pds"), StatsMgr::generateName("subnet", lease->subnet_id_,
int64_t(1)); lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
int64_t(1));
} else {
// adding an expired-reclaimed lease
// Increase total number of reclaimed leases.
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
// Increase number of reclaimed leases for a subnet.
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
return (true); return (true);
} }
LeaseMgrFactory::instance().updateLease6(lease); LeaseMgrFactory::instance().updateLease6(lease);
bool update = lease6->stateExpiredReclaimed(); if (!lease6->stateExpiredReclaimed()) {
if (lease6->subnet_id_ != lease->subnet_id_) { // old lease is non expired-reclaimed
StatsMgr::instance().addValue( if (lease6->subnet_id_ != lease->subnet_id_) {
StatsMgr::generateName("subnet", lease6->subnet_id_, StatsMgr::instance().addValue(
lease->type_ == Lease::TYPE_NA ? StatsMgr::generateName("subnet", lease6->subnet_id_,
"assigned-nas" : "assigned-pds"), lease->type_ == Lease::TYPE_NA ?
int64_t(-1)); "assigned-nas" : "assigned-pds"),
update = true; int64_t(-1));
} }
if (update) { if (!lease->stateExpiredReclaimed()) {
StatsMgr::instance().addValue( // new lease is non expired-reclaimed
StatsMgr::generateName("subnet", lease->subnet_id_, StatsMgr::instance().addValue(
lease->type_ == Lease::TYPE_NA ? StatsMgr::generateName("subnet", lease->subnet_id_,
"assigned-nas" : "assigned-pds"), lease->type_ == Lease::TYPE_NA ?
int64_t(1)); "assigned-nas" : "assigned-pds"),
int64_t(1));
} else {
// new lease is expired-reclaimed
StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
}
} else {
// old lease is expired-reclaimed
if (lease->stateExpiredReclaimed()) {
// new lease is non expired-reclaimed
StatsMgr::instance().addValue(
StatsMgr::generateName("subnet", lease->subnet_id_,
lease->type_ == Lease::TYPE_NA ?
"assigned-nas" : "assigned-pds"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease6->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
} else {
// new lease is expired-reclaimed
if (lease6->subnet_id_ != lease->subnet_id_) {
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease->subnet_id_,
"reclaimed-leases"),
int64_t(1));
StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
lease6->subnet_id_,
"reclaimed-leases"),
int64_t(-1));
}
}
} }
return (false); return (false);
} }