atscppapi  1.0.9
C++ wrapper for Apache Traffic Server API
 All Classes Files Functions Enumerations Enumerator Macros
Public Types | Public Member Functions | List of all members
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.

Public Types

enum  SyncType { SYNC_SUM = 0, SYNC_COUNT, SYNC_AVG, SYNC_TIMEAVG }
 

Public Member Functions

bool init (std::string name, Stat::SyncType type=SYNC_COUNT, bool persistent=false)
 
void increment (int64_t amount=1)
 
void decrement (int64_t amount=1)
 
int64_t get () const
 
void set (int64_t value)
 

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/.

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)

Member Function Documentation

void Stat::decrement ( int64_t  amount = 1)

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

Parameters
amountthe amount to decrement the stat by the default value is 1.
int64_t Stat::get ( ) const

This method returns the current value of the stat.

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

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

Parameters
amountthe amount to increment the stat by the default value is 1.
bool 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
nameThe string name of the stat, this will be visbible via traffic_line -r, or through http stats.
typeThe SyncType of the Stat, this decides how TrafficServer will treat your inputs. The default value is SYNC_COUNT.
persistentThis 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 Stat::set ( int64_t  value)

This method sets the value of the stat.

Parameters
valuethe value to set the stat to.

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