namespace isc {
namespace stats {
-ObservationPtr StatContext::get(const std::string& name) {
- std::map<std::string, ObservationPtr>::iterator obs = stats_.find(name);
+ObservationPtr StatContext::get(const std::string& name) const {
+ std::map<std::string, ObservationPtr>::const_iterator obs = stats_.find(name);
if (obs == stats_.end()) {
return (ObservationPtr());
} else {
}
void StatContext::add(const ObservationPtr& obs) {
- std::map<std::string, ObservationPtr>::iterator obs = stats_.find(name);
- if (obs == stats_.end()) {
+ std::map<std::string, ObservationPtr>::iterator existing = stats_.find(obs->getName());
+ if (existing == stats_.end()) {
stats_.insert(make_pair(obs->getName() ,obs));
} else {
isc_throw(InvalidStatType, "Statistic named " << obs->getName()
/// @brief attempts to get an observation
/// @param name name of the statistic
/// @return appropriate Observation object (or NULL)
- ObservationPtr get(const std::string& name);
+ ObservationPtr get(const std::string& name) const;
/// @brief Adds a new observation
/// @param obs observation to be added
}
}
-IntegerSample Observation::getInteger() {
+IntegerSample Observation::getInteger() const {
return (getValueInternal<IntegerSample>(integer_samples_, STAT_INTEGER));
}
-FloatSample Observation::getFloat() {
+FloatSample Observation::getFloat() const {
return (getValueInternal<FloatSample>(float_samples_, STAT_FLOAT));
}
-DurationSample Observation::getDuration() {
+DurationSample Observation::getDuration() const {
return (getValueInternal<DurationSample>(duration_samples_, STAT_DURATION));
}
-StringSample Observation::getString() {
+StringSample Observation::getString() const {
return (getValueInternal<StringSample>(string_samples_, STAT_STRING));
}
template<typename SampleType, typename Storage>
-SampleType Observation::getValueInternal(Storage& storage, Type exp_type) {
+SampleType Observation::getValueInternal(Storage& storage, Type exp_type) const {
if (type_ != exp_type) {
isc_throw(InvalidStatType, "Invalid statistic type requested: "
<< typeToText(exp_type) << ", but the actual type is "
}
isc::data::ConstElementPtr
-Observation::getJSON() {
+Observation::getJSON() const {
ElementPtr entry = isc::data::Element::createList(); // a single observation
ElementPtr value;
/// @brief Returns observed integer sample
/// @return observed sample (value + timestamp)
/// @throw InvalidStatType if statistic is not integer
- IntegerSample getInteger();
+ IntegerSample getInteger() const;
/// @brief Returns observed float sample
/// @return observed sample (value + timestamp)
/// @throw InvalidStatType if statistic is not fp
- FloatSample getFloat();
+ FloatSample getFloat() const;
/// @brief Returns observed duration sample
/// @return observed sample (value + timestamp)
/// @throw InvalidStatType if statistic is not time duration
- DurationSample getDuration();
+ DurationSample getDuration() const;
/// @brief Returns observed string sample
/// @return observed sample (value + timestamp)
/// @throw InvalidStatType if statistic is not a string
- StringSample getString();
+ StringSample getString() const;
/// @brief Returns as a JSON structure
/// @return JSON structures representing all observations
- isc::data::ConstElementPtr getJSON();
+ isc::data::ConstElementPtr getJSON() const;
/// @brief Converts statistic type to string
/// @return textual name of statistic type
static std::string durationToText(StatsDuration dur);
/// @brief Returns observation name
- std::string getName() {
+ std::string getName() const {
return (name_);
}
/// @throw InvalidStatType if observation type mismatches
/// @return Observed sample
template<typename SampleType, typename Storage>
- SampleType getValueInternal(Storage& storage, Type exp_type);
+ SampleType getValueInternal(Storage& storage, Type exp_type) const;
/// @brief Observation (statistic) name
std::string name_;