123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
- //
- // This Source Code Form is subject to the terms of the Mozilla Public
- // License, v. 2.0. If a copy of the MPL was not distributed with this
- // file, You can obtain one at http://mozilla.org/MPL/2.0/.
- #include <config.h>
- #include <dhcpsrv/cfgmgr.h>
- #include <dhcpsrv/dhcpsrv_log.h>
- #include <dhcpsrv/lease_mgr.h>
- #include <exceptions/exceptions.h>
- #include <stats/stats_mgr.h>
- #include <boost/foreach.hpp>
- #include <boost/algorithm/string.hpp>
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <map>
- #include <sstream>
- #include <string>
- #include <time.h>
- using namespace std;
- namespace isc {
- namespace dhcp {
- Lease6Ptr
- LeaseMgr::getLease6(Lease::Type type, const DUID& duid,
- uint32_t iaid, SubnetID subnet_id) const {
- Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
- if (col.size() > 1) {
- isc_throw(MultipleRecords, "More than one lease found for type "
- << static_cast<int>(type) << ", duid "
- << duid.toText() << ", iaid " << iaid
- << " and subnet-id " << subnet_id);
- }
- if (col.empty()) {
- return (Lease6Ptr());
- }
- return (*col.begin());
- }
- void
- LeaseMgr::recountAddressStats4() {
- using namespace stats;
- StatsMgr& stats_mgr = StatsMgr::instance();
- AddressStatsQuery4Ptr query = startAddressStatsQuery4();
- if (!query) {
- /// NULL means not backend does not support recounting.
- 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.
- int64_t zero = 0;
- stats_mgr.setValue("declined-addresses", zero);
- stats_mgr.setValue("declined-reclaimed-addresses", zero);
- // Clear subnet level stats. This ensures we don't end up with corner
- // cases that leave stale values in place.
- const Subnet4Collection* subnets =
- CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
- for (Subnet4Collection::const_iterator subnet = subnets->begin();
- subnet != subnets->end(); ++subnet) {
- SubnetID subnet_id = (*subnet)->getID();
- stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
- "assigned-addresses"),
- zero);
- stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
- "declined-addresses"),
- zero);
- stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
- "declined-reclaimed-addresses"),
- zero);
- }
-
- // Get counts per state per subnet. Iterate over the result set
- // updating the subnet and global values.
- AddressStatsRow4 row;
- while (query->getNextRow(row)) {
- switch(row.lease_state_) {
- case Lease::STATE_DEFAULT:
- // Set subnet level value.
- stats_mgr.setValue(StatsMgr::generateName("subnet",
- row.subnet_id_,
- "assigned-addresses"),
- row.state_count_);
- break;
- case Lease::STATE_DECLINED:
- // Set subnet level value.
- stats_mgr.setValue(StatsMgr::generateName("subnet",
- row.subnet_id_,
- "declined-addresses"),
- row.state_count_);
- // Add to the global value.
- stats_mgr.addValue("declined-addresses", row.state_count_);
- break;
- default:
- // Not one we're tracking.
- break;
- }
- }
- }
- AddressStatsQuery4Ptr
- LeaseMgr::startAddressStatsQuery4() {
- return(AddressStatsQuery4Ptr());
- }
- std::string
- LeaseMgr::getDBVersion() {
- isc_throw(NotImplemented, "LeaseMgr::getDBVersion() called");
- }
- } // namespace isc::dhcp
- } // namespace isc
|