LogCabin
|
This class gathers statistics about a given metric over time, like its average, standard deviation, and exponentially weighted moving average. More...
#include <RollingStat.h>
Public Types | |
typedef Core::Time::SteadyClock | Clock |
Clock used for exceptional values. | |
typedef Clock::time_point | TimePoint |
Time point used for exceptional values. | |
Public Member Functions | |
RollingStat () | |
Constructor. | |
~RollingStat () | |
Destructor. | |
double | getAverage () const |
Return mean, or 0 if no values reported. | |
uint64_t | getCount () const |
Return number of values reported. | |
double | getEWMA2 () const |
Return exponentially weighted moving average with alpha of 0.5, or 0 if no values reported. | |
double | getEWMA4 () const |
Return exponentially weighted moving average with alpha of 0.25, or 0 if no values reported. | |
uint64_t | getExceptionalCount () const |
Return total number of exceptional values reported. | |
uint64_t | getLast () const |
Return last value reported, or 0 if no values reported. | |
std::vector< std::pair < TimePoint, uint64_t > > | getLastExceptional () const |
Return up to the last 5 exceptional values reported, newest first. | |
uint64_t | getMin () const |
Return the smallest value reported, or 0 if no values reported. | |
uint64_t | getMax () const |
Return the largest value reported, or 0 if no values reported. | |
uint64_t | getSum () const |
Return the cumulative total of all values reported, or 0 if no values reported. | |
double | getStdDev () const |
Return the standard deviation of all values reported, or 0 if no values reported. | |
void | noteExceptional (TimePoint when, uint64_t value) |
Report an exceptional value. | |
void | push (uint64_t value) |
Report a value. | |
void | updateProtoBuf (Protocol::RollingStat &message) const |
Serialize all the stats into the given empty ProtoBuf message. | |
Private Attributes | |
uint64_t | count |
double | ewma2 |
double | ewma4 |
uint64_t | exceptionalCount |
uint64_t | last |
std::deque< std::pair < TimePoint, uint64_t > > | lastExceptional |
uint64_t | max |
uint64_t | min |
uint64_t | sum |
uint64_t | sumSquares |
Used to calculate standard deviation. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const RollingStat &stat) |
Print all the stats. |
This class gathers statistics about a given metric over time, like its average, standard deviation, and exponentially weighted moving average.
This class also keeps track of the last 5 "exceptional" values, typically those that are above some pre-defined threshold.
This currently assumes your metric is a uint64_t. It could probably be abstracted out in some way, but most metrics in LogCabin seem to fit this category.
Definition at line 44 of file RollingStat.h.
Clock used for exceptional values.
Definition at line 49 of file RollingStat.h.
Time point used for exceptional values.
Definition at line 53 of file RollingStat.h.
Constructor.
Definition at line 25 of file RollingStat.cc.
Destructor.
Definition at line 39 of file RollingStat.cc.
double LogCabin::Core::RollingStat::getAverage | ( | ) | const |
Return mean, or 0 if no values reported.
Definition at line 44 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getCount | ( | ) | const |
Return number of values reported.
Definition at line 52 of file RollingStat.cc.
double LogCabin::Core::RollingStat::getEWMA2 | ( | ) | const |
Return exponentially weighted moving average with alpha of 0.5, or 0 if no values reported.
Definition at line 58 of file RollingStat.cc.
double LogCabin::Core::RollingStat::getEWMA4 | ( | ) | const |
Return exponentially weighted moving average with alpha of 0.25, or 0 if no values reported.
Definition at line 64 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getExceptionalCount | ( | ) | const |
Return total number of exceptional values reported.
Definition at line 70 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getLast | ( | ) | const |
Return last value reported, or 0 if no values reported.
Definition at line 84 of file RollingStat.cc.
std::vector< std::pair< RollingStat::TimePoint, uint64_t > > LogCabin::Core::RollingStat::getLastExceptional | ( | ) | const |
Return up to the last 5 exceptional values reported, newest first.
Definition at line 76 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getMin | ( | ) | const |
Return the smallest value reported, or 0 if no values reported.
Definition at line 90 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getMax | ( | ) | const |
Return the largest value reported, or 0 if no values reported.
Definition at line 96 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::getSum | ( | ) | const |
Return the cumulative total of all values reported, or 0 if no values reported.
Definition at line 102 of file RollingStat.cc.
double LogCabin::Core::RollingStat::getStdDev | ( | ) | const |
Return the standard deviation of all values reported, or 0 if no values reported.
Definition at line 108 of file RollingStat.cc.
void LogCabin::Core::RollingStat::noteExceptional | ( | TimePoint | when, |
uint64_t | value | ||
) |
Report an exceptional value.
Note that this does not include a 'push'; you may want to do that separately.
when | The time the exceptional situation occurred (by convention, this is usually its start time). |
value | The exceptional value. |
Definition at line 117 of file RollingStat.cc.
void LogCabin::Core::RollingStat::push | ( | uint64_t | value | ) |
Report a value.
Definition at line 126 of file RollingStat.cc.
void LogCabin::Core::RollingStat::updateProtoBuf | ( | Protocol::RollingStat & | message | ) | const |
Serialize all the stats into the given empty ProtoBuf message.
Definition at line 154 of file RollingStat.cc.
std::ostream& operator<< | ( | std::ostream & | os, |
const RollingStat & | stat | ||
) | [friend] |
Print all the stats.
Definition at line 180 of file RollingStat.cc.
uint64_t LogCabin::Core::RollingStat::count [private] |
Definition at line 143 of file RollingStat.h.
double LogCabin::Core::RollingStat::ewma2 [private] |
Definition at line 144 of file RollingStat.h.
double LogCabin::Core::RollingStat::ewma4 [private] |
Definition at line 145 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::exceptionalCount [private] |
Definition at line 146 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::last [private] |
Definition at line 147 of file RollingStat.h.
std::deque<std::pair<TimePoint, uint64_t> > LogCabin::Core::RollingStat::lastExceptional [private] |
Definition at line 148 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::max [private] |
Definition at line 149 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::min [private] |
Definition at line 150 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::sum [private] |
Definition at line 151 of file RollingStat.h.
uint64_t LogCabin::Core::RollingStat::sumSquares [private] |
Used to calculate standard deviation.
sum of x times x over all values.
Definition at line 155 of file RollingStat.h.