Kea: stat_cmds.cc Source File

| Kea 2.2.0

stat_cmds.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2021 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 }
82
83 return (os.str());
84 }
85 };
86
87public:
88
100 int
101 statLease4GetHandler(CalloutHandle& handle);
102
114 int
115 statLease6GetHandler(CalloutHandle& handle);
116
126 Parameters getParameters(const ConstElementPtr& cmd_args);
127
145 uint64_t makeResultSet4(const ElementPtr& result, const Parameters& params);
146
163 uint64_t makeResultSet6(const ElementPtr& result, const Parameters& params);
164
184 ElementPtr createResultSet(const ElementPtr& wrapper,
185 const std::vector<std::string>& column_labels);
186
194 void addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id,
195 int64_t assigned, int64_t declined);
196
205 void addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id,
206 int64_t assigned, int64_t declined, int64_t assigned_pds);
207
214 int64_t getSubnetStat(const SubnetID& subnet_id, const std::string& name);
215};
216
217int
218LeaseStatCmdsImpl::statLease4GetHandler(CalloutHandle& handle) {
219 ElementPtr result = Element::createMap();
220 Parameters params;
221 ConstElementPtr response;
222
223 // Extract the command and then the parameters
224 try {
225 extractCommand(handle);
226 params = getParameters(cmd_args_);
227 } catch (const std::exception& ex) {
228 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_INVALID)
229 .arg(ex.what());
230 setErrorResponse(handle, ex.what());
231 return (1);
232 }
233
234 try {
235 // Now build the result set
236 uint64_t rows = makeResultSet4(result, params);
237 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET)
238 .arg(params.toText())
239 .arg(rows);
240 std::stringstream os;
241 os << "stat-lease4-get" << params.toText() << ": " << rows << " rows found";
242 response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
243 } catch (const NotFound& ex) {
244 // Criteria was valid but included no known subnets,
245 // so we return a not found response.
246 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET_NO_SUBNETS)
247 .arg(params.toText())
248 .arg(ex.what());
249 std::stringstream os;
250 os << "stat-lease4-get" << params.toText() << ": no matching data, " << ex.what();
251 response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
252 } catch (const std::exception& ex) {
253 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_FAILED)
254 .arg(params.toText())
255 .arg(ex.what());
256 setErrorResponse(handle, ex.what());
257 return (1);
258 }
259
260 setResponse(handle, response);
261 return (0);
262}
263
264int
265LeaseStatCmdsImpl::statLease6GetHandler(CalloutHandle& handle) {
266 ElementPtr result = Element::createMap();
267 Parameters params;
268 ConstElementPtr response;
269
270 // Extract the command and then the parameters
271 try {
272 extractCommand(handle);
273 params = getParameters(cmd_args_);
274 } catch (const std::exception& ex) {
275 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_INVALID)
276 .arg(ex.what());
277 setErrorResponse(handle, ex.what());
278 return (1);
279 }
280
281 try {
282 // Now build the result set
283 uint64_t rows = makeResultSet6(result, params);
284 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET)
285 .arg(params.toText())
286 .arg(rows);
287 std::stringstream os;
288 os << "stat-lease6-get" << params.toText() << ": " << rows << " rows found";
289 response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result);
290 } catch (const NotFound& ex) {
291 // Criteria was valid but included no known subnets,
292 // so we return a not found response.
293 LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET_NO_SUBNETS)
294 .arg(params.toText())
295 .arg(ex.what());
296 std::stringstream os;
297 os << "stat-lease6-get" << params.toText() << ": no matching data, " << ex.what();
298 response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result);
299 } catch (const std::exception& ex) {
300 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_FAILED)
301 .arg(params.toText())
302 .arg(ex.what());
303 setErrorResponse(handle, ex.what());
304 return (1);
305 }
306
307 setResponse(handle, response);
308 return (0);
309}
310
311 LeaseStatCmdsImpl::Parameters
312LeaseStatCmdsImpl::getParameters(const ConstElementPtr& cmd_args) {
313 Parameters params;
314
315 params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
316 params.first_subnet_id_ = 0;
317 params.last_subnet_id_ = 0;
318 if (!cmd_args ) {
319 // No arguments defaults to ALL_SUBNETS.
320 return (params);
321 }
322
323 if (cmd_args->getType() != Element::map) {
324 isc_throw(BadValue, "'arguments' parameter is not a map");
325 }
326
327 params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS;
328 if (cmd_args->contains("subnet-id")) {
329
330 ConstElementPtr value = cmd_args->get("subnet-id");
331 if (value->getType() != Element::integer) {
332 isc_throw(BadValue, "'subnet-id' parameter is not integer");
333 }
334
335 if (value->intValue() <= 0) {
336 isc_throw(BadValue, "'subnet-id' parameter must be > 0");
337 }
338
339 params.first_subnet_id_ = value->intValue();
340 params.select_mode_ = LeaseStatsQuery::SINGLE_SUBNET;
341 }
342
343 if (cmd_args->contains("subnet-range")) {
344 if (params.select_mode_ == LeaseStatsQuery::SINGLE_SUBNET) {
345 isc_throw(BadValue, "cannot specify both subnet-id and subnet-range");
346 }
347
348 ConstElementPtr range = cmd_args->get("subnet-range");
349 if (range->getType() != Element::map) {
350 isc_throw(BadValue, "subnet-range parameter is not a map");
351 }
352
353 ConstElementPtr value = range->get("first-subnet-id");
354 if (!value || value->getType() != Element::integer) {
355 isc_throw(BadValue, "'first-subnet-id' parameter missing or not an integer");
356 }
357
358 if (value->intValue() <= 0) {
359 isc_throw(BadValue, "'first-subnet-id' parameter must be > 0");
360 }
361
362 params.first_subnet_id_ = value->intValue();
363
364 value = range->get("last-subnet-id");
365 if (!value || value->getType() != Element::integer) {
366 isc_throw(BadValue, "'last-subnet-id' parameter missing or not an integer");
367 }
368
369 if (value->intValue() <= 0) {
370 isc_throw(BadValue, "'last-subnet-id' parameter must be > 0");
371 }
372
373 params.last_subnet_id_ = value->intValue();
374
375 if (params.last_subnet_id_ < params.first_subnet_id_) {
376 isc_throw(BadValue, "'last-subnet-id' must be greater than 'first-subnet-id'");
377 }
378
379 params.select_mode_ = LeaseStatsQuery::SUBNET_RANGE;
380 }
381
382 return (params);
383}
384
385uint64_t
386LeaseStatCmdsImpl::makeResultSet4(const ElementPtr& result_wrapper,
387 const Parameters& params) {
388 // First we need to determine the range of configured subnets
389 // which meet the selection criteria. If the range contains
390 // no subnets we punt.
391 // Iterate over the selected range of configured subnets generating
392 // a result-set row for each one. If a subnet has data in the query
393 // content use it, otherwise, it gets a row with totals only. This
394 // way we send back a row for every selected subnet.
395 const Subnet4Collection* subnets =
396 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
397
398 // Set the bounds on the selected subnet range
399 const auto& idx = subnets->get<SubnetSubnetIdIndexTag>();
400
401 // Init to ALL so we can use auto
402 auto lower = idx.begin();
403 auto upper = idx.end();
404 switch (params.select_mode_) {
405 case LeaseStatsQuery::SINGLE_SUBNET:
406 lower = idx.find(params.first_subnet_id_);
407 // If it's an unknown subnet, punt.
408 if (lower == idx.end()) {
409 isc_throw(NotFound, "subnet-id: "
410 << params.first_subnet_id_ << " does not exist");
411 }
412
413 upper = idx.upper_bound(params.first_subnet_id_);
414 break;
415 case LeaseStatsQuery::SUBNET_RANGE:
416 lower = idx.lower_bound(params.first_subnet_id_);
417 upper = idx.upper_bound(params.last_subnet_id_);
418 break;
419 default:
420 break;
421 }
422
423 // If it's an empty range, punt.
424 if (lower == upper) {
425 isc_throw(NotFound, "selected ID range: "
426 << params.first_subnet_id_ << " through "
427 << params.last_subnet_id_ << " includes no known subnets");
428 }
429
430 // Now we can run the stats query.
431 LeaseStatsQueryPtr query;
432 switch (params.select_mode_) {
433 case LeaseStatsQuery::ALL_SUBNETS:
434 query = LeaseMgrFactory::instance().startLeaseStatsQuery4();
435 break;
436 case LeaseStatsQuery::SINGLE_SUBNET:
437 query = LeaseMgrFactory::instance()
438 .startSubnetLeaseStatsQuery4(params.first_subnet_id_);
439 break;
440 case LeaseStatsQuery::SUBNET_RANGE:
441 query = LeaseMgrFactory::instance()
442 .startSubnetRangeLeaseStatsQuery4(params.first_subnet_id_,
443 params.last_subnet_id_);
444 break;
445 }
446
447 // Create the result-set map.
448 // labels could be class statics?
449 std::vector<std::string>column_labels = { "subnet-id", "total-addresses",
450 "cumulative-assigned-addresses",
451 "assigned-addresses",
452 "declined-addresses" };
453 ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
454
455 // Get the first query row
456 LeaseStatsRow query_row;
457 bool query_eof = !(query->getNextRow(query_row));
458
459 // Now we iterate over the selected range, building rows accordingly.
460 bool orphaned_stats = false;
461 for (auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
462 SubnetID cur_id = (*cur_subnet)->getID();
463
464 // Skip any unexpected result set rows. These occur when
465 // subnets no longer exist but either their leases (memfile)
466 // or their leaseX-stat rows (db lease backends) still do.
467 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
468 orphaned_stats = true;
469 query_eof = !(query->getNextRow(query_row));
470 }
471
472 // Add total only rows for subnets that occur before
473 // or after the subnets in the query content. These are
474 // subnets which exist but for which there is not yet any
475 // lease data.
476 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
477 // Generate a totals only row
478 addValueRow4(value_rows, cur_id, 0, 0);
479 continue;
480 }
481
482 // Current subnet matches query row, so iterate over its
483 // query rows (one per state) and accumulate them
484 // into a result-set row.
485 int64_t assigned = 0;
486 int64_t declined = 0;
487 bool add_row = false;
488 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
489 if (query_row.lease_state_ == Lease::STATE_DEFAULT) {
490 add_row = true;
491 assigned = query_row.state_count_;
492 } else if (query_row.lease_state_ == Lease::STATE_DECLINED) {
493 add_row = true;
494 declined = query_row.state_count_;
495 }
496
497 // Get next query row
498 query_eof = !(query->getNextRow(query_row));
499 }
500 // Add the row for the current subnet
501 if (add_row) {
502 addValueRow4(value_rows, cur_id, assigned, declined);
503 }
504 }
505
506 // If there are any orphaned statistics log it.
507 if (!(query_eof) || orphaned_stats) {
508 LOG_DEBUG(stat_cmds_logger, DBGLVL_TRACE_BASIC, STAT_CMDS_LEASE4_ORPHANED_STATS);
509 }
510
511 return (value_rows->size());
512}
513
514uint64_t
515LeaseStatCmdsImpl::makeResultSet6(const ElementPtr& result_wrapper,
516 const Parameters& params) {
517 // First we need to determine the range of configured subnets
518 // which meet the selection criteria. If the range contains
519 // no subnets we punt.
520 // Iterate over the selected range of configured subnets generating
521 // a result-set row for each one. If a subnet has data in the query
522 // content use it, otherwise, it gets a row with totals only. This
523 // way we send back a row for every selected subnet.
524 const Subnet6Collection* subnets =
525 CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
526
527 // Set the bounds on the selected subnet range
528 const auto& idx = subnets->get<SubnetSubnetIdIndexTag>();
529
530 // Init to ALL so we can use auto
531 auto lower = idx.begin();
532 auto upper = idx.end();
533 switch (params.select_mode_) {
534 case LeaseStatsQuery::SINGLE_SUBNET:
535 lower = idx.find(params.first_subnet_id_);
536 // If it's an unknown subnet, punt.
537 if (lower == idx.end()) {
538 isc_throw(NotFound, "subnet-id: "
539 << params.first_subnet_id_ << " does not exist");
540 }
541
542 upper = idx.upper_bound(params.first_subnet_id_);
543 break;
544 case LeaseStatsQuery::SUBNET_RANGE:
545 lower = idx.lower_bound(params.first_subnet_id_);
546 upper = idx.upper_bound(params.last_subnet_id_);
547 break;
548 default:
549 break;
550 }
551
552 // If it's an empty range, punt.
553 if (lower == upper) {
554 isc_throw(NotFound, "selected ID range: "
555 << params.first_subnet_id_ << " through "
556 << params.last_subnet_id_ << " includes no known subnets");
557 }
558
559 // Now we can run the stats query.
560 LeaseStatsQueryPtr query;
561 switch (params.select_mode_) {
562 case LeaseStatsQuery::ALL_SUBNETS:
563 query = LeaseMgrFactory::instance().startLeaseStatsQuery6();
564 break;
565 case LeaseStatsQuery::SINGLE_SUBNET:
566 query = LeaseMgrFactory::instance()
567 .startSubnetLeaseStatsQuery6(params.first_subnet_id_);
568 break;
569 case LeaseStatsQuery::SUBNET_RANGE:
570 query = LeaseMgrFactory::instance()
571 .startSubnetRangeLeaseStatsQuery6(params.first_subnet_id_,
572 params.last_subnet_id_);
573 break;
574 }
575
576 // Create the result-set map.
577 // labels could be class statics?
578 std::vector<std::string>column_labels = { "subnet-id", "total-nas",
579 "cumulative-assigned-nas",
580 "assigned-nas",
581 "declined-nas", "total-pds",
582 "cumulative-assigned-pds",
583 "assigned-pds" };
584 ElementPtr value_rows = createResultSet(result_wrapper, column_labels);
585
586 // Get the first query row
587 LeaseStatsRow query_row;
588 bool query_eof = !(query->getNextRow(query_row));
589
590 // Now we iterate over the selected range, building rows accordingly.
591 bool orphaned_stats = false;
592 for (auto cur_subnet = lower; cur_subnet != upper; ++cur_subnet) {
593 SubnetID cur_id = (*cur_subnet)->getID();
594
595 // Skip any unexpected result set rows. These occur when
596 // subnets no longer exist but either their leases (memfile)
597 // or their leaseX-stat rows (db lease backends) still do.
598 while ((cur_id > query_row.subnet_id_) && (!query_eof)) {
599 orphaned_stats = true;
600 query_eof = !(query->getNextRow(query_row));
601 }
602
603 // Add total only rows for subnets that occur before
604 // or after the subnets in the query content. These are
605 // subnets which exist but for which there is not yet any
606 // lease data.
607 if ((cur_id < query_row.subnet_id_) || (query_eof)) {
608 // Generate a totals only row
609 addValueRow6(value_rows, cur_id, 0, 0, 0);
610 continue;
611 }
612
613 // Current subnet matches query row, so iterate over its
614 // query rows (one per state) and accumulate them
615 // into a result-set row.
616 int64_t assigned = 0;
617 int64_t declined = 0;
618 int64_t assigned_pds = 0;
619 bool add_row = false;
620 while (!query_eof && (query_row.subnet_id_ == cur_id)) {
621 if (query_row.lease_state_ == Lease::STATE_DEFAULT) {
622 add_row = true;
623 if (query_row.lease_type_ == Lease::TYPE_NA) {
624 assigned = query_row.state_count_;
625 } else {
626 assigned_pds = query_row.state_count_;
627 }
628 } else if (query_row.lease_state_ == Lease::STATE_DECLINED) {
629 add_row = true;
630 declined = query_row.state_count_;
631 }
632
633 // Get next query row
634 query_eof = !(query->getNextRow(query_row));
635 }
636 // Add the row for the current subnet
637 if (add_row) {
638 addValueRow6(value_rows, cur_id, assigned, declined, assigned_pds);
639 }
640 }
641
642 // If there are any orphaned statistics log it.
643 if (!(query_eof) || orphaned_stats) {
644 LOG_DEBUG(stat_cmds_logger, DBGLVL_TRACE_BASIC, STAT_CMDS_LEASE6_ORPHANED_STATS);
645 }
646
647 return (value_rows->size());
648}
649
650 ElementPtr
651LeaseStatCmdsImpl::createResultSet(const ElementPtr &result_wrapper,
652 const std::vector<std::string>& column_labels) {
653 // Create the result-set map and add it to the wrapper.
654 ElementPtr result_set = Element::createMap();
655 result_wrapper->set("result-set", result_set);
656
657 // Create the timestamp based on time now and add it to the result set.
658 boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time());
659
660 ElementPtr timestamp = Element::create(isc::util::ptimeToText(now));
661 result_set->set("timestamp", timestamp);
662
663 // Create the list of column names and add it to the result set.
664 ElementPtr columns = Element::createList();
665 for (auto label = column_labels.begin(); label != column_labels.end(); ++label) {
666 columns->add(Element::create(*label));
667 }
668 result_set->set("columns", columns);
669
670 // Create the empty value_rows list, add it and then return it.
671 ElementPtr value_rows = Element::createList();
672 result_set->set("rows", value_rows);
673 return (value_rows);
674}
675
676
677void
678LeaseStatCmdsImpl::addValueRow4(ElementPtr value_rows, const SubnetID &subnet_id,
679 int64_t assigned, int64_t declined) {
680 ElementPtr row = Element::createList();
681 row->add(Element::create(static_cast<int64_t>(subnet_id)));
682 row->add(Element::create(getSubnetStat(subnet_id, "total-addresses")));
683 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-addresses")));
684 row->add(Element::create(assigned));
685 row->add(Element::create(declined));
686 value_rows->add(row);
687}
688
689void
690LeaseStatCmdsImpl::addValueRow6(ElementPtr value_rows, const SubnetID &subnet_id,
691 int64_t assigned, int64_t declined, int64_t assigned_pds) {
692 ElementPtr row = Element::createList();
693 row->add(Element::create(static_cast<int64_t>(subnet_id)));
694 row->add(Element::create(getSubnetStat(subnet_id, "total-nas")));
695 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-nas")));
696 row->add(Element::create(assigned));
697 row->add(Element::create(declined));
698 row->add(Element::create(getSubnetStat(subnet_id, "total-pds")));
699 row->add(Element::create(getSubnetStat(subnet_id, "cumulative-assigned-pds")));
700 row->add(Element::create(assigned_pds));
701 value_rows->add(row);
702}
703
704int64_t
705LeaseStatCmdsImpl::getSubnetStat(const SubnetID& subnet_id, const std::string& name) {
706 ObservationPtr stat = StatsMgr::instance().
707 getObservation(StatsMgr::generateName("subnet", subnet_id, name));
708 if (stat) {
709 return (stat->getInteger().first);
710 }
711
712 return (0);
713}
714
715// Using a critical section to avoid any changes in parallel.
716
717int
718StatCmds::statLease4GetHandler(CalloutHandle& handle) {
719 try {
720 LeaseStatCmdsImpl impl;
721 MultiThreadingCriticalSection cs;
722 return (impl.statLease4GetHandler(handle));
723 } catch (const std::exception& ex) {
724
725 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_FAILED)
726 .arg(ex.what());
727 }
728 return (1);
729}
730
731int
732StatCmds::statLease6GetHandler(CalloutHandle& handle) {
733 try {
734 LeaseStatCmdsImpl impl;
735 MultiThreadingCriticalSection cs;
736 return (impl.statLease6GetHandler(handle));
737 } catch (const std::exception& ex) {
738
739 LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_FAILED)
740 .arg(ex.what());
741 }
742 return (1);
743}
744
745};
746};
boost_time_utils.h
cfgmgr.h
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::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::LeaseStatsQuery::SelectMode
SelectMode
Defines the types of selection criteria supported.
Definition: lease_mgr.h:132
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:515
isc::stat_cmds::LeaseStatCmdsImpl::getParameters
Parameters getParameters(const ConstElementPtr &cmd_args)
Parses command arguments into stat-leaseX-get parameters.
Definition: stat_cmds.cc:312
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:690
isc::stat_cmds::LeaseStatCmdsImpl::getSubnetStat
int64_t getSubnetStat(const SubnetID &subnet_id, const std::string &name)
Fetches a single statistic for a subnet from StatsMgr.
Definition: stat_cmds.cc:705
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:678
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:386
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:265
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:651
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:218
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:718
isc::stat_cmds::StatCmds::statLease6GetHandler
int statLease6GetHandler(hooks::CalloutHandle &handle)
stat-lease6-get command handler
Definition: stat_cmds.cc:732
isc::util::MultiThreadingCriticalSection
RAII class creating a critical section.
Definition: multi_threading_mgr.h:355
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(const int status_code, const std::string &text, const ConstElementPtr &arg)
Definition: command_interpreter.cc:34
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:27
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
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:208
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:964
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:893
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
isc::flex_option::impl
FlexOptionImplPtr impl
Definition: flex_option_callouts.cc:19
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::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:440
isc::util
Definition: edns.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:143
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:62
isc::dhcp::LeaseStatsRow::state_count_
int64_t state_count_
state_count The count of leases in the lease state
Definition: lease_mgr.h:121
isc::dhcp::LeaseStatsRow::lease_state_
uint32_t lease_state_
The lease_state to which the count applies.
Definition: lease_mgr.h:119
isc::dhcp::LeaseStatsRow::subnet_id_
SubnetID subnet_id_
The subnet ID to which this data applies.
Definition: lease_mgr.h:115
isc::dhcp::LeaseStatsRow::lease_type_
Lease::Type lease_type_
The lease_type to which the count applies.
Definition: lease_mgr.h:117
isc::dhcp::SubnetSubnetIdIndexTag
Tag for the index for searching by subnet identifier.
Definition: subnet.h:804
subnet_id.h