Kea: stat_cmds.cc Source File

| Kea 3.0.2-git

stat_cmds.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8#include <config/command_mgr.h>
9#include <config/cmds_impl.h>
10#include <cc/command_interpreter.h>
11#include <cc/data.h>
12#include <dhcpsrv/cfgmgr.h>
13#include <dhcpsrv/lease_mgr.h>
14#include <dhcpsrv/lease_mgr_factory.h>
15#include <dhcpsrv/subnet_id.h>
16#include <hooks/hooks.h>
17#include <exceptions/exceptions.h>
18#include <stat_cmds.h>
19#include <stat_cmds_log.h>
20#include <stats/stats_mgr.h>
21#include <util/boost_time_utils.h>
22#include <util/multi_threading_mgr.h>
23
24#include <boost/date_time/posix_time/posix_time.hpp>
25#include <string>
26
27using namespace isc::dhcp;
28using namespace isc::data;
29using namespace isc::config;
30using namespace isc::asiolink;
31using namespace isc::hooks;
32using namespace isc::stats;
33using namespace isc::util;
34using namespace isc::log;
35using namespace std;
36
37namespace isc {
38 namespace stat_cmds {
39
43 class NotFound: public isc::Exception {
44public:
45 NotFound (const char* file, size_t line, const char* what) :
46 isc::Exception(file, line, what) { }
47};
48
50 class LeaseStatCmdsImpl : private CmdsImpl {
51public:
52
54 class Parameters {
55 public:
58 SubnetID first_subnet_id_;
59
61 SubnetID last_subnet_id_;
62
65 LeaseStatsQuery::SelectMode select_mode_;
66
68 std::string toText() {
69 std::stringstream os;
70 switch (select_mode_) {
71 case LeaseStatsQuery::ALL_SUBNETS:
72 os << "[all subnets]";
73 break;
74 case LeaseStatsQuery::SINGLE_SUBNET:
75 os << "[subnet-id=" << first_subnet_id_ << "]";
76 break;
77 case LeaseStatsQuery::SUBNET_RANGE:
78 os << "[subnets " << first_subnet_id_
79 << " through " << last_subnet_id_ << "]";
80 break;
81 default:
82 os << "unsupported";
83 }
84
85 return (os.str());
86 }
87 };
88
89public:
90
102 int
103 statLease4GetHandler(CalloutHandle& handle);
104
116 int
117 statLease6GetHandler(CalloutHandle& handle);
118
128 Parameters getParameters(const ConstElementPtr& cmd_args);
129
147 uint64_t makeResultSet4(const ElementPtr& result, const Parameters& params);
148
165 uint64_t makeResultSet6(const ElementPtr& result, const Parameters& params);
166
186 ElementPtr createResultSet(const ElementPtr& wrapper,
187 const std::vector<std::string>& column_labels);
188
196 void addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id,
197 int64_t assigned, int64_t declined);
198
207 void addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id,
208 int64_t assigned, int64_t declined, int64_t assigned_pds);
209
216 int64_t getSubnetStat(const SubnetID& subnet_id, const std::string& name);
217
224 int128_t getBigSubnetStat(const SubnetID& subnet_id, const std::string& name);
225};
226
227int
228LeaseStatCmdsImpl::statLease4GetHandler(CalloutHandle& handle) {
229 ElementPtr result = Element::createMap();
230 Parameters params;
231 ConstElementPtr response;
232
233 // Extract the command and then the parameters
234 try {
235 extractCommand(handle);
236 params = getParameters(cmd_args_);
237 } catch (const std::exception& ex) {
238 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_INVALID)
239 .arg(ex.what());
240 setErrorResponse(handle, ex.what());
241 return (1);
242 }
243
244 try {
245 // Now build the result set
246 uint64_t rows = makeResultSet4(result, params);
247 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET)
248 .arg(params.toText())
249 .arg(rows);
250 std::stringstream os;
251 os << "stat-lease4-get" << params.toText() << ": " << rows << " rows found";
252 response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
253 } catch (const NotFound& ex) {
254 // Criteria was valid but included no known subnets,
255 // so we return a not found response.
256 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET_NO_SUBNETS)
257 .arg(params.toText())
258 .arg(ex.what());
259 std::stringstream os;
260 os << "stat-lease4-get" << params.toText() << ": no matching data, " << ex.what();
261 response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
262 } catch (const std::exception& ex) {
263 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_FAILED)
264 .arg(params.toText())
265 .arg(ex.what());
266 setErrorResponse(handle, ex.what());
267 return (1);
268 }
269
270 setResponse(handle, response);
271 return (0);
272}
273
274int
275LeaseStatCmdsImpl::statLease6GetHandler(CalloutHandle& handle) {
276 ElementPtr result = Element::createMap();
277 Parameters params;
278 ConstElementPtr response;
279
280 // Extract the command and then the parameters
281 try {
282 extractCommand(handle);
283 params = getParameters(cmd_args_);
284 } catch (const std::exception& ex) {
285 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_INVALID)
286 .arg(ex.what());
287 setErrorResponse(handle, ex.what());
288 return (1);
289 }
290
291 try {
292 // Now build the result set
293 uint64_t rows = makeResultSet6(result, params);
294 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET)
295 .arg(params.toText())
296 .arg(rows);
297 std::stringstream os;
298 os << "stat-lease6-get" << params.toText() << ": " << rows << " rows found";
299 response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
300 } catch (const NotFound& ex) {
301 // Criteria was valid but included no known subnets,
302 // so we return a not found response.
303 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET_NO_SUBNETS)
304 .arg(params.toText())
305 .arg(ex.what());
306 std::stringstream os;
307 os << "stat-lease6-get" << params.toText() << ": no matching data, " << ex.what();
308 response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
309 } catch (const std::exception& ex) {
310 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_FAILED)
311 .arg(params.toText())
312 .arg(ex.what());
313 setErrorResponse(handle, ex.what());
314 return (1);
315 }
316
317 setResponse(handle, response);
318 return (0);
319}
320
321 LeaseStatCmdsImpl::Parameters
322LeaseStatCmdsImpl::getParameters(const ConstElementPtr& cmd_args) {
323 Parameters params;
324
325 params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
326 params.first_subnet_id_ = 0;
327 params.last_subnet_id_ = 0;
328 if (!cmd_args ) {
329 // No arguments defaults to ALL_SUBNETS.
330 return (params);
331 }
332
333 if (cmd_args->getType() != Element::map) {
334 isc_throw(BadValue, "'arguments' parameter is not a map");
335 }
336
337 params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
338 if (cmd_args->contains("subnet-id")) {
339
340 ConstElementPtr value = cmd_args->get("subnet-id");
341 if (value->getType() != Element::integer) {
342 isc_throw(BadValue, "'subnet-id' parameter is not integer");
343 }
344
345 if (value->intValue() <= 0) {
346 isc_throw(BadValue, "'subnet-id' parameter must be > 0");
347 }
348
349 params.first_subnet_id_ = value->intValue();
350 params.select_mode_ = LeaseStatsQuery::SINGLE_SUBNET;
351 }
352
353 if (cmd_args->contains("subnet-range")) {
354 if (params.select_mode_ == LeaseStatsQuery::SINGLE_SUBNET) {
355 isc_throw(BadValue, "cannot specify both subnet-id and subnet-range");
356 }
357
358 ConstElementPtr range = cmd_args->get("subnet-range");
359 if (range->getType() != Element::map) {
360 isc_throw(BadValue, "subnet-range parameter is not a map");
361 }
362
363 ConstElementPtr value = range->get("first-subnet-id");
364 if (!value || value->getType() != Element::integer) {
365 isc_throw(BadValue, "'first-subnet-id' parameter missing or not an integer");
366 }
367
368 if (value->intValue() <= 0) {
369 isc_throw(BadValue, "'first-subnet-id' parameter must be > 0");
370 }
371
372 params.first_subnet_id_ = value->intValue();
373
374 value = range->get("last-subnet-id");
375 if (!value || value->getType() != Element::integer) {
376 isc_throw(BadValue, "'last-subnet-id' parameter missing or not an integer");
377 }
378
379 if (value->intValue() <= 0) {
380 isc_throw(BadValue, "'last-subnet-id' parameter must be > 0");
381 }
382
383 params.last_subnet_id_ = value->intValue();
384
385 if (params.last_subnet_id_ < params.first_subnet_id_) {
386 isc_throw(BadValue, "'last-subnet-id' must be greater than 'first-subnet-id'");
387 }
388
389 params.select_mode_ = LeaseStatsQuery::SUBNET_RANGE;
390 }
391
392 return (params);
393}
394
395uint64_t
396LeaseStatCmdsImpl::makeResultSet4(const ElementPtr& result_wrapper,
397 const Parameters& params) {
398 // First we need to determine the range of configured subnets
399 // which meet the selection criteria. If the range contains
400 // no subnets we punt.
401 // Iterate over the selected range of configured subnets generating
402 // a result-set row for each one. If a subnet has data in the query
403 // content use it, otherwise, it gets a row with totals only. This
404 // way we send back a row for every selected subnet.
405 const Subnet4Collection* subnets =
406 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
407
408 // Set the bounds on the selected subnet range
409 auto const& idx = subnets->get<SubnetSubnetIdIndexTag>();
410
411 // Init to ALL so we can use auto
412 auto lower = idx.begin();
413 auto upper = idx.end();
414 switch (params.select_mode_) {
415 case LeaseStatsQuery::SINGLE_SUBNET:
416 lower = idx.find(params.first_subnet_id_);
417 // If it's an unknown subnet, punt.
418 if (lower == idx.end()) {
419 isc_throw(NotFound, "subnet-id: "
420 << params.first_subnet_id_ << " does not exist");
421 }
422
423 upper = idx.upper_bound(params.first_subnet_id_);
424 break;
425 case LeaseStatsQuery::SUBNET_RANGE:
426 lower = idx.lower_bound(params.first_subnet_id_);
427 upper = idx.upper_bound(params.last_subnet_id_);
428 break;
429 default:
430 break;
431 }
432
433 // If it's an empty range, punt.
434 if (lower == upper) {
435 isc_throw(NotFound, "selected ID range: "
436 << params.first_subnet_id_ << " through "
437 << params.last_subnet_id_ << " includes no known subnets");
438 }
439
440 // Now we can run the stats query.
441 LeaseStatsQueryPtr query;
442 switch (params.select_mode_) {
443 case LeaseStatsQuery::ALL_SUBNETS:
444 query = LeaseMgrFactory::instance().startLeaseStatsQuery4();
445 break;
446 case LeaseStatsQuery::SINGLE_SUBNET:
447 query = LeaseMgrFactory::instance()
448 .startSubnetLeaseStatsQuery4(params.first_subnet_id_);
449 break;
450 case LeaseStatsQuery::SUBNET_RANGE:
451 query = LeaseMgrFactory::instance()
452 .startSubnetRangeLeaseStatsQuery4(params.first_subnet_id_,
453 params.last_subnet_id_);
454 break;
455 default:
456 return (0);
457 }
458
459 // Create the result-set map.
460 // labels could be class statics?
461 std::vector<std::string>column_labels = { "subnet-id", "total-addresses",
462 "cumulative-assigned-addresses",
463 "assigned-addresses",
464 "declined-addresses" };
465 ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
466
467 // Get the first query row
468 LeaseStatsRow query_row;
469 bool query_eof = !(query->getNextRow(query_row));
470
471 // Now we iterate over the selected range, building rows accordingly.
472 bool orphaned_stats = false;
473 for (auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
474 SubnetID cur_id = (*cur_subnet)->getID();
475
476 // Skip any unexpected result set rows. These occur when
477 // subnets no longer exist but either their leases (memfile)
478 // or their leaseX-stat rows (db lease backends) still do.
479 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
480 orphaned_stats = true;
481 query_eof = !(query->getNextRow(query_row));
482 }
483
484 // Add total only rows for subnets that occur before
485 // or after the subnets in the query content. These are
486 // subnets which exist but for which there is not yet any
487 // lease data.
488 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
489 // Generate a totals only row
490 addValueRow4(value_rows, cur_id, 0, 0);
491 continue;
492 }
493
494 // Current subnet matches query row, so iterate over its
495 // query rows (one per state) and accumulate them
496 // into a result-set row.
497 int64_t assigned = 0;
498 int64_t declined = 0;
499 bool add_row = false;
500 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
501 if (query_row.lease_state_ == Lease::STATE_DEFAULT) {
502 add_row = true;
503 assigned = query_row.state_count_;
504 } else if (query_row.lease_state_ == Lease::STATE_DECLINED) {
505 add_row = true;
506 declined = query_row.state_count_;
507 }
508
509 // Get next query row
510 query_eof = !(query->getNextRow(query_row));
511 }
512 // Add the row for the current subnet
513 if (add_row) {
514 addValueRow4(value_rows, cur_id, assigned, declined);
515 }
516 }
517
518 // If there are any orphaned statistics log it.
519 if (!(query_eof) || orphaned_stats) {
520 LOG_DEBUG(stat_cmds_logger, DBGLVL_TRACE_BASIC, STAT_CMDS_LEASE4_ORPHANED_STATS);
521 }
522
523 return (value_rows->size());
524}
525
526uint64_t
527LeaseStatCmdsImpl::makeResultSet6(const ElementPtr& result_wrapper,
528 const Parameters& params) {
529 // First we need to determine the range of configured subnets
530 // which meet the selection criteria. If the range contains
531 // no subnets we punt.
532 // Iterate over the selected range of configured subnets generating
533 // a result-set row for each one. If a subnet has data in the query
534 // content use it, otherwise, it gets a row with totals only. This
535 // way we send back a row for every selected subnet.
536 const Subnet6Collection* subnets =
537 CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
538
539 // Set the bounds on the selected subnet range
540 auto const& idx = subnets->get<SubnetSubnetIdIndexTag>();
541
542 // Init to ALL so we can use auto
543 auto lower = idx.begin();
544 auto upper = idx.end();
545 switch (params.select_mode_) {
546 case LeaseStatsQuery::SINGLE_SUBNET:
547 lower = idx.find(params.first_subnet_id_);
548 // If it's an unknown subnet, punt.
549 if (lower == idx.end()) {
550 isc_throw(NotFound, "subnet-id: "
551 << params.first_subnet_id_ << " does not exist");
552 }
553
554 upper = idx.upper_bound(params.first_subnet_id_);
555 break;
556 case LeaseStatsQuery::SUBNET_RANGE:
557 lower = idx.lower_bound(params.first_subnet_id_);
558 upper = idx.upper_bound(params.last_subnet_id_);
559 break;
560 default:
561 break;
562 }
563
564 // If it's an empty range, punt.
565 if (lower == upper) {
566 isc_throw(NotFound, "selected ID range: "
567 << params.first_subnet_id_ << " through "
568 << params.last_subnet_id_ << " includes no known subnets");
569 }
570
571 // Now we can run the stats query.
572 LeaseStatsQueryPtr query;
573 switch (params.select_mode_) {
574 case LeaseStatsQuery::ALL_SUBNETS:
575 query = LeaseMgrFactory::instance().startLeaseStatsQuery6();
576 break;
577 case LeaseStatsQuery::SINGLE_SUBNET:
578 query = LeaseMgrFactory::instance()
579 .startSubnetLeaseStatsQuery6(params.first_subnet_id_);
580 break;
581 case LeaseStatsQuery::SUBNET_RANGE:
582 query = LeaseMgrFactory::instance()
583 .startSubnetRangeLeaseStatsQuery6(params.first_subnet_id_,
584 params.last_subnet_id_);
585 break;
586 default:
587 return (0);
588 }
589
590 // Create the result-set map.
591 // labels could be class statics?
592 std::vector<std::string>column_labels = { "subnet-id", "total-nas",
593 "cumulative-assigned-nas",
594 "assigned-nas",
595 "declined-addresses", "total-pds",
596 "cumulative-assigned-pds",
597 "assigned-pds" };
598 ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
599
600 // Get the first query row
601 LeaseStatsRow query_row;
602 bool query_eof = !(query->getNextRow(query_row));
603
604 // Now we iterate over the selected range, building rows accordingly.
605 bool orphaned_stats = false;
606 for (auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
607 SubnetID cur_id = (*cur_subnet)->getID();
608
609 // Skip any unexpected result set rows. These occur when
610 // subnets no longer exist but either their leases (memfile)
611 // or their leaseX-stat rows (db lease backends) still do.
612 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
613 orphaned_stats = true;
614 query_eof = !(query->getNextRow(query_row));
615 }
616
617 // Add total only rows for subnets that occur before
618 // or after the subnets in the query content. These are
619 // subnets which exist but for which there is not yet any
620 // lease data.
621 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
622 // Generate a totals only row
623 addValueRow6(value_rows, cur_id, 0, 0, 0);
624 continue;
625 }
626
627 // Current subnet matches query row, so iterate over its
628 // query rows (one per state) and accumulate them
629 // into a result-set row.
630 int64_t assigned = 0;
631 int64_t declined = 0;
632 int64_t assigned_pds = 0;
633 bool add_row = false;
634 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
635 if (query_row.lease_state_ == Lease::STATE_DEFAULT) {
636 add_row = true;
637 if (query_row.lease_type_ == Lease::TYPE_NA) {
638 assigned = query_row.state_count_;
639 } else {
640 assigned_pds = query_row.state_count_;
641 }
642 } else if (query_row.lease_state_ == Lease::STATE_DECLINED) {
643 add_row = true;
644 declined = query_row.state_count_;
645 }
646
647 // Get next query row
648 query_eof = !(query->getNextRow(query_row));
649 }
650 // Add the row for the current subnet
651 if (add_row) {
652 addValueRow6(value_rows, cur_id, assigned, declined, assigned_pds);
653 }
654 }
655
656 // If there are any orphaned statistics log it.
657 if (!(query_eof) || orphaned_stats) {
658 LOG_DEBUG(stat_cmds_logger, DBGLVL_TRACE_BASIC, STAT_CMDS_LEASE6_ORPHANED_STATS);
659 }
660
661 return (value_rows->size());
662}
663
664 ElementPtr
665LeaseStatCmdsImpl::createResultSet(const ElementPtr &result_wrapper,
666 const std::vector<std::string>& column_labels) {
667 // Create the result-set map and add it to the wrapper.
668 ElementPtr result_set = Element::createMap();
669 result_wrapper->set("result-set", result_set);
670
671 // Create the timestamp based on time now and add it to the result set.
672 boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
673
674 ElementPtr timestamp = Element::create(isc::util::ptimeToText(now));
675 result_set->set("timestamp", timestamp);
676
677 // Create the list of column names and add it to the result set.
678 ElementPtr columns = Element::createList();
679 for (auto const& label : column_labels) {
680 columns->add(Element::create(label));
681 }
682 result_set->set("columns", columns);
683
684 // Create the empty value_rows list, add it and then return it.
685 ElementPtr value_rows = Element::createList();
686 result_set->set("rows", value_rows);
687 return (value_rows);
688}
689
690
691void
692LeaseStatCmdsImpl::addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id,
693 int64_t assigned, int64_t declined) {
694 ElementPtr row = Element::createList();
695 row->add(Element::create(static_cast<int64_t>(subnet_id)));
696 row->add(Element::create(getSubnetStat(subnet_id, "total-addresses")));
697 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-addresses")));
698 row->add(Element::create(assigned));
699 row->add(Element::create(declined));
700 value_rows->add(row);
701}
702
703void
704LeaseStatCmdsImpl::addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id,
705 int64_t assigned, int64_t declined, int64_t assigned_pds) {
706 ElementPtr row = Element::createList();
707 row->add(Element::create(static_cast<int64_t>(subnet_id)));
708 row->add(Element::create(getBigSubnetStat(subnet_id, "total-nas")));
709 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-nas")));
710 row->add(Element::create(assigned));
711 row->add(Element::create(declined));
712 row->add(Element::create(getBigSubnetStat(subnet_id, "total-pds")));
713 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-pds")));
714 row->add(Element::create(assigned_pds));
715 value_rows->add(row);
716}
717
718int64_t
719LeaseStatCmdsImpl::getSubnetStat(const SubnetID& subnet_id, const std::string& name) {
720 ObservationPtr stat = StatsMgr::instance().
721 getObservation(StatsMgr::generateName("subnet", subnet_id, name));
722 if (stat) {
723 return (stat->getInteger().first);
724 }
725
726 return (0);
727}
728
729 int128_t
730LeaseStatCmdsImpl::getBigSubnetStat(const SubnetID& subnet_id, const std::string& name) {
731 ObservationPtr stat = StatsMgr::instance().
732 getObservation(StatsMgr::generateName("subnet", subnet_id, name));
733 if (stat) {
734 return (stat->getBigInteger().first);
735 }
736
737 return (0);
738}
739
740// Using a critical section to avoid any changes in parallel.
741
742int
743StatCmds::statLease4GetHandler(CalloutHandle& handle) {
744 try {
745 LeaseStatCmdsImpl impl;
746 return (impl.statLease4GetHandler(handle));
747 } catch (const std::exception& ex) {
748
749 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_FAILED)
750 .arg(ex.what());
751 }
752 return (1);
753}
754
755int
756StatCmds::statLease6GetHandler(CalloutHandle& handle) {
757 try {
758 LeaseStatCmdsImpl impl;
759 return (impl.statLease6GetHandler(handle));
760 } catch (const std::exception& ex) {
761
762 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_FAILED)
763 .arg(ex.what());
764 }
765 return (1);
766}
767
768};
769};
boost_time_utils.h
cfgmgr.h
Element::create
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
Element::map
@ map
Definition data.h:147
Element::integer
@ integer
Definition data.h:140
Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
Element::createList
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::config::CmdsImpl
Base class that command handler implementers may use for common tasks.
Definition cmds_impl.h:21
isc::config::CmdsImpl::setErrorResponse
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
Definition cmds_impl.h:54
isc::config::CmdsImpl::cmd_args_
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
Definition cmds_impl.h:72
isc::config::CmdsImpl::extractCommand
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
Definition cmds_impl.h:29
isc::config::CmdsImpl::setResponse
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
Definition cmds_impl.h:64
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::dhcp::CfgMgr::getCurrentCfg
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition cfgmgr.cc:116
isc::dhcp::LeaseMgrFactory::instance
static TrackingLeaseMgr & instance()
Return current lease manager.
Definition lease_mgr_factory.cc:124
isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery6
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
Definition lease_mgr.cc:525
isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery4
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.
Definition lease_mgr.cc:271
isc::dhcp::LeaseMgr::startSubnetRangeLeaseStatsQuery6
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.
Definition lease_mgr.cc:530
isc::dhcp::LeaseMgr::startSubnetLeaseStatsQuery4
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
Definition lease_mgr.cc:266
isc::dhcp::LeaseMgr::startLeaseStatsQuery4
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
Definition lease_mgr.cc:256
isc::dhcp::LeaseMgr::startLeaseStatsQuery6
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
Definition lease_mgr.cc:515
isc::dhcp::LeaseStatsQuery::SelectMode
SelectMode
Defines the types of selection criteria supported.
Definition lease_mgr.h:152
isc::dhcp::LeaseStatsQuery::ALL_SUBNETS
@ ALL_SUBNETS
Definition lease_mgr.h:153
isc::dhcp::LeaseStatsQuery::SINGLE_SUBNET
@ SINGLE_SUBNET
Definition lease_mgr.h:154
isc::dhcp::LeaseStatsQuery::SUBNET_RANGE
@ SUBNET_RANGE
Definition lease_mgr.h:155
isc::hooks::CalloutHandle
Per-packet callout handle.
Definition callout_handle.h:78
isc::stat_cmds::LeaseStatCmdsImpl::Parameters
Wrapper class for stat-leaseX-get command parameters.
Definition stat_cmds.cc:54
isc::stat_cmds::LeaseStatCmdsImpl::Parameters::first_subnet_id_
SubnetID first_subnet_id_
Specifies the subnet-id for a single subnet, or the first subnet for a subnet range.
Definition stat_cmds.cc:58
isc::stat_cmds::LeaseStatCmdsImpl::Parameters::select_mode_
LeaseStatsQuery::SelectMode select_mode_
Denotes the query selection mode all, subnet, or subnet range.
Definition stat_cmds.cc:65
isc::stat_cmds::LeaseStatCmdsImpl::Parameters::toText
std::string toText()
Generate a string version of the contents.
Definition stat_cmds.cc:68
isc::stat_cmds::LeaseStatCmdsImpl::Parameters::last_subnet_id_
SubnetID last_subnet_id_
Specifies the last subnet for subnet range.
Definition stat_cmds.cc:61
isc::stat_cmds::LeaseStatCmdsImpl
Implements command handling for stat-leaseX-get commands.
Definition stat_cmds.cc:50
isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet6
uint64_t makeResultSet6(const ElementPtr &result, const Parameters &params)
Executes the lease4 query and constructs the outbound result set This method uses the command paramet...
Definition stat_cmds.cc:527
isc::stat_cmds::LeaseStatCmdsImpl::getParameters
Parameters getParameters(const ConstElementPtr &cmd_args)
Parses command arguments into stat-leaseX-get parameters.
Definition stat_cmds.cc:322
isc::stat_cmds::LeaseStatCmdsImpl::addValueRow6
void addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id, int64_t assigned, int64_t declined, int64_t assigned_pds)
Adds a row of Lease6 stat values to a list of value rows.
Definition stat_cmds.cc:704
isc::stat_cmds::LeaseStatCmdsImpl::getSubnetStat
int64_t getSubnetStat(const SubnetID &subnet_id, const std::string &name)
Fetches a single integer statistic for a subnet from StatsMgr.
Definition stat_cmds.cc:719
isc::stat_cmds::LeaseStatCmdsImpl::addValueRow4
void addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id, int64_t assigned, int64_t declined)
Adds a row of Lease4 stat values to a list of value rows.
Definition stat_cmds.cc:692
isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet4
uint64_t makeResultSet4(const ElementPtr &result, const Parameters &params)
Executes the lease4 query and constructs the outbound result set.
Definition stat_cmds.cc:396
isc::stat_cmds::LeaseStatCmdsImpl::statLease6GetHandler
int statLease6GetHandler(CalloutHandle &handle)
Provides the implementation for stat-lease6-get, isc::stat_cmds::StatCmds::statLease6GetHandler.
Definition stat_cmds.cc:275
isc::stat_cmds::LeaseStatCmdsImpl::createResultSet
ElementPtr createResultSet(const ElementPtr &wrapper, const std::vector< std::string > &column_labels)
Instantiates a new "empty" result-set Element.
Definition stat_cmds.cc:665
isc::stat_cmds::LeaseStatCmdsImpl::getBigSubnetStat
int128_t getBigSubnetStat(const SubnetID &subnet_id, const std::string &name)
Fetches a single bigint statistic for a subnet from StatsMgr.
Definition stat_cmds.cc:730
isc::stat_cmds::LeaseStatCmdsImpl::statLease4GetHandler
int statLease4GetHandler(CalloutHandle &handle)
Provides the implementation for stat-lease4-get, isc::stat_cmds::StatCmds::statLease4GetHandler.
Definition stat_cmds.cc:228
isc::stat_cmds::NotFound
Exception thrown no subnets fall within the selection criteria This exception is thrown when a valid ...
Definition stat_cmds.cc:43
isc::stat_cmds::NotFound::NotFound
NotFound(const char *file, size_t line, const char *what)
Definition stat_cmds.cc:45
isc::stat_cmds::StatCmds::statLease4GetHandler
int statLease4GetHandler(hooks::CalloutHandle &handle)
stat-lease4-get command handler
Definition stat_cmds.cc:743
isc::stat_cmds::StatCmds::statLease6GetHandler
int statLease6GetHandler(hooks::CalloutHandle &handle)
stat-lease6-get command handler
Definition stat_cmds.cc:756
isc::stats::StatsMgr::instance
static StatsMgr & instance()
Statistics Manager accessor method.
Definition lib/stats/stats_mgr.cc:30
isc::stats::StatsMgr::generateName
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
Definition lib/stats/stats_mgr.h:298
cmds_impl.h
command_interpreter.h
This file contains several functions and constants that are used for handling commands and responses ...
command_mgr.h
data.h
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
hooks.h
lease_mgr.h
An abstract API for lease database.
lease_mgr_factory.h
stats_mgr.h
LOG_ERROR
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
LOG_INFO
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
LOG_DEBUG
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
multi_threading_mgr.h
isc::asiolink
Definition addr_utilities.cc:170
isc::config
Definition command_interpreter.cc:23
isc::config::CONTROL_RESULT_EMPTY
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
Definition command_interpreter.h:53
isc::config::createAnswer
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
Definition command_interpreter.cc:54
isc::config::CONTROL_RESULT_SUCCESS
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
Definition command_interpreter.h:42
isc::data
Definition base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::LeaseStatsQueryPtr
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
Definition lease_mgr.h:233
isc::dhcp::Subnet6Collection
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.
Definition subnet.h:937
isc::dhcp::Subnet4Collection
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.
Definition subnet.h:866
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::hooks
Definition callout_handle.cc:21
isc::log
Definition buffer_appender_impl.cc:17
isc::log::DBGLVL_TRACE_BASIC
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Definition log_dbglevels.h:69
isc::stat_cmds
Definition stat_cmds.cc:38
isc::stat_cmds::stat_cmds_logger
isc::log::Logger stat_cmds_logger("stat-cmds-hooks")
Definition stat_cmds_log.h:17
isc::stats
Definition context.cc:18
isc::stats::ObservationPtr
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
Definition observation.h:479
isc::util::file
Definition filesystem.cc:28
isc::util
Definition time_utils.cc:43
isc::util::int128_t
boost::multiprecision::checked_int128_t int128_t
Definition bigints.h:19
isc::util::ptimeToText
std::string ptimeToText(boost::posix_time::ptime t, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts ptime structure to text.
Definition boost_time_utils.cc:14
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
stat_cmds.h
stat_cmds_log.h
STAT_CMDS_LEASE4_GET_INVALID
const isc::log::MessageID STAT_CMDS_LEASE4_GET_INVALID
STAT_CMDS_LEASE6_GET_INVALID
const isc::log::MessageID STAT_CMDS_LEASE6_GET_INVALID
STAT_CMDS_LEASE6_FAILED
const isc::log::MessageID STAT_CMDS_LEASE6_FAILED
STAT_CMDS_LEASE6_GET
const isc::log::MessageID STAT_CMDS_LEASE6_GET
STAT_CMDS_LEASE4_FAILED
const isc::log::MessageID STAT_CMDS_LEASE4_FAILED
STAT_CMDS_LEASE6_GET_FAILED
const isc::log::MessageID STAT_CMDS_LEASE6_GET_FAILED
STAT_CMDS_LEASE4_GET_NO_SUBNETS
const isc::log::MessageID STAT_CMDS_LEASE4_GET_NO_SUBNETS
STAT_CMDS_LEASE6_GET_NO_SUBNETS
const isc::log::MessageID STAT_CMDS_LEASE6_GET_NO_SUBNETS
STAT_CMDS_LEASE6_ORPHANED_STATS
const isc::log::MessageID STAT_CMDS_LEASE6_ORPHANED_STATS
STAT_CMDS_LEASE4_GET_FAILED
const isc::log::MessageID STAT_CMDS_LEASE4_GET_FAILED
STAT_CMDS_LEASE4_ORPHANED_STATS
const isc::log::MessageID STAT_CMDS_LEASE4_ORPHANED_STATS
STAT_CMDS_LEASE4_GET
const isc::log::MessageID STAT_CMDS_LEASE4_GET
isc::dhcp::LeaseStatsRow
Contains a single row of lease statistical data.
Definition lease_mgr.h:64
isc::dhcp::LeaseStatsRow::state_count_
int64_t state_count_
state_count The count of leases in the lease state
Definition lease_mgr.h:141
isc::dhcp::LeaseStatsRow::lease_state_
uint32_t lease_state_
The lease_state to which the count applies.
Definition lease_mgr.h:138
isc::dhcp::LeaseStatsRow::subnet_id_
SubnetID subnet_id_
The subnet ID to which this data applies.
Definition lease_mgr.h:129
isc::dhcp::LeaseStatsRow::lease_type_
Lease::Type lease_type_
The lease_type to which the count applies.
Definition lease_mgr.h:135
isc::dhcp::Lease::STATE_DEFAULT
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
isc::dhcp::Lease::STATE_DECLINED
static const uint32_t STATE_DECLINED
Declined lease.
Definition lease.h:72
isc::dhcp::Lease::TYPE_NA
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
isc::dhcp::SubnetSubnetIdIndexTag
Tag for the index for searching by subnet identifier.
Definition subnet.h:777
subnet_id.h