Home

Traffic Server Software Developers Kit

Chapter 17. Adding Statistics

Table of Contents

Uncoupled Statistics
Coupled Statistics
Example Using redirect-1.c Sample Plugin
Viewing Statistics Using Traffic Line

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 INKStat. The value of the statistic is of type INKStatType. The possible INKStatTypes are:

  • INKSTAT_TYPE_INT64

  • INKSTAT_TYPE_FLOAT

There is no INKSTAT_TYPE_INT32.

To add uncoupled statistics, follow the steps below:

  1. Declare your statistic as a global variable in your plugin. For example:

    static INKStat my_statistic;
  2. In INKPluginInit, create new statistics using INKStatCreate.

    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 = INKStatCreate (“my.statistic”, INKSTAT_TYPE_INT64);
  3. Modify (increment, decrement, or other modification) your statistic in plugin functions.