14 #include <boost/make_shared.hpp>
27 StatsMgr::instance() {
32 StatsMgr::StatsMgr() :
38 if (MultiThreadingMgr::instance().getMode()) {
39 lock_guard<mutex> lock(*mutex_);
48 if (MultiThreadingMgr::instance().getMode()) {
49 lock_guard<mutex> lock(*mutex_);
58 if (MultiThreadingMgr::instance().getMode()) {
59 lock_guard<mutex> lock(*mutex_);
68 if (MultiThreadingMgr::instance().getMode()) {
69 lock_guard<mutex> lock(*mutex_);
78 if (MultiThreadingMgr::instance().getMode()) {
79 lock_guard<mutex> lock(*mutex_);
88 if (MultiThreadingMgr::instance().getMode()) {
89 lock_guard<mutex> lock(*mutex_);
98 if (MultiThreadingMgr::instance().getMode()) {
99 lock_guard<mutex> lock(*mutex_);
108 if (MultiThreadingMgr::instance().getMode()) {
109 lock_guard<mutex> lock(*mutex_);
118 if (MultiThreadingMgr::instance().getMode()) {
119 lock_guard<mutex> lock(*mutex_);
130 return (global_->get(name));
135 if (MultiThreadingMgr::instance().getMode()) {
136 lock_guard<mutex> lock(*mutex_);
151 StatsMgr::deleteObservation(
const string& name) {
152 if (MultiThreadingMgr::instance().getMode()) {
153 lock_guard<mutex> lock(*mutex_);
154 return (deleteObservationInternal(name));
156 return (deleteObservationInternal(name));
161 StatsMgr::deleteObservationInternal(
const string& name) {
164 return (global_->del(name));
169 if (MultiThreadingMgr::instance().getMode()) {
170 lock_guard<mutex> lock(*mutex_);
171 return (setMaxSampleAgeInternal(name, duration));
173 return (setMaxSampleAgeInternal(name, duration));
178 StatsMgr::setMaxSampleAgeInternal(
const string& name,
182 obs->setMaxSampleAge(duration);
190 if (MultiThreadingMgr::instance().getMode()) {
191 lock_guard<mutex> lock(*mutex_);
192 return (setMaxSampleCountInternal(name, max_samples));
194 return (setMaxSampleCountInternal(name, max_samples));
199 StatsMgr::setMaxSampleCountInternal(
const string& name,
200 uint32_t max_samples) {
203 obs->setMaxSampleCount(max_samples);
211 if (MultiThreadingMgr::instance().getMode()) {
212 lock_guard<mutex> lock(*mutex_);
213 setMaxSampleAgeAllInternal(duration);
215 setMaxSampleAgeAllInternal(duration);
220 StatsMgr::setMaxSampleAgeAllInternal(
const StatsDuration& duration) {
221 global_->setMaxSampleAgeAll(duration);
226 if (MultiThreadingMgr::instance().getMode()) {
227 lock_guard<mutex> lock(*mutex_);
228 setMaxSampleCountAllInternal(max_samples);
230 setMaxSampleCountAllInternal(max_samples);
235 StatsMgr::setMaxSampleCountAllInternal(uint32_t max_samples) {
236 global_->setMaxSampleCountAll(max_samples);
241 if (MultiThreadingMgr::instance().getMode()) {
242 lock_guard<mutex> lock(*mutex_);
243 setMaxSampleAgeDefaultInternal(duration);
245 setMaxSampleAgeDefaultInternal(duration);
250 StatsMgr::setMaxSampleAgeDefaultInternal(
const StatsDuration& duration) {
256 if (MultiThreadingMgr::instance().getMode()) {
257 lock_guard<mutex> lock(*mutex_);
258 setMaxSampleCountDefaultInternal(max_samples);
260 setMaxSampleCountDefaultInternal(max_samples);
265 StatsMgr::setMaxSampleCountDefaultInternal(uint32_t max_samples) {
271 if (MultiThreadingMgr::instance().getMode()) {
272 lock_guard<mutex> lock(*mutex_);
273 return (getMaxSampleAgeDefaultInternal());
275 return (getMaxSampleAgeDefaultInternal());
280 StatsMgr::getMaxSampleAgeDefaultInternal()
const {
286 if (MultiThreadingMgr::instance().getMode()) {
287 lock_guard<mutex> lock(*mutex_);
288 return (getMaxSampleCountDefaultInternal());
290 return (getMaxSampleCountDefaultInternal());
295 StatsMgr::getMaxSampleCountDefaultInternal()
const {
301 if (MultiThreadingMgr::instance().getMode()) {
302 lock_guard<mutex> lock(*mutex_);
303 return (resetInternal(name));
305 return (resetInternal(name));
310 StatsMgr::resetInternal(
const string& name) {
321 if (MultiThreadingMgr::instance().getMode()) {
322 lock_guard<mutex> lock(*mutex_);
323 return (delInternal(name));
325 return (delInternal(name));
330 StatsMgr::delInternal(
const string& name) {
331 return (global_->del(name));
336 if (MultiThreadingMgr::instance().getMode()) {
337 lock_guard<mutex> lock(*mutex_);
345 StatsMgr::removeAllInternal() {
351 if (MultiThreadingMgr::instance().getMode()) {
352 lock_guard<mutex> lock(*mutex_);
353 return (getInternal(name));
355 return (getInternal(name));
360 StatsMgr::getInternal(
const string& name)
const {
364 map->set(name, obs->getJSON());
371 if (MultiThreadingMgr::instance().getMode()) {
372 lock_guard<mutex> lock(*mutex_);
373 return (getAllInternal());
375 return (getAllInternal());
380 StatsMgr::getAllInternal()
const {
381 return (global_->getAll());
386 if (MultiThreadingMgr::instance().getMode()) {
387 lock_guard<mutex> lock(*mutex_);
395 StatsMgr::resetAllInternal() {
401 if (MultiThreadingMgr::instance().getMode()) {
402 lock_guard<mutex> lock(*mutex_);
403 return (getSizeInternal(name));
405 return (getSizeInternal(name));
410 StatsMgr::getSizeInternal(
const string& name)
const {
413 return (obs->getSize());
420 if (MultiThreadingMgr::instance().getMode()) {
421 lock_guard<mutex> lock(*mutex_);
422 return (countInternal());
424 return (countInternal());
429 StatsMgr::countInternal()
const {
430 return (global_->size());
438 if (!StatsMgr::getStatName(params, name, error)) {
441 if (!StatsMgr::getStatDuration(params, duration, error)) {
446 "Statistic '" + name +
"' duration limit is set."));
449 "No '" + name +
"' statistic found"));
457 uint32_t max_samples;
458 if (!StatsMgr::getStatName(params, name, error)) {
461 if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) {
466 "Statistic '" + name +
"' count limit is set."));
469 "No '" + name +
"' statistic found"));
477 if (!StatsMgr::getStatName(params, name, error)) {
488 if (!StatsMgr::getStatName(params, name, error)) {
493 "Statistic '" + name +
"' reset."));
496 "No '" + name +
"' statistic found"));
504 if (!StatsMgr::getStatName(params, name, error)) {
509 "Statistic '" + name +
"' removed."));
512 "No '" + name +
"' statistic found"));
522 "Warning: statistic-remove-all command is deprecated."
523 " All statistics removed."));
538 "All statistics reset to neutral values."));
545 if (!StatsMgr::getStatDuration(params, duration, error)) {
548 if (MultiThreadingMgr::instance().getMode()) {
549 lock_guard<mutex> lock(*mutex_);
559 "All statistics duration limit are set."));
565 uint32_t max_samples;
566 if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) {
569 if (max_samples == 0) {
570 error =
"'max-samples' parameter must not be zero";
573 if (MultiThreadingMgr::instance().getMode()) {
574 lock_guard<mutex> lock(*mutex_);
582 "All statistics count limit are set."));
590 reason =
"Missing mandatory 'name' parameter.";
595 reason =
"Missing mandatory 'name' parameter.";
598 if (stat_name->getType() != Element::string) {
599 reason =
"'name' parameter expected to be a string.";
602 name = stat_name->stringValue();
611 reason =
"Missing mandatory 'duration' parameter.";
615 if (!stat_duration) {
616 reason =
"Missing mandatory 'duration' parameter.";
619 duration = std::chrono::seconds(stat_duration->intValue());
625 uint32_t& max_samples,
628 reason =
"Missing mandatory 'max-samples' parameter.";
632 if (!stat_max_samples) {
633 reason =
"Missing mandatory 'max-samples' parameter.";
636 if (stat_max_samples->getType() != Element::integer) {
637 reason =
"'max-samples' parameter expected to be an integer.";
640 max_samples = stat_max_samples->intValue();
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get command.
static isc::data::ConstElementPtr statisticSetMaxSampleAgeHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set command.
static void setMaxSampleAgeDefault(const StatsDuration &duration)
Determines default maximum age of samples.
void addObservation(const ObservationPtr &stat)
Adds a new observation.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
isc::data::ConstElementPtr get(const std::string &name) const
Returns a single statistic as a JSON structure.
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set-all command.
void setMaxSampleCountDefault(uint32_t max_samples)
Set default count limit.
void addObservationInternal(const ObservationPtr &stat)
Adds a new observation in a thread safe context.
void addValueInternal(const std::string &name, DataType value)
Adds specified value to a given statistic (internal version).
static uint32_t getMaxSampleCountDefault()
Get default maximum count of samples.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
void setMaxSampleCountAll(uint32_t max_samples)
Set count limit for all collected statistics.
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get-all command.
bool setMaxSampleAge(const std::string &name, const StatsDuration &duration)
Determines maximum age of samples.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset command.
size_t count() const
Returns number of available statistics.
static StatsMgr & instance()
Statistics Manager accessor method.
Statistics Manager class.
isc::data::ConstElementPtr getAll() const
Returns all statistics as a JSON structure.
void removeAll()
Removes all collected statistics.
std::chrono::system_clock::duration StatsDuration
Defines duration type.
void setMaxSampleAgeAll(const StatsDuration &duration)
Set duration limit for all collected statistics.
size_t getSize(const std::string &name) const
Returns size of specified statistic.
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset-all command.
bool del(const std::string &name)
Removes specified statistic.
static isc::data::ConstElementPtr statisticRemoveAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove-all command.
static isc::data::ConstElementPtr statisticSetMaxSampleCountHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set command.
boost::shared_ptr< const Element > ConstElementPtr
static isc::data::ConstElementPtr statisticRemoveHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove command.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
void resetAll()
Resets all collected statistics back to zero.
Defines the logger used by the top-level component of kea-dhcp-ddns.
static const StatsDuration & getMaxSampleAgeDefault()
Get default maximum age of samples.
bool setMaxSampleCount(const std::string &name, uint32_t max_samples)
Determines how many samples of a given statistic should be kept.
void setValueInternal(const std::string &name, DataType value)
Sets a given statistic to specified value (internal version).
This file contains several functions and constants that are used for handling commands and responses ...
bool reset(const std::string &name)
Resets specified statistic.
static void setMaxSampleCountDefault(uint32_t max_samples)
Determines default maximum count of samples.
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set-all command.
void setMaxSampleAgeDefault(const StatsDuration &duration)
Set default duration limit.
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
uint32_t getMaxSampleCountDefault() const
Get default count limit.
ObservationPtr getObservationInternal(const std::string &name) const
Returns an observation in a thread safe context.
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.