2020-08-12 04:10:41 +08:00
# StatsD Input Plugin
2015-09-25 02:06:11 +08:00
2022-06-09 05:22:56 +08:00
The StatsD input plugin gathers metrics from a Statsd server.
2023-03-27 20:12:35 +08:00
## Service Input <!-- @/docs/includes/service_input.md -->
This plugin is a service input. Normal plugins gather metrics determined by the
interval setting. Service plugins start a service to listens and waits for
metrics or events to occur. Service plugins have two key differences from
normal plugins:
1. The global or plugin specific `interval` setting may not apply
2. The CLI options of `--test` , `--test-wait` , and `--once` may not produce
output for this plugin
2022-10-27 03:58:36 +08:00
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
2023-01-12 23:55:21 +08:00
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
2022-10-27 03:58:36 +08:00
2021-11-25 02:50:13 +08:00
## Configuration
2016-02-19 01:08:15 +08:00
2022-05-24 21:49:47 +08:00
```toml @sample .conf
2016-02-19 01:08:15 +08:00
# Statsd Server
[[inputs.statsd]]
2017-10-17 05:18:36 +08:00
## Protocol, must be "tcp", "udp4", "udp6" or "udp" (default=udp)
2017-08-09 02:41:26 +08:00
protocol = "udp"
## MaxTCPConnection - applicable when protocol is set to tcp (default=250)
max_tcp_connections = 250
2018-09-18 02:45:08 +08:00
2018-02-16 12:04:49 +08:00
## Enable TCP keep alive probes (default=false)
tcp_keep_alive = false
## Specifies the keep-alive period for an active network connection.
## Only applies to TCP sockets and will be ignored if tcp_keep_alive is false.
## Defaults to the OS configuration.
# tcp_keep_alive_period = "2h"
2017-08-09 02:41:26 +08:00
2016-02-19 05:26:51 +08:00
## Address and port to host UDP listener on
2016-02-19 01:08:15 +08:00
service_address = ":8125"
2016-12-14 00:34:52 +08:00
## The following configuration options control when telegraf clears it's cache
## of previous values. If set to false, then telegraf will only clear it's
## cache when the daemon is restarted.
## Reset gauges every interval (default=true)
delete_gauges = true
## Reset counters every interval (default=true)
delete_counters = true
## Reset sets every interval (default=true)
delete_sets = true
## Reset timings & histograms every interval (default=true)
2016-02-19 01:08:15 +08:00
delete_timings = true
2016-12-14 00:34:52 +08:00
2023-05-03 01:19:30 +08:00
## Enable aggregation temporality adds temporality=delta or temporality=commulative tag, and
## start_time field, which adds the start time of the metric accumulation.
## You should use this when using OpenTelemetry output.
# enable_aggregation_temporality = false
2019-07-10 07:50:20 +08:00
## Percentiles to calculate for timing & histogram stats.
percentiles = [50.0, 90.0, 99.0, 99.9, 99.95, 100.0]
2016-02-19 01:08:15 +08:00
2016-04-29 03:11:41 +08:00
## separator to use between elements of a statsd metric
metric_separator = "_"
2016-02-19 01:08:15 +08:00
2016-04-29 03:11:41 +08:00
## Parses tags in the datadog statsd format
2016-03-25 06:14:30 +08:00
## http://docs.datadoghq.com/guides/dogstatsd/
2019-05-15 07:20:35 +08:00
## deprecated in 1.10; use datadog_extensions option instead
2016-03-25 05:31:23 +08:00
parse_data_dog_tags = false
2019-05-15 07:20:35 +08:00
## Parses extensions to statsd in the datadog statsd format
## currently supports metrics and datadog tags.
## http://docs.datadoghq.com/guides/dogstatsd/
datadog_extensions = false
2021-02-17 01:50:01 +08:00
## Parses distributions metric as specified in the datadog statsd format
## https://docs.datadoghq.com/developers/metrics/types/?tab=distribution#definition
datadog_distributions = false
2016-02-19 05:26:51 +08:00
## Statsd data translation templates, more info can be read here:
2018-09-18 02:45:08 +08:00
## https://github.com/influxdata/telegraf/blob/master/docs/TEMPLATE_PATTERN.md
2016-02-19 01:08:15 +08:00
# templates = [
# "cpu.* measurement*"
# ]
2016-02-19 05:26:51 +08:00
## Number of UDP messages allowed to queue up, once filled,
## the statsd server will start dropping packets
2016-02-19 01:08:15 +08:00
allowed_pending_messages = 10000
2023-02-18 04:46:23 +08:00
## Number of worker threads used to parse the incoming messages.
# number_workers_threads = 5
2016-02-19 05:26:51 +08:00
## Number of timing/histogram values to track per-measurement in the
## calculation of percentiles. Raising this limit increases the accuracy
## of percentiles but also increases the memory usage and cpu time.
2016-02-19 01:08:15 +08:00
percentile_limit = 1000
2018-08-28 05:47:04 +08:00
## Maximum socket buffer size in bytes, once the buffer fills up, metrics
## will start dropping. Defaults to the OS default.
# read_buffer_size = 65535
2020-12-05 03:39:00 +08:00
## Max duration (TTL) for each metric to stay cached/reported without being updated.
# max_ttl = "10h"
2022-03-02 06:01:08 +08:00
## Sanitize name method
## By default, telegraf will pass names directly as they are received.
## However, upstream statsd now does sanitization of names which can be
## enabled by using the "upstream" method option. This option will a) replace
## white space with '_', replace '/' with '-', and remove charachters not
## matching 'a-zA-Z_\-0-9\.;='.
#sanitize_name_method = ""
2023-12-06 01:03:05 +08:00
## Replace dots (.) with underscore (_) and dashes (-) with
## double underscore (__) in metric names.
# convert_names = false
2016-02-19 01:08:15 +08:00
```
2021-11-25 02:50:13 +08:00
## Description
2015-09-25 02:06:11 +08:00
The statsd plugin is a special type of plugin which runs a backgrounded statsd
listener service while telegraf is running.
The format of the statsd messages was based on the format described in the
2022-06-09 05:22:56 +08:00
original [etsy
statsd](https://github.com/etsy/statsd/blob/master/docs/metric_types.md)
2015-09-25 02:06:11 +08:00
implementation. In short, the telegraf statsd listener will accept:
- Gauges
2021-11-25 02:50:13 +08:00
- `users.current.den001.myapp:32|g` < - standard
- `users.current.den001.myapp:+10|g` < - additive
- `users.current.den001.myapp:-10|g`
2015-09-25 02:06:11 +08:00
- Counters
2021-11-25 02:50:13 +08:00
- `deploys.test.myservice:1|c` < - increments by 1
- `deploys.test.myservice:101|c` < - increments by 101
- `deploys.test.myservice:1|c|@0.1` < - with sample rate , increments by 10
2015-09-25 02:06:11 +08:00
- Sets
2021-11-25 02:50:13 +08:00
- `users.unique:101|s`
- `users.unique:101|s`
- `users.unique:102|s` < - would result in a count of 2 for `users.unique`
2015-10-08 06:11:52 +08:00
- Timings & Histograms
2021-11-25 02:50:13 +08:00
- `load.time:320|ms`
- `load.time.nanoseconds:1|h`
- `load.time:200|ms|@0.1` < - sampled 1 / 10 of the time
2021-02-17 01:50:01 +08:00
- Distributions
2021-11-25 02:50:13 +08:00
- `load.time:320|d`
- `load.time.nanoseconds:1|d`
- `load.time:200|d|@0.1` < - sampled 1 / 10 of the time
2015-10-08 06:11:52 +08:00
2015-11-08 18:19:00 +08:00
It is possible to omit repetitive names and merge individual stats into a
single line by separating them with additional colons:
2021-11-25 02:50:13 +08:00
- `users.current.den001.myapp:32|g:+10|g:-10|g`
- `deploys.test.myservice:1|c:101|c:1|c|@0.1`
- `users.unique:101|s:101|s:102|s`
- `load.time:320|ms:200|ms|@0.1`
2015-11-08 18:19:00 +08:00
This also allows for mixed types in a single line:
2021-11-25 02:50:13 +08:00
- `foo:1|c:200|ms`
2015-11-08 18:19:00 +08:00
The string `foo:1|c:200|ms` is internally split into two individual metrics
`foo:1|c` and `foo:200|ms` which are added to the aggregator separately.
2021-11-25 02:50:13 +08:00
## Influx Statsd
2015-10-08 06:11:52 +08:00
In order to take advantage of InfluxDB's tagging system, we have made a couple
additions to the standard statsd protocol. First, you can specify
tags in a manner similar to the line-protocol, like this:
2021-11-25 02:50:13 +08:00
```shell
2015-10-08 06:11:52 +08:00
users.current,service=payroll,region=us-west:32|g
```
<!-- TODO Second, you can specify multiple fields within a measurement:
```
current.users,service=payroll,server=host01:west=10,east=10,central=2,south=10|g
2022-06-09 05:22:56 +08:00
```
-->
2015-10-08 06:11:52 +08:00
2022-06-09 05:22:56 +08:00
## Metrics
2015-10-08 06:11:52 +08:00
Meta:
2021-11-25 02:50:13 +08:00
2015-10-08 06:11:52 +08:00
- tags: `metric_type=<gauge|set|counter|timing|histogram>`
Outputted measurements will depend entirely on the measurements that the user
sends, but here is a brief rundown of what you can expect to find from each
metric type:
- Gauges
2021-11-25 02:50:13 +08:00
- Gauges are a constant data type. They are not subject to averaging, and they
2015-10-08 06:11:52 +08:00
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.
- Counters
2021-11-25 02:50:13 +08:00
- Counters are the most basic type. They are treated as a count of a type of
2015-10-08 06:11:52 +08:00
event. They will continually increase unless you set `delete_counters=true` .
- Sets
2021-11-25 02:50:13 +08:00
- Sets count the number of unique values passed to a key. For example, you
2015-10-08 06:11:52 +08:00
could count the number of users accessing your system using `users:<user_id>|s` .
No matter how many times the same user_id is sent, the count will only increase
by 1.
- Timings & Histograms
2021-11-25 02:50:13 +08:00
- Timers are meant to track how long something took. They are an invaluable
2015-10-08 06:11:52 +08:00
tool for tracking application performance.
2021-11-25 02:50:13 +08:00
- The following aggregate measurements are made for timers:
- `statsd_<name>_lower` : The lower bound is the lowest value statsd saw
2015-10-08 06:11:52 +08:00
for that stat during that interval.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_upper` : The upper bound is the highest value statsd saw
2015-10-08 06:11:52 +08:00
for that stat during that interval.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_mean` : The mean is the average of all values statsd saw
2015-10-08 06:11:52 +08:00
for that stat during that interval.
2022-07-22 21:52:11 +08:00
- `statsd_<name>_median` : The median is the middle of all values statsd saw
for that stat during that interval.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_stddev` : The stddev is the sample standard deviation
2015-10-08 06:11:52 +08:00
of all values statsd saw for that stat during that interval.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_sum` : The sum is the sample sum of all values statsd saw
2017-09-15 06:21:54 +08:00
for that stat during that interval.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_count` : The count is the number of timings statsd saw
2015-10-08 06:11:52 +08:00
for that stat during that interval. It is not averaged.
2021-11-25 02:50:13 +08:00
- `statsd_<name>_percentile_<P>` The `Pth` percentile is a value x such
2015-10-08 06:11:52 +08:00
that `P%` of all the values statsd saw for that stat during that time
period are below x. The most common value that people use for `P` is the
`90` , this is a great number to try to optimize.
2021-02-17 01:50:01 +08:00
- Distributions
2021-11-25 02:50:13 +08:00
- The Distribution metric represents the global statistical distribution of a set of values calculated across your entire distributed infrastructure in one time interval. A Distribution can be used to instrument logical objects, like services, independently from the underlying hosts.
- Unlike the Histogram metric type, which aggregates on the Agent during a given time interval, a Distribution metric sends all the raw data during a time interval.
2015-10-08 06:11:52 +08:00
2021-11-25 02:50:13 +08:00
## Plugin arguments
2015-10-08 06:11:52 +08:00
2017-08-09 02:41:26 +08:00
- **protocol** string: Protocol used in listener - tcp or udp options
- **max_tcp_connections** []int: Maximum number of concurrent TCP connections
to allow. Used when protocol is set to tcp.
2018-02-16 12:04:49 +08:00
- **tcp_keep_alive** boolean: Enable TCP keep alive probes
2021-04-10 01:15:04 +08:00
- **tcp_keep_alive_period** duration: Specifies the keep-alive period for an active network connection
2015-10-08 06:11:52 +08:00
- **service_address** string: Address to listen for statsd UDP packets on
- **delete_gauges** boolean: Delete gauges on every collection interval
- **delete_counters** boolean: Delete counters on every collection interval
- **delete_sets** boolean: Delete set counters on every collection interval
- **delete_timings** boolean: Delete timings on every collection interval
- **percentiles** []int: Percentiles to calculate for timing & histogram stats
- **allowed_pending_messages** integer: Number of messages allowed to queue up
waiting to be processed. When this fills, messages will be dropped and logged.
- **percentile_limit** integer: Number of timing/histogram values to track
per-measurement in the calculation of percentiles. Raising this limit increases
the accuracy of percentiles but also increases the memory usage and cpu time.
- **templates** []string: Templates for transforming statsd buckets into influx
measurements and tags.
2021-11-25 02:50:13 +08:00
- **parse_data_dog_tags** boolean: Enable parsing of tags in DataDog's dogstatsd format (< http: // docs . datadoghq . com / guides / dogstatsd /> )
- **datadog_extensions** boolean: Enable parsing of DataDog's extensions to dogstatsd format (< http: // docs . datadoghq . com / guides / dogstatsd /> )
- **datadog_distributions** boolean: Enable parsing of the Distribution metric in DataDog's dogstatsd format (< https: // docs . datadoghq . com / developers / metrics / types /? tab = distribution#definition > )
2020-12-05 03:39:00 +08:00
- **max_ttl** config.Duration: Max duration (TTL) for each metric to stay cached/reported without being updated.
2015-10-08 06:11:52 +08:00
2021-11-25 02:50:13 +08:00
## Statsd bucket -> InfluxDB line-protocol Templates
2015-10-08 06:11:52 +08:00
The plugin supports specifying templates for transforming statsd buckets into
InfluxDB measurement names and tags. The templates have a _measurement_ keyword,
which can be used to specify parts of the bucket that are to be used in the
2022-06-09 05:22:56 +08:00
measurement name. Other words in the template are used as tag names. For
example, the following template:
2015-10-08 06:11:52 +08:00
2021-11-25 02:50:13 +08:00
```toml
2015-10-08 06:11:52 +08:00
templates = [
"measurement.measurement.region"
]
```
would result in the following transformation:
2021-11-25 02:50:13 +08:00
```shell
2015-10-08 06:11:52 +08:00
cpu.load.us-west:100|g
=> cpu_load,region=us-west 100
```
Users can also filter the template to use based on the name of the bucket,
using glob matching, like so:
2021-11-25 02:50:13 +08:00
```toml
2015-10-08 06:11:52 +08:00
templates = [
"cpu.* measurement.measurement.region",
"mem.* measurement.measurement.host"
]
```
which would result in the following transformation:
2021-11-25 02:50:13 +08:00
```shell
2015-10-08 06:11:52 +08:00
cpu.load.us-west:100|g
=> cpu_load,region=us-west 100
mem.cached.localhost:256|g
=> mem_cached,host=localhost 256
```
2018-09-18 02:45:08 +08:00
Consult the [Template Patterns ](/docs/TEMPLATE_PATTERN.md ) documentation for
additional details.
2023-02-09 18:04:41 +08:00
## Example Output