Plugin Statistics

A plugin can create statistics (metrics) that are accessible in the same way as Traffic Server core statistics. In general monitoring the behavior of plugins in production is easier to do in this way in contrast to processing log files.

Note

These APIs are deprecated as of ATS v10.0.0, and will likely be removed in v11. Instead, use the new APIs in Metrics.h diretly.

Synopsis

#include <ts/ts.h>
int TSStatCreate(const char *name, TSRecordDataType type, TSStatPersistence persistence, TSStatSync sync_style)
TSReturnCode TSStatFindName(const char *name, int *idx_ptr)
TSMgmtInt TSStatIntGet(int idx)
void TSStatIntSet(int idx, TSMgmtInt value)
void TSStatIntIncrement(int idx, TSMgmtInt value)
void TSStatIntDecrement(int idx, TSMgmtInt value)
typedef void (*TSRecordDumpCb)(TSRecordType *type, void *edata, int registered, const char *name, TSRecordDataType type, TSRecordData *datum)
void TSRecordDump(TSRecordType rect_type, TSRecordDumpCb callback, void *edata)

Description

A plugin statistic is created by TSStatCreate(). The name must be globally unique and should follow the standard dotted tag form. To avoid collisions and for easy of use the first tag should be the plugin name or something easily derived from it. Currently only integers are supported therefore type must be TS_RECORDDATATYPE_INT. The return value is the index of the statistic. In general this should work but if it doesn’t it will assert. In particular, creating the same statistic twice will fail in this way, which can happen if statistics are created as part of or based on configuration files and Traffic Server is reloaded.

TSStatFindName() locates a statistic by name. If found the function returns TS_SUCCESS and the value pointed at by idx_ptr is updated to be the index of the statistic. Otherwise it returns TS_ERROR.

The values in statistics are manipulated by TSStatIntSet() to set the statistic directly, TSStatIntIncrement() to increase it by value, and TSStatIntDecrement() to decrease it by value.

A group of records can be examined via TSRecordDump(). A set of records is specified and the iterated over. For each record in the set the callbac callback is invoked.

The records are specified by the TSRecordType. If this is TS_RECORDTYPE_NULL then all records are examined. The callback is passed

type

The record type.

edata

Callback context. This is the edata value passed to TSRecordDump().

registered

A flag indicating if the value has been registered.

name

The name of the record. This is nul terminated.

type

The storage type of the data in the record.

datum

The record data.

Return Values

TSMgmtStringCreate() and TSMgmtIntCreate() return TS_SUCCESS if the management value was created and TS_ERROR if not.

See Also

Adding Statistics TSAPI(3ts)