Public Types | Public Member Functions

atscppapi::Stat Class Reference

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.

Collaboration diagram for atscppapi::Stat:
Collaboration graph
[legend]

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.

Detailed Description

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.


Member Enumeration Documentation

The available Stat types.

Enumerator:
SYNC_SUM 

The stat will sum all values from a stat.inc(VAL).

SYNC_COUNT 

The stat will count all calls to stat.inc(VAL).

SYNC_AVG 

The stat will keep an average after call calls to stat.inc(VAL).

SYNC_TIMEAVG 

The stat will keep a time average of all calls to stat.inc(VAL).

Definition at line 54 of file Stat.h.


Constructor & Destructor Documentation

atscppapi::Stat::Stat (  ) 
atscppapi::Stat::~Stat (  ) 

Member Function Documentation

void atscppapi::Stat::decrement ( int64_t  amount = 1  ) 

This method allows you to decrement a stat by a certain amount.

Parameters:
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.

Returns:
The value of the stat.
void atscppapi::Stat::increment ( int64_t  amount = 1  ) 

This method allows you to increment a stat by a certain amount.

Parameters:
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.

Parameters:
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.
Returns:
True if the stat was successfully created and false otherwise.
See also:
SyncType
void atscppapi::Stat::set ( int64_t  value  ) 

This method sets the value of the stat.

Parameters:
value the value to set the stat to.

The documentation for this class was generated from the following file: