2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#1005] Checkpoint: updated stats lib

This commit is contained in:
Francis Dupont
2020-04-05 13:22:19 +02:00
parent 08f8f89dfc
commit a4dc3db6b3
10 changed files with 338 additions and 117 deletions

View File

@@ -515,6 +515,14 @@
// information) with each lease.
"store-extended-info": true,
// Statistics keep some samples per observation point.
// There are two default values: maximum count and maximum age.
// Set the maximum count to zero disables it.
"statistic-default-sample-count": 0,
// When the maximum count the maximum age (in seconds) applies.
"statistic-default-sample-age": 60,
// Governs how the Kea DHCPv4 server should deal with the invalid
// data received from the client.
"sanity-checks": {

View File

@@ -456,6 +456,14 @@
// information) with each lease.
"store-extended-info": true,
// Statistics keep some samples per observation point.
// There are two default values: maximum count and maximum age.
// Set the maximum count to zero disables it.
"statistic-default-sample-count": 0,
// When the maximum count the maximum age (in seconds) applies.
"statistic-default-sample-age": 60,
// Governs how the Kea DHCPv6 server should deal with the invalid
// data received from the client.
"sanity-checks": {

View File

@@ -576,7 +576,9 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
(config_pair.first == "ddns-replace-client-name") ||
(config_pair.first == "ddns-generated-prefix") ||
(config_pair.first == "ddns-qualifying-suffix") ||
(config_pair.first == "store-extended-info")) {
(config_pair.first == "store-extended-info") ||
(config_pair.first == "statistic-default-sample-count") ||
(config_pair.first == "statistic-default-sample-age")) {
CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
config_pair.second);
continue;

View File

@@ -695,7 +695,9 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
(config_pair.first == "ddns-replace-client-name") ||
(config_pair.first == "ddns-generated-prefix") ||
(config_pair.first == "ddns-qualifying-suffix") ||
(config_pair.first == "store-extended-info")) {
(config_pair.first == "store-extended-info") ||
(config_pair.first == "statistic-default-sample-count") ||
(config_pair.first == "statistic-default-sample-age")) {
CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
config_pair.second);
continue;

View File

