16#include <boost/make_shared.hpp>
21using namespace std::chrono;
109 return (global_->get(name));
126StatsMgr::deleteObservation(
const string& name) {
128 return (deleteObservationInternal(name));
132StatsMgr::deleteObservationInternal(
const string& name) {
135 return (global_->del(name));
141 return (setMaxSampleAgeInternal(name, duration));
145StatsMgr::setMaxSampleAgeInternal(
const string& name,
149 obs->setMaxSampleAge(duration);
158 return (setMaxSampleCountInternal(name, max_samples));
162StatsMgr::setMaxSampleCountInternal(
const string& name,
163 uint32_t max_samples) {
166 obs->setMaxSampleCount(max_samples);
175 setMaxSampleAgeAllInternal(duration);
179StatsMgr::setMaxSampleAgeAllInternal(
const StatsDuration& duration) {
180 global_->setMaxSampleAgeAll(duration);
186 setMaxSampleCountAllInternal(max_samples);
190StatsMgr::setMaxSampleCountAllInternal(uint32_t max_samples) {
191 global_->setMaxSampleCountAll(max_samples);
197 setMaxSampleAgeDefaultInternal(duration);
201StatsMgr::setMaxSampleAgeDefaultInternal(
const StatsDuration& duration) {
208 setMaxSampleCountDefaultInternal(max_samples);
212StatsMgr::setMaxSampleCountDefaultInternal(uint32_t max_samples) {
219 return (getMaxSampleAgeDefaultInternal());
223StatsMgr::getMaxSampleAgeDefaultInternal()
const {
230 return (getMaxSampleCountDefaultInternal());
234StatsMgr::getMaxSampleCountDefaultInternal()
const {
241 return (resetInternal(name));
245StatsMgr::resetInternal(
const string& name) {
257 return (delInternal(name));
261StatsMgr::delInternal(
const string& name) {
262 return (global_->del(name));
272StatsMgr::removeAllInternal() {
279 return (getInternal(name));
283StatsMgr::getInternal(
const string& name)
const {
287 map->set(name, obs->getJSON());
295 return (getAllInternal());
299StatsMgr::getAllInternal()
const {
300 return (global_->getAll());
310StatsMgr::resetAllInternal() {
317 return (getSizeInternal(name));
321StatsMgr::getSizeInternal(
const string& name)
const {
324 return (obs->getSize());
332 return (countInternal());
336StatsMgr::countInternal()
const {
337 return (global_->size());
345 if (!StatsMgr::getStatName(params, name, error)) {
348 if (!StatsMgr::getStatDuration(params, duration, error)) {
353 "Statistic '" + name +
"' duration limit is set."));
356 "No '" + name +
"' statistic found"));
364 uint32_t max_samples;
365 if (!StatsMgr::getStatName(params, name, error)) {
368 if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) {
373 "Statistic '" + name +
"' count limit is set."));
376 "No '" + name +
"' statistic found"));
384 if (!StatsMgr::getStatName(params, name, error)) {
395 if (!StatsMgr::getStatName(params, name, error)) {
400 "Statistic '" + name +
"' reset."));
403 "No '" + name +
"' statistic found"));
411 if (!StatsMgr::getStatName(params, name, error)) {
416 "Statistic '" + name +
"' removed."));
419 "No '" + name +
"' statistic found"));
429 "Warning: statistic-remove-all command is deprecated."
430 " All statistics removed."));
445 "All statistics reset to neutral values."));
452 if (!StatsMgr::getStatDuration(params, duration, error)) {
460 "All statistics duration limit are set."));
466 uint32_t max_samples;
467 if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) {
470 if (max_samples == 0) {
471 error =
"'max-samples' parameter must not be zero";
478 "All statistics count limit are set."));
486 reason =
"Missing mandatory 'name' parameter.";
491 reason =
"Missing mandatory 'name' parameter.";
495 reason =
"'name' parameter expected to be a string.";
498 name = stat_name->stringValue();
507 reason =
"Missing mandatory 'duration' parameter.";
511 if (!stat_duration) {
512 reason =
"Missing mandatory 'duration' parameter.";
515 duration = std::chrono::seconds(stat_duration->intValue());
521 uint32_t& max_samples,
524 reason =
"Missing mandatory 'max-samples' parameter.";
528 if (!stat_max_samples) {
529 reason =
"Missing mandatory 'max-samples' parameter.";
533 reason =
"'max-samples' parameter expected to be an integer.";
536 max_samples = stat_max_samples->intValue();
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static const StatsDuration & getMaxSampleAgeDefault()
Get default maximum age of samples.
static uint32_t getMaxSampleCountDefault()
Get default maximum count of samples.
static void setMaxSampleCountDefault(uint32_t max_samples)
Determines default maximum count of samples.
static void setMaxSampleAgeDefault(const StatsDuration &duration)
Determines default maximum age of samples.
Statistics Manager class.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
ObservationPtr getObservationInternal(const std::string &name) const
Returns an observation in a thread safe context.
static StatsMgr & instance()
Statistics Manager accessor method.
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).
void addObservation(const ObservationPtr &stat)
Adds a new observation.
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 ...
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set-all command.
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset command.
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get-all command.
static isc::data::ConstElementPtr statisticRemoveHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove command.
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get command.
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set-all command.
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset-all command.
static isc::data::ConstElementPtr statisticSetMaxSampleAgeHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set command.
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.
bool reset(const std::string &name)
Resets specified statistic.
void removeAll()
Removes all collected statistics.
void resetAll()
Resets all collected statistics back to zero.
bool del(const std::string &name)
Removes specified statistic.
size_t count() const
Returns number of available statistics.
isc::data::ConstElementPtr getAll() const
Returns all statistics as a JSON structure.
size_t getSize(const std::string &name) const
Returns size of specified statistic.
isc::data::ConstElementPtr get(const std::string &name) const
Returns a single statistic as a JSON structure.
void setMaxSampleCountDefault(uint32_t max_samples)
Set default count limit.
bool setMaxSampleCount(const std::string &name, uint32_t max_samples)
Determines how many samples of a given statistic should be kept.
uint32_t getMaxSampleCountDefault() const
Get default count limit.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
bool setMaxSampleAge(const std::string &name, const StatsDuration &duration)
Determines maximum age of samples.
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
void setMaxSampleAgeAll(const StatsDuration &duration)
Set duration limit for all collected statistics.
void setMaxSampleCountAll(uint32_t max_samples)
Set count limit for all collected statistics.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
void setMaxSampleAgeDefault(const StatsDuration &duration)
Set default duration limit.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Observation > ObservationPtr
Observation pointer.
std::chrono::system_clock::duration StatsDuration
Defines duration type.
boost::multiprecision::checked_int128_t int128_t
Defines the logger used by the top-level component of kea-lfc.
RAII lock object to protect the code in the same scope with a mutex.