Adding Statistics¶
This chapter describes how to add statistics to your plugins. Statistics can be coupled or uncoupled; coupled statistics are quantities that are related and must therefore be updated together. The Traffic Server API statistics functions add your plugin’s statistics to the Traffic Server statistics system. You can view your plugin statistics as you would any other Traffic Server statistic, using Traffic Line (Traffic Server’s command line interface). This chapter contains the following topics:
Uncoupled Statistics¶
A statistic is an object of type TSStat. The value of the statistic is of type TSStatType. The possible TSStatTypes are:
- TSSTAT_TYPE_INT64
- TSSTAT_TYPE_FLOAT
There is no TSSTAT_TYPE_INT32.
To add uncoupled statistics, follow the steps below:
Declare your statistic as a global variable in your plugin. For example:
static TSStat my_statistic;
In TSPluginInit, create new statistics using TSStatCreate. When you create a new statistic, you need to give it an “external” name that the Traffic Server command line interface (Traffic Line) uses to access the statistic. For example:
my_statistic = TSStatCreate ("my.statistic", TSSTAT_TYPE_INT64);
Modify (increment, decrement, or other modification) your statistic in plugin functions.