@@ -83,7 +83,9 @@ const SimpleKeywords SimpleParser4::GLOBAL4_PARAMETERS = {
{ "ddns-replace-client-name", Element::string },
{ "ddns-generated-prefix", Element::string },
{ "ddns-qualifying-suffix", Element::string },
{ "store-extended-info", Element::boolean }
{ "store-extended-info", Element::boolean },
{ "statistic-default-sample-count", Element::integer },
{ "statistic-default-sample-age", Element::integer }
};
/// @brief This table defines default global values for DHCPv4
@@ -114,7 +116,9 @@ const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = {
{ "ddns-qualifying-suffix", Element::string, "" },
{ "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
{ "hostname-char-replacement", Element::string, "" },
{ "store-extended-info", Element::boolean, "false" }
{ "store-extended-info", Element::boolean, "false" },
{ "statistic-default-sample-count", Element::integer, "20" },
{ "statistic-default-sample-age", Element::integer, "0" }
};
/// @brief This table defines all option definition parameters.

View File

@@ -83,7 +83,9 @@ const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = {
{ "ddns-replace-client-name", Element::string },
{ "ddns-generated-prefix", Element::string },
{ "ddns-qualifying-suffix", Element::string },
{ "store-extended-info", Element::boolean }
{ "store-extended-info", Element::boolean },
{ "statistic-default-sample-count", Element::integer },
{ "statistic-default-sample-age", Element::integer }
};
/// @brief This table defines default global values for DHCPv6
@@ -109,8 +111,9 @@ const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
{ "ddns-qualifying-suffix", Element::string, "" },
{ "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
{ "hostname-char-replacement", Element::string, "" },
{ "store-extended-info", Element::boolean, "false" }
{ "store-extended-info", Element::boolean, "false" },
{ "statistic-default-sample-count", Element::integer, "20" },
{ "statistic-default-sample-age", Element::integer, "0" }
};
/// @brief This table defines all option definition parameters.

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2020 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
@@ -20,23 +20,38 @@ using namespace boost::posix_time;
namespace isc {
namespace stats {
std::pair<bool, uint32_t>
Observation::default_max_sample_count_ = std::make_pair(true, 20);
std::pair<bool, StatsDuration>
Observation::default_max_sample_age_ =
std::make_pair(false, time_duration(0, 0, 0, 0));
Observation::Observation(const std::string& name, const int64_t value) :
name_(name), type_(STAT_INTEGER) {
name_(name), type_(STAT_INTEGER),
max_sample_count_(default_max_sample_count_),
max_sample_age_(default_max_sample_age_) {
setValue(value);
}
Observation::Observation(const std::string& name, const double value) :
name_(name), type_(STAT_FLOAT) {
name_(name), type_(STAT_FLOAT),
max_sample_count_(default_max_sample_count_),
max_sample_age_(default_max_sample_age_) {
setValue(value);
}
Observation::Observation(const std::string& name, const StatsDuration& value) :
name_(name), type_(STAT_DURATION) {
name_(name), type_(STAT_DURATION),
max_sample_count_(default_max_sample_count_),
max_sample_age_(default_max_sample_age_) {
setValue(value);
}
Observation::Observation(const std::string& name, const std::string& value) :
name_(name), type_(STAT_STRING) {
name_(name), type_(STAT_STRING),
max_sample_count_(default_max_sample_count_),
max_sample_age_(default_max_sample_age_) {
setValue(value);
}
@@ -306,6 +321,7 @@ void Observation::setMaxSampleCountInternal(StorageType& storage,
<< typeToText(exp_type) << ", but the actual type is "
<< typeToText(type_));
}
// Should we refuse the max_samples = 0 value here?
// setting new value of max_sample_count_
max_sample_count_.first = true;
max_sample_count_.second = max_samples;
@@ -318,6 +334,37 @@ void Observation::setMaxSampleCountInternal(StorageType& storage,
}
}
void Observation::setMaxSampleAgeDefault(const StatsDuration& duration) {
// setting new value of default_max_sample_age_
default_max_sample_age_.second = duration;
}
void Observation::setMaxSampleCountDefault(uint32_t max_samples) {
if (max_samples == 0) {
// deactivating the default_max_sample_count_ limit
default_max_sample_count_.first = false;
default_max_sample_age_.first = true;
} else {
// setting new value of default_max_sample_count_
default_max_sample_count_.second = max_samples;
// deactivating the default_max_sample_age_ limit
default_max_sample_age_.first = false;
default_max_sample_count_.first = true;
}
}
const StatsDuration& Observation::getMaxSampleAgeDefault() {
return (default_max_sample_age_.second);
}
uint32_t Observation::getMaxSampleCountDefault() {
if (default_max_sample_count_.first) {
return (default_max_sample_count_.second);
} else {
return (0);
}
}
std::string Observation::typeToText(Type type) {
std::stringstream tmp;
switch (type) {
@@ -456,5 +503,5 @@ void Observation::reset() {
};
}
};
};
} // end of namespace stats
} // end of namespace isc

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2020 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
@@ -140,6 +140,30 @@ class Observation {
/// setMaxSampleCount(100);
void setMaxSampleCount(uint32_t max_samples);
/// @brief Determines default maximum age of samples.
///
/// @param duration determines default maximum age of samples.
static void setMaxSampleAgeDefault(const StatsDuration& duration);
/// @brief Determines default maximum count of samples.
///
/// @param max_samples default maximum count of samples to keep.
/// (0 means to disable count limit and enable age limit)
static void setMaxSampleCountDefault(uint32_t max_samples);
/// @brief Get default maximum age of samples.
///
/// @return default maximum age of samples.
static const StatsDuration& getMaxSampleAgeDefault();
/// @brief Get default maximum count of samples.
///
/// @return max_samples default maximum count of samples to keep.
/// (0 means that count limit was disabled)
static uint32_t getMaxSampleCountDefault();
/// @
/// @brief Records absolute integer observation
///
/// @param value integer value observed
@@ -354,9 +378,13 @@ private:
/// The bool value informs which limit
/// is available
/// True means active limit, false means inactive limit
std::pair<bool, uint32_t> max_sample_count_;
/// @brief Default maximum number of samples
///
/// By default the MaxSampleCount is set to 20
/// and MaxSampleAge is disabled
std::pair<bool, uint32_t> max_sample_count_ = std::make_pair(true, 20);
static std::pair<bool, uint32_t> default_max_sample_count_;
/// @brief Maximum timespan of samples
/// The limit is represented as a pair
@@ -365,10 +393,13 @@ private:
/// The bool value informs which limit
/// is available
/// True means active limit, false means inactive limit
std::pair<bool, StatsDuration> max_sample_age_;
/// @brief Default maximum timespan of samples
///
/// By default the MaxSampleCount is set to 20
/// and MaxSampleAge is disabled
std::pair<bool, StatsDuration> max_sample_age_ = std::make_pair(false,
boost::posix_time::time_duration(0, 0, 0, 0));
static std::pair<bool, StatsDuration> default_max_sample_age_;
/// @defgroup samples_storage Storage for supported observations
///

View File

@@ -236,6 +236,66 @@ StatsMgr::setMaxSampleCountAllInternal(uint32_t max_samples) {
global_->setMaxSampleCountAll(max_samples);
}
void
StatsMgr::setMaxSampleAgeDefault(const StatsDuration& duration) {
if (MultiThreadingMgr::instance().getMode()) {
lock_guard<mutex> lock(*mutex_);
setMaxSampleAgeDefaultInternal(duration);
} else {
setMaxSampleAgeDefaultInternal(duration);
}
}
void
StatsMgr::setMaxSampleAgeDefaultInternal(const StatsDuration& duration) {
Observation::setMaxSampleAgeDefault(duration);
}
void
StatsMgr::setMaxSampleCountDefault(uint32_t max_samples) {
if (MultiThreadingMgr::instance().getMode()) {
lock_guard<mutex> lock(*mutex_);
setMaxSampleCountDefaultInternal(max_samples);
} else {
setMaxSampleCountDefaultInternal(max_samples);
}
}
void
StatsMgr::setMaxSampleCountDefaultInternal(uint32_t max_samples) {
Observation::setMaxSampleCountDefault(max_samples);
}
const StatsDuration&
StatsMgr::getMaxSampleAgeDefault() const {
if (MultiThreadingMgr::instance().getMode()) {
lock_guard<mutex> lock(*mutex_);
return (getMaxSampleAgeDefaultInternal());
} else {
return (getMaxSampleAgeDefaultInternal());
}
}
const StatsDuration&
StatsMgr::getMaxSampleAgeDefaultInternal() const {
return (Observation::getMaxSampleAgeDefault());
}
uint32_t
StatsMgr::getMaxSampleCountDefault() const {
if (MultiThreadingMgr::instance().getMode()) {
lock_guard<mutex> lock(*mutex_);
return (getMaxSampleCountDefaultInternal());
} else {
return (getMaxSampleCountDefaultInternal());
}
}
uint32_t
StatsMgr::getMaxSampleCountDefaultInternal() const {
return (Observation::getMaxSampleCountDefault());
}
bool
StatsMgr::reset(const string& name) {
if (MultiThreadingMgr::instance().getMode()) {

View File

@@ -170,6 +170,28 @@ public:
/// @param max_samples how many samples of a given statistic should be kept
void setMaxSampleCountAll(uint32_t max_samples);
/// @brief Set default duration limit.
///
/// @param duration determines default maximum age of samples
void setMaxSampleAgeDefault(const StatsDuration& duration);
/// @brief Set default count limit.
///
/// @param max_samples default maximum number of samples to keep
/// (0 means to disable count limit and enable age limit)
void setMaxSampleCountDefault(uint32_t max_samples);
/// @brief Get default duration limit.
///
/// @return default maximum age of samples.
const StatsDuration& getMaxSampleAgeDefault() const;
/// @brief Get default count limit.
///
/// @return default maximum number of samples to keep.
/// (0 means that count limit was disabled)
uint32_t getMaxSampleCountDefault() const;
/// @}
/// @defgroup consumer_methods Methods are used by data consumers.
@@ -589,6 +611,40 @@ private:
/// @private
/// @brief Set default duration limit.
///
/// Should be called in a thread safe context.
///
/// @param duration determines default maximum age of samples
void setMaxSampleAgeDefaultInternal(const StatsDuration& duration);
/// @brief Set default count limit.
///
/// Should be called in a thread safe context.
///
/// @param max_samples default maximum number of samples to keep
/// (0 means to disable count limit and enable age limit)
void setMaxSampleCountDefaultInternal(uint32_t max_samples);
/// @private
/// @brief Get default duration limit.
///
/// Should be called in a thread safe context.
///
/// @return default maximum age of samples.
const StatsDuration& getMaxSampleAgeDefaultInternal() const;
/// @brief Get default count limit.
///
/// Should be called in a thread safe context.
///
/// @return default maximum number of samples to keep.
/// (0 means that count limit was disabled)
uint32_t getMaxSampleCountDefaultInternal() const;
/// @private
/// @brief Resets specified statistic.
///
/// Should be called in a thread safe context.