|
1 | 1 | # StatsD input |
2 | 2 |
|
| 3 | +## Overview |
| 4 | + |
3 | 5 | The `statsd input package` spawns a UDP server and listens for metrics in StatsD compatible format. |
4 | 6 | This input can be used to collect metrics from services that send data over the StatsD protocol. To tailor the data you can provide custom mappings and ingest pipelines through Kibana. |
5 | 7 |
|
6 | | -## Metric types |
| 8 | +### Compatibility |
| 9 | + |
| 10 | +#### Metric types |
7 | 11 |
|
8 | 12 | The input supports the following types of metrics: |
9 | 13 |
|
10 | | -**Counter (c)**:: Measurement which accumulates over a period of time until flushed (value set to 0). |
| 14 | +**Counter (c)** |
| 15 | +: Measurement which accumulates over period of time until flushed (value set to 0). |
| 16 | + |
| 17 | +**Gauge (g)** |
| 18 | +: Measurement which can increase, decrease or be set to a value. |
| 19 | + |
| 20 | +**Timer (ms)** |
| 21 | +: Time measurement (in milliseconds) of an event. |
| 22 | + |
| 23 | +**Histogram (h)** |
| 24 | +: Time measurement, alias for timer. |
| 25 | + |
| 26 | +**Set (s)** |
| 27 | +: Measurement which counts unique occurrences until flushed (value set to 0). |
| 28 | + |
| 29 | +#### Supported tag extensions |
| 30 | + |
| 31 | +Example of tag styles supported by the `statsd` input: |
| 32 | + |
| 33 | +[DogStatsD](https://docs.datadoghq.com/developers/dogstatsd/datagram_shell/?tab=metrics#the-dogstatsd-protocol) |
| 34 | + |
| 35 | +`<metric name>:<value>|<type>|@samplerate|#<k>:<v>,<k>:<v>` |
| 36 | + |
| 37 | +[InfluxDB](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/statsd/README.md#influx-statsd) |
| 38 | + |
| 39 | +`<metric name>,<k>=<v>,<k>=<v>:<value>|<type>|@samplerate` |
| 40 | + |
| 41 | +[Graphite_1.1.x](https://graphite.readthedocs.io/en/latest/tags.html#graphite-tag-support) |
| 42 | + |
| 43 | +`<metric name>;<k>=<v>;<k>=<v>:<value>|<type>|@samplerate` |
| 44 | + |
| 45 | +## What data does this integration collect? |
| 46 | + |
| 47 | +The StatsD input integration collects one type of data streams: metrics. |
| 48 | + |
| 49 | +## What do I need to use this integration? |
| 50 | + |
| 51 | +You need Elasticsearch for storing and searching your data and Kibana for visualizing and managing it. |
| 52 | +You can use our hosted Elasticsearch Service on Elastic Cloud, which is recommended, or self-manage the Elastic Stack on your own hardware. |
| 53 | + |
| 54 | +## How do I deploy this integration? |
| 55 | + |
| 56 | +For step-by-step instructions on how to set up an integration, check the |
| 57 | +[Getting started](https://www.elastic.co/guide/en/welcome-to-elastic/current/getting-started-observability.html) guide. |
| 58 | + |
| 59 | +### Configuration options |
| 60 | + |
| 61 | +The `statsd` input has these additional configuration options: |
| 62 | + |
| 63 | +**Listen Address and Listen Port** |
| 64 | +: Bind address and port for the UDP server to listen on. |
| 65 | + |
| 66 | +**TTL** |
| 67 | +: It defines how long a metric will be reported after it was last recorded. Metrics are always reported at least once, regardless of the specified TTL. A TTL of zero indicates that the metrics never expire. |
| 68 | + |
| 69 | +**StatsD metric mappings (Optional)** |
| 70 | +: It defines how metrics will be mapped from the original metric label to the event JSON. Here’s an example configuration: |
| 71 | + |
| 72 | +```yaml |
| 73 | +- metric: 'ti_failures' <1> |
| 74 | + value: |
| 75 | + field: task_failures <2> |
| 76 | +- metric: '<job_name>_start' <1> |
| 77 | + labels: |
| 78 | + - attr: job_name <3> |
| 79 | + field: job_name <4> |
| 80 | + value: |
| 81 | + field: started <2> |
| 82 | +``` |
| 83 | +
|
| 84 | +1. `metric`, required: The label key of the metric in statsd, either as an exact match string, or as a template with named label placeholder in the format `<label_placeholder>`. |
| 85 | +2. `value.field`, required: Field name where to save the metric value in the event JSON. |
| 86 | +3. `label[].attr`, required when using the label placeholder: Reference to the label placeholder defined in `metric`. |
| 87 | +4. `label[].field`, required when using the label placeholder field name where to save the label placeholder value from the template in the event JSON. |
| 88 | + |
| 89 | +**Important**: |
| 90 | +- If the `statsd.mappings` is provided, only the metrics mentioned in it will remain. |
| 91 | +- If the `statsd.mappings` is provided, then flattening (replacing dots `.` with underscores `_` in metric names) is not applied. |
| 92 | +- If the `statsd.mappings` is NOT provided (default), then flattening is applied, e.g. `python.gauge.foo:10|g` becomes `python_gauge_foo:10|g`. |
| 93 | + |
| 94 | +## Troubleshooting |
| 95 | + |
| 96 | +General troubleshooting checklist (detailed steps depend on the environment): |
| 97 | +- Make sure Elastic Agent is running. |
| 98 | +- Check that the Elastic Agent is listening on the specified UDP port. |
| 99 | +- Inspect network connectivity and check firewall rules. |
| 100 | +- Examine Elastic Agent logs. |
| 101 | +- Make sure that the application or service sending metrics is correctly configured to point to the right UDP endpoint. |
| 102 | + |
| 103 | +If the `nc` is available in the environment, a sample UDP packet with StatsD payload may be sent using `nc` to check if the configuration is correct and the document appears in Kibana: |
11 | 104 |
|
12 | | -**Gauge (g)**:: Measurement which can increase, decrease or be set to a value. |
| 105 | +```bash |
| 106 | +# Replace "localhost" and "8125" with your values |
| 107 | +echo "sample:1|g" | nc -u -w0 localhost 8125 |
| 108 | +``` |
13 | 109 |
|
14 | | -**Timer (ms)**:: Time measurement (in milliseconds) of an event. |
| 110 | +## Metrics reference |
15 | 111 |
|
16 | | -**Histogram (h)**:: Time measurement, an alias for the *Timer*. |
| 112 | +### Example document |
17 | 113 |
|
18 | | -**Set (s)**:: Measurement which counts unique occurrences until flushed (value set to 0). |
| 114 | +Provided that the elastic-agent with StatsD input integration is listening on `localhost:8125`, it is possible to send a UDP packet with the following bash one-liner: |
19 | 115 |
|
| 116 | +`echo "python_gauge_foo:10|g" | nc -u -w0 localhost 8125` |
20 | 117 |
|
21 | | -## Compatibility |
| 118 | +The resulting event will look like this: |
22 | 119 |
|
23 | | -Node.js version v18.12.1 is used to test the Statsd input package |
| 120 | +```json |
| 121 | +{ |
| 122 | + "@timestamp": "2024-06-19T06:26:36.664Z", |
| 123 | + "agent": { |
| 124 | + "ephemeral_id": "f9a3bc3e-14ed-4245-a140-38032ec3e459", |
| 125 | + "id": "b138c66d-6261-4eac-a652-7f30ea89bcfc", |
| 126 | + "name": "docker-fleet-agent", |
| 127 | + "type": "metricbeat", |
| 128 | + "version": "8.13.0" |
| 129 | + }, |
| 130 | + "data_stream": { |
| 131 | + "dataset": "statsd_input.statsd", |
| 132 | + "namespace": "ep", |
| 133 | + "type": "metrics" |
| 134 | + }, |
| 135 | + "ecs": { |
| 136 | + "version": "8.17.0" |
| 137 | + }, |
| 138 | + "elastic_agent": { |
| 139 | + "id": "b138c66d-6261-4eac-a652-7f30ea89bcfc", |
| 140 | + "snapshot": false, |
| 141 | + "version": "8.13.0" |
| 142 | + }, |
| 143 | + "event": { |
| 144 | + "agent_id_status": "verified", |
| 145 | + "dataset": "statsd_input.statsd", |
| 146 | + "ingested": "2024-06-19T06:26:46Z", |
| 147 | + "module": "statsd" |
| 148 | + }, |
| 149 | + "host": { |
| 150 | + "architecture": "x86_64", |
| 151 | + "containerized": true, |
| 152 | + "hostname": "docker-fleet-agent", |
| 153 | + "id": "8259e024976a406e8a54cdbffeb84fec", |
| 154 | + "ip": [ |
| 155 | + "192.168.253.7" |
| 156 | + ], |
| 157 | + "mac": [ |
| 158 | + "02-42-C0-A8-FD-07" |
| 159 | + ], |
| 160 | + "name": "docker-fleet-agent", |
| 161 | + "os": { |
| 162 | + "codename": "focal", |
| 163 | + "family": "debian", |
| 164 | + "kernel": "3.10.0-1160.102.1.el7.x86_64", |
| 165 | + "name": "Ubuntu", |
| 166 | + "platform": "ubuntu", |
| 167 | + "type": "linux", |
| 168 | + "version": "20.04.6 LTS (Focal Fossa)" |
| 169 | + } |
| 170 | + }, |
| 171 | + "labels": {}, |
| 172 | + "metricset": { |
| 173 | + "name": "server" |
| 174 | + }, |
| 175 | + "service": { |
| 176 | + "type": "statsd" |
| 177 | + }, |
| 178 | + "statsd": { |
| 179 | + "python_gauge_foo": { |
| 180 | + "value": 10 |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | +``` |
0 commit comments