# &adminguide;

## Overview

The module provides the ability to send commands to statsd (you can use InfluxDB too) with different types of information. It provides native integration with statsd (https://github.com/etsy/statsd/) and graphite (http://graphite.wikidot.com/).

The module does not have any special dependency, it does a direct socket connection to Graphite.

## Parameters

### `ip`(string)

Statsd server IP address.

Defaults to 127.0.0.1

#### Set ip parameter

    ...
    modparam("statsd", "ip", "127.0.0.1")
    ...

### `port`(string)

Statsd server port number

Defaults to 8125

#### Set port parameter

    ...
    modparam("statsd", "port", "8125")
    ...

## Functions

### `statsd_set(key, value)`

Sets count the number of unique values passed to a key.

If this method is called multiple times with the same userid in the same sample period, that userid will only be counted once.

This function can be used in ALL ROUTES.

#### `statsd_set` usage

    ...
    failure_route[tryagain] {
    ...
        statsd_set("customerFailure", 1);
    ...
    }
    ...

### `statsd_gauge(key, value)`

Gauges are a constant data type. They are not subject to averaging and they don't change unless you change them. That is, once you set a gauge value, it will be a flat line on the graph until you change it again.

Gauges are useful for things that are already averaged, or don't need to reset periodically

This function can be used in ALL ROUTES.

The statsd server collects gauges under the stats.gauges prefix.

#### `statsd_gauge` usage

    ...
    route [gauge_method]{
        statsd_gauge("method"+$rm, "+1");
        statsd_gauge("customer_credit"+$var(customer),"$var(customer_credit)");
    }
    ...

### `statsd_histogram(key, value)`

The histograms are a measure of time, but they are calculated at the server side. As the data exported by the client is the same, this is just an alias for the Timer type.

This function can be used in ALL ROUTES.

The statsd server collects histograms under the stats.histograms prefix.

#### `statsd_histogram` usage

    ...
        statsd_histogram("latency", 1000);
    ...

### `statsd_start(key)`

statsd_start set an avp with the key name, and when statsd_stop(key) is used, the module will send statsd the difference in milliseconds. This is useful to know the time of a SQL query, or how much time your replies take.

This function can be used in all routes.

The statsd server collects all timers under the stats.timers prefix and will calculate the lower bound, mean, 90th percentile, upper bound, and count of each timer for each period (by the time it can be seen in graphite, that's usually per minute).

#### `statsd_start` usage

    ...
    statsd_start("long_mysql_query");
    sql_query("ca", "select sleep(0.2)", "ra");
    statsd_stop("long_mysql_query");
    ...

### `statsd_stop(key)`

statsd_stop(key) get the avp string with the key and calculate the difference from the start time. When finished the milliseconds used will be sent to statsd.

This function can be used in all routes.

#### `statsd_stop` usage

    ...
    statsd_start("long_mysql_query");
    sql_query("ca", "select sleep(0.2)", "ra");
    statsd_stop("long_mysql_query");
    ...

### `statsd_incr(key)`

Increment a statsd counter

This function can be used in all routes.

#### `statsd_incr` usage

    ...
    if(geoip_match("$si", "src")){
        statsd_incr("country."+$(gip(src=>cc)));
    }
    ...

### `statsd_decr(key)`

Decrement a counter

This function can be used in all routes.

#### `statsd_decr` usage

    ...
    if (t_check_status("408")) {
        statsd_decr("kamailio.successfulCalls");
        statsd_incr("kamailio.reply.timeout");
    }
    ...