A Stat is an atomic variable that can be used to store counters, averages, time averages, or summations. More...
#include <Stat.h>
Inherits atscppapi::noncopyable.
Public Types | |
enum | SyncType { SYNC_SUM = 0, SYNC_COUNT, SYNC_AVG, SYNC_TIMEAVG } |
The available Stat types. More... | |
Public Member Functions | |
Stat () | |
~Stat () | |
bool | init (std::string name, Stat::SyncType type=SYNC_COUNT, bool persistent=false) |
You must initialize your Stat with a call to this init() method. | |
void | increment (int64_t amount=1) |
This method allows you to increment a stat by a certain amount. | |
void | decrement (int64_t amount=1) |
This method allows you to decrement a stat by a certain amount. | |
int64_t | get () const |
This method returns the current value of the stat. | |
void | set (int64_t value) |
This method sets the value of the stat. |
A Stat is an atomic variable that can be used to store counters, averages, time averages, or summations.
All stats are exposed through the traffic_line program included with Apache Traffic Server. Additionally, if you've enabled HttpStats all Stats you define will be displayed there. Stats can be read via traffic_line -r stat_name.
Stats are very easy to use, here is a simple example of how you can create a counter and increment its value:
Stat stat; stat.init("stat_name"); stat.inc();
A full example is available in examples/stat_example/.
Definition at line 49 of file Stat.h.
The available Stat types.
atscppapi::Stat::Stat | ( | ) |
atscppapi::Stat::~Stat | ( | ) |
void atscppapi::Stat::decrement | ( | int64_t | amount = 1 |
) |
This method allows you to decrement a stat by a certain amount.
amount | the amount to decrement the stat by the default value is 1. |
int64_t atscppapi::Stat::get | ( | ) | const |
This method returns the current value of the stat.
void atscppapi::Stat::increment | ( | int64_t | amount = 1 |
) |
This method allows you to increment a stat by a certain amount.
amount | the amount to increment the stat by the default value is 1. |
bool atscppapi::Stat::init | ( | std::string | name, | |
Stat::SyncType | type = SYNC_COUNT , |
|||
bool | persistent = false | |||
) |
You must initialize your Stat with a call to this init() method.
name | The string name of the stat, this will be visbible via traffic_line -r, or through http stats. | |
type | The SyncType of the Stat, this decides how TrafficServer will treat your inputs. The default value is SYNC_COUNT. | |
persistent | This determines if your Stats will persist, the default value is false. |
void atscppapi::Stat::set | ( | int64_t | value | ) |
This method sets the value of the stat.
value | the value to set the stat to. |