\"duration\": 1245
}
}",
- "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description."
+ "cmd-comment": "The server will respond with message about successfully set limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description."
}
\"duration\": 1245
}
}",
- "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description."
+ "cmd-comment": "The server will respond with message about successfully set limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description."
}
\"max-samples\": 100
}
}",
- "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description."
+ "cmd-comment": "The server will respond with message about successfully set limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description."
}
\"max-samples\": 100
}
}",
- "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description."
+ "cmd-comment": "The server will respond with message about successfully set limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description."
}
Time series
====================
-Previously, by default, each statistic holded only a single data point. When Kea
-attempted to record a new value, the existing previous value was
-overwritten. That approach has the benefit of taking up little memory and
-it covers most cases reasonably well. However, there may be cases where
-you need to have many data points for some process. For example, some
-processes, such as received packet size, packet processing time or number
-of database queries needed to process a packet, are not cumulative and it
-would be useful to keep many data points, perhaps to do some form of
-statistical analysis afterwards.
+Previously, by default, each statistic held only a single data point. When Kea
+attempted to record a new value, the existing previous value was overwritten.
+That approach has the benefit of taking up little memory and it covers most
+cases reasonably well. However, there may be cases where you need to have many
+data points for some process. For example, some processes, such as received
+packet size, packet processing time or number of database queries needed to
+process a packet, are not cumulative and it would be useful to keep many data
+points, perhaps to do some form of statistical analysis afterwards.
Since Kea 1.6, by default, each statistic holds 20 data points. Setting such
CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all",
boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2));
-
-
}
void ControlledDhcpv4Srv::shutdown() {
CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all");
CommandMgr::instance().deregisterCommand("version-get");
-
} catch (...) {
// Don't want to throw exceptions from the destructor. The server
// is shutting down anyway.
CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age");
CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count");
CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age-all");
- CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all");
+ CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all");
CommandMgr::instance().deregisterCommand("version-get");
} catch (...) {
checkListCommands(rsp, "statistic-set-max-sample-age");
checkListCommands(rsp, "statistic-set-max-sample-age-all");
checkListCommands(rsp, "statistic-set-max-sample-count");
- checkListCommands(rsp, "statistic-set-max-sample-count-all");
+ checkListCommands(rsp, "statistic-set-max-sample-count-all");
}
// Tests if the server returns its configuration using config-get.
/// @return size of storage
size_t getSize() const;
- /// @brief Returns both value of max_sample_age_ of statistic.
+ /// @brief Returns both values of max_sample_age_ of statistic.
///
/// @return max_sample_age_.
std::pair<bool, StatsDuration> getMaxSampleAge() const;
- /// @brief Returns both value of max_sample_count_ of statistic.
+ /// @brief Returns both values of max_sample_count_ of statistic.
///
/// @return max_sample_count_.
std::pair<bool, uint32_t> getMaxSampleCount() const;
if (!getStatDuration(params, duration, error)) {
return (createAnswer(CONTROL_RESULT_ERROR, error));
}
- if (instance().setMaxSampleAge(name, duration)) {
+ if (setMaxSampleAge(name, duration)) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + name + "' duration limit is set."));
} else {
if (!getStatMaxSamples(params, max_samples, error)) {
return (createAnswer(CONTROL_RESULT_ERROR, error));
}
- if (instance().setMaxSampleCount(name, max_samples)) {
+ if (setMaxSampleCount(name, max_samples)) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + name + "' count limit is set."));
} else {
if (!getStatDuration(params, duration, error)) {
return (createAnswer(CONTROL_RESULT_ERROR, error));
}
- instance().setMaxSampleAgeAll(duration);
+ setMaxSampleAgeAll(duration);
return (createAnswer(CONTROL_RESULT_SUCCESS,
"All statistics duration limit are set."));
}
if (!getStatMaxSamples(params, max_samples, error)) {
return (createAnswer(CONTROL_RESULT_ERROR, error));
}
- instance().setMaxSampleCountAll(max_samples);
+ setMaxSampleCountAll(max_samples);
return (createAnswer(CONTROL_RESULT_SUCCESS,
"All statistics count limit are set."));
}
return (false);
}
- int64_t dur = stat_duration->intValue();
+ int64_t time_duration = stat_duration->intValue();
- int64_t hours = dur/3600;
- dur = dur - hours*3600;
+ int64_t hours = time_duration / 3600;
+ time_duration -= hours * 3600;
- int64_t minutes = dur/60;
- dur = dur - minutes*60;
+ int64_t minutes = time_duration / 60;
+ time_duration -= minutes * 60;
- int64_t seconds = dur;
- duration = boost::posix_time::time_duration(hours,minutes,seconds,0);
+ int64_t seconds = time_duration;
+ duration = boost::posix_time::time_duration(hours, minutes, seconds, 0);
return (true);
}
///
/// Specifies that statistic name should be stored not as single value, but
/// rather as a set of values. In this form, at most max_samples will be kept.
- /// When adding max_samples+1 sample, the oldest sample will be discarded.
+ /// When adding max_samples + 1 sample, the oldest sample will be discarded.
///
///
/// @param name name of the observation
///
/// This method handles statistic-get command, which returns value
/// of a given statistic). It expects one parameter stored in params map:
- /// name: name-of-the-statistic
+ /// name: name of the statistic
///
/// Example params structure:
/// {
///
/// This method handles statistic-reset command, which resets value
/// of a given statistic. It expects one parameter stored in params map:
- /// name: name-of-the-statistic
+ /// name: name of the statistic
///
/// Example params structure:
/// {
///
/// This method handles statistic-reset command, which removes a given
/// statistic completely. It expects one parameter stored in params map:
- /// name: name-of-the-statistic
+ /// name: name of the statistic
///
/// Example params structure:
/// {
/// which set max_sample_age_ limit of a given statistic
/// and leaves max_sample_count_ disabled.
/// It expects two parameters stored in params map:
- /// name: name-of-the-statistic
+ /// name: name of the statistic
/// duration: time limit expressed as a number of seconds
///
/// Example params structure:
/// which set max_sample_count_ limit of a given statistic
/// and leaves max_sample_age_ disabled.
/// It expects two parameters stored in params map:
- /// name: name-of-the-statistic
- /// max-samples: value of max_sample_count_
+ /// name: name of the statistic
+ /// max-samples: count limit
///
/// Example params structure:
/// {
/// @return answer containing information about successfully setup limit of statistic
static isc::data::ConstElementPtr
statisticSetMaxSampleCountHandler(const std::string& name,
- const isc::data::ConstElementPtr& params);
+ const isc::data::ConstElementPtr& params);
/// @brief Handles statistic-get-all command
///
/// @return answer confirming success of this operation
static isc::data::ConstElementPtr
statisticSetMaxSampleAgeAllHandler(const std::string& name,
- const isc::data::ConstElementPtr& params);
+ const isc::data::ConstElementPtr& params);
- /// @brief Handles statistic-set-max-sample-count command
+ /// @brief Handles statistic-set-max-sample-count-all command
///
- /// This method handles statistic-set-max-sample-count command,
+ /// This method handles statistic-set-max-sample-count-all command,
/// which set max_sample_count_ limit of a given statistic
/// and leaves max_sample_age_ disabled.
/// It expects one parameter stored in params map:
- /// max-samples: value of max_sample_count_
+ /// max-samples: count limit
///
/// Example params structure:
/// {
/// "max-samples": 15
/// }
///
- /// @param name name of the command (ignored, should be "statistic-set-max-sample-count")
+ /// @param name name of the command (ignored, should be "statistic-set-max-sample-count-all")
/// @param params structure containing a map that contains "max-samples"
/// @return answer confirming success of this operation
static isc::data::ConstElementPtr
statisticSetMaxSampleCountAllHandler(const std::string& name,
- const isc::data::ConstElementPtr& params);
+ const isc::data::ConstElementPtr& params);
/// @}
///
/// This method attempts to extract count limit for a given statistic
/// from the params structure.
- /// It is expected to be a map that contains 'max_samples' element,
+ /// It is expected to be a map that contains 'max-samples' element,
/// that is of type int. If present as expected, statistic count
/// limit (max_samples) is set and true is returned.
/// If missing or is of incorrect type, the reason is specified in reason
EXPECT_EQ(c.getMaxSampleCount().second, 20);
EXPECT_EQ(d.getMaxSampleCount().second, 20);
- // Change limit to max_sample_age_
- a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3));
+ // change limit to time duration
+ ASSERT_NOT_THROW(a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)));
+ ASSERT_NOT_THROW(b.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)));
+ ASSERT_NOT_THROW(c.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)));
+ ASSERT_NOT_THROW(d.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)));
+
EXPECT_EQ(a.getMaxSampleAge().first, true);
+ EXPECT_EQ(b.getMaxSampleAge().first, true);
+ EXPECT_EQ(c.getMaxSampleAge().first, true);
+ EXPECT_EQ(d.getMaxSampleAge().first, true);
+
EXPECT_EQ(a.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3));
+ EXPECT_EQ(b.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3));
+ EXPECT_EQ(c.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3));
+ EXPECT_EQ(d.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3));
EXPECT_EQ(a.getMaxSampleCount().first, false);
- EXPECT_EQ(a.getMaxSampleCount().second, 20);
+ EXPECT_EQ(b.getMaxSampleCount().first, false);
+ EXPECT_EQ(c.getMaxSampleCount().first, false);
+ EXPECT_EQ(d.getMaxSampleCount().first, false);
+ EXPECT_EQ(a.getMaxSampleCount().second, 20);
+ EXPECT_EQ(b.getMaxSampleCount().second, 20);
+ EXPECT_EQ(c.getMaxSampleCount().second, 20);
+ EXPECT_EQ(d.getMaxSampleCount().second, 20);
}
// Test checks whether timing is reported properly.
StatsMgr::instance().setValue("gamma", time_duration(1, 2, 3, 4));
StatsMgr::instance().setValue("delta", "Lorem ipsum");
- //First, check the setting of time limit to existing statistics
+ // check the setting of time limit to existing statistics
EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeAll(time_duration(0, 0, 1, 0)));
- // Now check if time limit was set properly
+
+ // check if time limit was set properly and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second,
- time_duration(0, 0, 1, 0));
- // and whether count limit is disabled
+ time_duration(0, 0, 1, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second,
- time_duration(0, 0, 1, 0));
-
+ time_duration(0, 0, 1, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second,
- time_duration(0, 0, 1, 0));
-
+ time_duration(0, 0, 1, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second,
- time_duration(0, 0, 1, 0));
-
+ time_duration(0, 0, 1, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false);
- //then, check the setting of count limit to existing statistics
+ // check the setting of count limit to existing statistics
EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountAll(1200));
- // Now check if count limit was set properly
+
+ // check if count limit was set properly and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 1200);
- // and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 1200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 1200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 1200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false);
}
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
- // Now check if time limit was set properly
+ // check if time limit was set properly and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second,
- time_duration(0, 20, 45, 0));
- // and whether count limit is disabled
+ time_duration(0, 20, 45, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false);
}
// - a request with missing statistic name
// - a request for non-existing statistic.
TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) {
-
// Case 1: a request without parameters
ConstElementPtr rsp =
StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", ElementPtr());
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
- // Now check if time limit was set properly
+ // check if time limit was set properly and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second,
- time_duration(1, 2, 45, 0));
- // and whether count limit is disabled
+ time_duration(1, 2, 45, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second,
- time_duration(1, 2, 45, 0));
-
+ time_duration(1, 2, 45, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second,
- time_duration(1, 2, 45, 0));
-
+ time_duration(1, 2, 45, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second,
- time_duration(1, 2, 45, 0));
-
+ time_duration(1, 2, 45, 0));
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false);
}
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
- // Now check if time limit was set properly
+ // check if time limit was set properly and whether duration limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 15);
-
- // and whether duration limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false);
}
-// Test checks if statistic-set-max-sample-age is able to handle:
+// Test checks if statistic-set-max-sample-count is able to handle:
// - a request without parameters
// - a request without max-samples parameter
// - a request with missing statistic name
// - a request for non-existing statistic.
TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) {
-
// Case 1: a request without parameters
ConstElementPtr rsp =
StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", ElementPtr());
int status_code;
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
- // Now check if count limit was set properly
+
+ // check if count limit was set properly and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 200);
- // and whether count limit is disabled
EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true);
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 200);
-
EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false);
}