LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Private Attributes | Friends
LogCabin::Core::RollingStat Class Reference

This class gathers statistics about a given metric over time, like its average, standard deviation, and exponentially weighted moving average. More...

#include <RollingStat.h>

List of all members.

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.

Detailed Description

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.


Member Typedef Documentation

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 & Destructor Documentation

Constructor.

Definition at line 25 of file RollingStat.cc.

Destructor.

Definition at line 39 of file RollingStat.cc.


Member Function Documentation

Return mean, or 0 if no values reported.

Definition at line 44 of file RollingStat.cc.

Return number of values reported.

Definition at line 52 of file RollingStat.cc.

Return exponentially weighted moving average with alpha of 0.5, or 0 if no values reported.

Definition at line 58 of file RollingStat.cc.

Return exponentially weighted moving average with alpha of 0.25, or 0 if no values reported.

Definition at line 64 of file RollingStat.cc.

Return total number of exceptional values reported.

Definition at line 70 of file RollingStat.cc.

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.

Return the smallest value reported, or 0 if no values reported.

Definition at line 90 of file RollingStat.cc.

Return the largest value reported, or 0 if no values reported.

Definition at line 96 of file RollingStat.cc.

Return the cumulative total of all values reported, or 0 if no values reported.

Definition at line 102 of file RollingStat.cc.

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.

Parameters:
whenThe time the exceptional situation occurred (by convention, this is usually its start time).
valueThe 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.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const RollingStat stat 
) [friend]

Print all the stats.

Definition at line 180 of file RollingStat.cc.


Member Data Documentation

Definition at line 143 of file RollingStat.h.

Definition at line 144 of file RollingStat.h.

Definition at line 145 of file RollingStat.h.

Definition at line 146 of file RollingStat.h.

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.

Definition at line 149 of file RollingStat.h.

Definition at line 150 of file RollingStat.h.

Definition at line 151 of file RollingStat.h.

Used to calculate standard deviation.

sum of x times x over all values.

Definition at line 155 of file RollingStat.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines