namespace stats {
ObservationPtr StatContext::get(const std::string& name) const {
- return MultiThreadingMgr::call(mutex_, [&]() {return getInternal(name);});
-}
-
-ObservationPtr StatContext::getInternal(const std::string& name) const {
auto obs = stats_.find(name);
if (obs != stats_.end()) {
return (obs->second);
}
void StatContext::add(const ObservationPtr& obs) {
- MultiThreadingMgr::call(mutex_, [&]() {addInternal(obs);});
-}
-
-void StatContext::addInternal(const ObservationPtr& obs) {
auto existing = stats_.find(obs->getName());
if (existing == stats_.end()) {
stats_.insert(make_pair(obs->getName() ,obs));
}
bool StatContext::del(const std::string& name) {
- return (MultiThreadingMgr::call(mutex_, [&]() {return delInternal(name);}));
-}
-
-bool StatContext::delInternal(const std::string& name) {
auto obs = stats_.find(name);
if (obs != stats_.end()) {
stats_.erase(obs);
}
size_t StatContext::size() {
- return (MultiThreadingMgr::call(mutex_, [&]() {return sizeInternal();}));
-}
-
-size_t StatContext::sizeInternal() {
return (stats_.size());
}
void StatContext::clear() {
- MultiThreadingMgr::call(mutex_, [&]() {clearInternal();});
-}
-
-void StatContext::clearInternal() {
stats_.clear();
}
void StatContext::resetAll() {
- MultiThreadingMgr::call(mutex_, [&]() {resetAllInternal();});
-}
-
-void StatContext::resetAllInternal() {
// Let's iterate over all stored statistics...
for (auto s : stats_) {
// ... and reset each statistic.
}
ConstElementPtr StatContext::getAll() const {
- return (MultiThreadingMgr::call(mutex_, [&]() {return getAllInternal();}));
-}
-
-ConstElementPtr StatContext::getAllInternal() const {
ElementPtr map = Element::createMap(); // a map
// Let's iterate over all stored statistics...
for (auto s : stats_) {
}
void StatContext::setMaxSampleCountAll(uint32_t max_samples) {
- MultiThreadingMgr::call(mutex_, [&]() {setMaxSampleCountAllInternal(max_samples);});
-}
-
-void StatContext::setMaxSampleCountAllInternal(uint32_t max_samples) {
// Let's iterate over all stored statistics...
for (auto s : stats_) {
// ... and set count limit for each statistic.
}
void StatContext::setMaxSampleAgeAll(const StatsDuration& duration) {
- MultiThreadingMgr::call(mutex_, [&]() {setMaxSampleAgeAllInternal(duration);});
-}
-
-void StatContext::setMaxSampleAgeAllInternal(const StatsDuration& duration) {
// Let's iterate over all stored statistics...
for (auto s : stats_) {
// ... and set duration limit for each statistic.
private:
- /// @brief Attempts to get an observation
- ///
- /// @param name name of the statistic
- /// @return appropriate Observation object (or NULL)
- ObservationPtr getInternal(const std::string& name) const;
-
- /// @brief Adds a new observation
- ///
- /// @param obs observation to be added
- /// @throw DuplicateStat if an observation with the same name exists already
- void addInternal(const ObservationPtr& obs);
-
- /// @brief Attempts to delete an observation
- ///
- /// @param name name of the observation to be deleted
- /// @return true if successful, false if no such statistic was found
- bool delInternal(const std::string& name);
-
- /// @brief Returns the number of observations
- ///
- /// @return the number of observations
- size_t sizeInternal();
-
- /// @brief Removes all observations
- void clearInternal();
-
- /// @brief Resets all observations
- void resetAllInternal();
-
- /// @brief Sets max sample count for all observations
- ///
- /// @param max_samples value to be set for all observations
- void setMaxSampleCountAllInternal(uint32_t max_samples);
-
- /// @brief Sets duration for all observations
- ///
- /// @param duration value to be set for all observations
- void setMaxSampleAgeAllInternal(const StatsDuration& duration);
-
- /// @brief Returns a map with all observations
- ///
- /// @return map with all observations
- isc::data::ConstElementPtr getAllInternal() const;
-
/// @brief Statistics container
std::map<std::string, ObservationPtr> stats_;
-
- /// @brief Mutex used to protect internal state
- mutable std::mutex mutex_;
};
/// @brief Pointer to the statistics context