2016-01-24 22:38:06 +00:00
# statsd exporter [![Build Status](https://travis-ci.org/prometheus/statsd_exporter.svg)][travis]
[![CircleCI ](https://circleci.com/gh/prometheus/statsd_exporter/tree/master.svg?style=shield )][circleci]
[![Docker Repository on Quay ](https://quay.io/repository/prometheus/statsd-exporter/status )][quay]
[![Docker Pulls ](https://img.shields.io/docker/pulls/prom/statsd-exporter.svg )][hub]
2013-07-02 16:29:40 +00:00
2015-10-10 00:34:28 +00:00
`statsd_exporter` receives StatsD-style metrics and exports them as Prometheus metrics.
2013-07-05 21:45:20 +00:00
## Overview
2021-09-01 13:59:07 +00:00
The StatsD exporter is a drop-in replacement for StatsD.
This exporter translates StatsD metrics to Prometheus metrics via configured mapping rules.
2015-06-18 12:23:23 +00:00
2021-09-01 13:59:07 +00:00
We recommend using the exporter only as an intermediate solution, and switching to [native Prometheus instrumentation ](http://prometheus.io/docs/instrumenting/clientlibs/ ) in the long term.
While it is common to run centralized StatsD servers, the exporter works best as a [sidecar ](https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar ).
### Transitioning from an existing StatsD setup
The relay feature allows for a gradual transition.
Introduce the exporter by adding it as a sidecar alongside the application instances.
In Kubernetes, this means adding it to the [pod ](https://kubernetes.io/docs/concepts/workloads/pods/ ).
Use the `--statsd.relay.address` to forward metrics to your existing StatsD UDP endpoint.
Relaying forwards statsd events unmodified, preserving the original metric name and tags in any format.
+-------------+ +----------+ +------------+
| Application +--->| Exporter +----------------->| StatsD |
+-------------+ +----------+ +------------+
^
| +------------+
+----------------------+ Prometheus |
+------------+
### Relaying from StatsD
To pipe metrics from an existing StatsD environment into Prometheus, configure StatsD's repeater backend to repeat all received metrics to a `statsd_exporter` process.
2013-07-05 21:45:20 +00:00
2017-08-02 05:15:53 +00:00
+----------+ +-------------------+ +--------------+
| StatsD |---(UDP/TCP repeater)--->| statsd_exporter |< --- ( scrape / metrics ) --- | Prometheus |
+----------+ +-------------------+ +--------------+
2013-07-05 21:45:20 +00:00
2021-09-01 13:59:07 +00:00
This allows trying out the exporter with minimal effort, but does not provide the per-instance metrics of the sidecar pattern.
2015-06-18 12:23:23 +00:00
2019-09-14 14:29:22 +00:00
### Tagging Extensions
2016-04-23 21:50:41 +00:00
2020-06-26 15:17:23 +00:00
The exporter supports Librato, InfluxDB, DogStatsD, and SignalFX-style tags,
2019-09-14 14:29:22 +00:00
which will be converted into Prometheus labels.
2019-09-17 14:59:08 +00:00
For Librato-style tags, they must be appended to the metric name with a
delimiting `#` , as so:
2019-09-14 14:29:22 +00:00
```
metric.name#tagName=val,tag2Name=val2:0|c
```
See the [statsd-librato-backend README ](https://github.com/librato/statsd-librato-backend#tags )
for a more complete description.
2019-09-17 14:59:08 +00:00
For InfluxDB-style tags, they must be appended to the metric name with a
delimiting comma, as so:
```
metric.name,tagName=val,tag2Name=val2:0|c
```
See [this InfluxDB blog post ](https://www.influxdata.com/blog/getting-started-with-sending-statsd-metrics-to-telegraf-influxdb/#introducing-influx-statsd )
for a larger overview.
For DogStatsD-style tags, they're appended as a `|#` delimited section at the
end of the metric, as so:
2019-09-14 14:29:22 +00:00
```
2019-11-05 16:55:23 +00:00
metric.name:0|c|#tagName:val,tag2Name:val2
2019-09-14 14:29:22 +00:00
```
See [Tags ](https://docs.datadoghq.com/developers/dogstatsd/data_types/#tagging )
in the DogStatsD documentation for the concept description and
[Datagram Format ](https://docs.datadoghq.com/developers/dogstatsd/datagram_shell/ ).
2019-09-18 11:14:57 +00:00
If you encounter problems, note that this tagging style is incompatible with
the original `statsd` implementation.
2019-09-14 14:29:22 +00:00
2020-06-26 15:17:23 +00:00
For [SignalFX dimension ](https://docs.signalfx.com/en/latest/integrations/agent/monitors/collectd-statsd.html#adding-dimensions-to-statsd-metrics ), add the tags to the metric name in square brackets, as so:
```
metric.name[tagName=val,tag2Name=val2]:0|c
```
Be aware: If you mix tag styles (e.g., Librato/InfluxDB with DogStatsD), the exporter will consider this an error and the behavior is undefined.
Also, tags without values (`#some_tag`) are not supported and will be ignored.
2016-04-23 21:50:41 +00:00
2020-08-10 16:56:23 +00:00
The exporter parses all tagging formats by default, but individual tagging formats can be disabled with command line flags:
```
--no-statsd.parse-dogstatsd-tags
--no-statsd.parse-influxdb-tags
--no-statsd.parse-librato-tags
--no-statsd.parse-signalfx-tags
```
2013-07-05 21:45:20 +00:00
## Building and Running
2018-08-28 08:08:00 +00:00
NOTE: Version 0.7.0 switched to the [kingpin ](https://github.com/alecthomas/kingpin ) flags library. With this change, flag behaviour is POSIX-ish:
* long flags start with two dashes (`--version`)
2020-08-10 18:46:44 +00:00
* boolean long flags are disabled by prefixing with no (`--flag-name` is true, `--no-flag-name` is false)
2018-08-28 08:08:00 +00:00
* multiple short flags can be combined (but there currently is only one)
* flag processing stops at the first `--`
2018-12-27 03:35:02 +00:00
```
2018-08-21 08:57:44 +00:00
usage: statsd_exporter [< flags > ]
Flags:
2020-05-29 07:59:58 +00:00
-h, --help Show context-sensitive help (also try
--help-long and --help-man).
2019-04-23 08:47:32 +00:00
--web.listen-address=":9102"
2020-05-29 07:59:58 +00:00
The address on which to expose the web interface
and generated Prometheus metrics.
2020-08-10 18:46:44 +00:00
--web.enable-lifecycle Enable shutdown and reload via HTTP request.
2019-04-23 08:47:32 +00:00
--web.telemetry-path="/metrics"
2019-05-26 13:08:54 +00:00
Path under which to expose metrics.
2019-04-23 08:47:32 +00:00
--statsd.listen-udp=":9125"
2020-05-29 07:59:58 +00:00
The UDP address on which to receive statsd
metric lines. "" disables it.
2019-04-23 08:47:32 +00:00
--statsd.listen-tcp=":9125"
2020-05-29 07:59:58 +00:00
The TCP address on which to receive statsd
metric lines. "" disables it.
2019-04-23 08:47:32 +00:00
--statsd.listen-unixgram=""
2020-05-29 07:59:58 +00:00
The Unixgram socket path to receive statsd
metric lines in datagram. "" disables it.
2019-04-23 08:47:32 +00:00
--statsd.unixsocket-mode="755"
2019-05-26 13:08:54 +00:00
The permission mode of the unix socket.
2019-04-23 08:47:32 +00:00
--statsd.mapping-config=STATSD.MAPPING-CONFIG
2019-05-26 13:08:54 +00:00
Metric mapping configuration file name.
2019-04-23 08:47:32 +00:00
--statsd.read-buffer=STATSD.READ-BUFFER
2020-05-29 07:59:58 +00:00
Size (in bytes) of the operating system's
transmit read buffer associated with the UDP or
Unixgram connection. Please make sure the kernel
parameters net.core.rmem_max is set to a value
greater than the value specified.
--statsd.cache-size=1000 Maximum size of your metric mapping cache.
Relies on least recently used replacement policy
if max size is reached.
--statsd.cache-type=lru Metric mapping cache type. Valid options are
"lru" and "random"
2019-05-26 13:08:54 +00:00
--statsd.event-queue-size=10000
Size of internal queue for processing events
--statsd.event-flush-threshold=1000
2020-05-29 07:59:58 +00:00
Number of events to hold in queue before
flushing
2019-05-26 13:08:54 +00:00
--statsd.event-flush-interval=200ms
2020-09-25 21:00:34 +00:00
Maximum time between event queue flushes.
--debug.dump-fsm="" The path to dump internal FSM generated for
glob matching as Dot file.
2020-05-29 07:59:58 +00:00
--check-config Check configuration and exit.
2020-08-10 18:54:59 +00:00
--statsd.parse-dogstatsd-tags
Parse DogStatsd style tags. Enabled by default.
--statsd.parse-influxdb-tags
Parse InfluxDB style tags. Enabled by default.
--statsd.parse-librato-tags
Parse Librato style tags. Enabled by default.
--statsd.parse-signalfx-tags
Parse SignalFX style tags. Enabled by default.
2021-07-21 12:46:19 +00:00
--statsd.relay.address=STATSD.RELAY.ADDRESS
The UDP relay target address (host:port)
--statsd.relay.packet-length=1400
Maximum relay output packet length to avoid fragmentation
2020-05-29 07:59:58 +00:00
--log.level=info Only log messages with the given severity or
above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt,
json]
2019-05-26 13:08:54 +00:00
--version Show application version.
2018-12-27 03:35:02 +00:00
```
2020-08-10 18:46:44 +00:00
## Lifecycle API
The `statsd_exporter` has an optional lifecycle API (disabled by default) that can be used to reload or quit the exporter
by sending a `PUT` or `POST` request to the `/-/reload` or `/-/quit` endpoints.
2013-07-05 21:45:20 +00:00
2021-07-21 12:46:19 +00:00
## Relay
The `statsd_exporter` has an optional mode that will buffer and relay incoming statsd lines to a remote server. This is useful to "tee" the data when migrating to using the exporter. The relay will flush the buffer at least once per second to avoid delaying delivery of metrics.
2013-07-05 21:45:20 +00:00
## Tests
$ go test
## Metric Mapping and Configuration
2015-10-10 00:34:28 +00:00
The `statsd_exporter` can be configured to translate specific dot-separated StatsD
2019-01-24 07:26:45 +00:00
metrics into labeled Prometheus metrics via a simple mapping language. The config
2019-07-05 13:27:47 +00:00
file is reloaded on SIGHUP.
2019-01-24 07:26:45 +00:00
A mapping definition starts with a line matching the StatsD metric in question,
2013-07-05 21:51:30 +00:00
with `*` s acting as wildcards for each dot-separated metric component. The
lines following the matching expression must contain one `label="value"` pair
each, and at least define the metric name (label name `name` ). The Prometheus
metric is then constructed from these labels. `$n` -style references in the
label value are replaced by the n-th wildcard match in the matching line,
starting at 1. Multiple matching definitions are separated by one or more empty
lines. The first mapping rule that matches a StatsD metric wins.
2013-07-05 21:45:20 +00:00
2013-07-05 22:32:52 +00:00
Metrics that don't match any mapping in the configuration file are translated
2017-11-10 20:34:10 +00:00
into Prometheus metrics without any labels and with any non-alphanumeric
characters, including periods, translated into underscores.
2013-07-05 22:32:52 +00:00
2016-05-02 18:53:00 +00:00
In general, the different metric types are translated as follows:
2013-07-05 22:32:52 +00:00
2016-05-02 18:53:00 +00:00
StatsD gauge -> Prometheus gauge
2015-06-07 14:11:38 +00:00
2016-05-02 18:53:00 +00:00
StatsD counter -> Prometheus counter
2015-06-07 14:11:38 +00:00
2020-06-19 11:56:55 +00:00
StatsD timer, histogram, distribution -> Prometheus summary or histogram
2013-07-05 22:32:52 +00:00
2020-12-18 09:22:45 +00:00
### Glob matching
The default (and fastest) `glob` mapping style uses `*` to denote parts of the statsd metric name that may vary.
These varying parts can then be referenced in the construction of the Prometheus metric name and labels.
2017-09-28 18:30:17 +00:00
An example mapping configuration:
2013-07-05 21:45:20 +00:00
2017-08-01 11:26:44 +00:00
```yaml
mappings:
2019-07-05 13:31:38 +00:00
- match: "test.dispatcher.*.*.*"
2017-11-13 12:21:29 +00:00
name: "dispatcher_events_total"
2017-08-01 11:26:44 +00:00
labels:
processor: "$1"
action: "$2"
outcome: "$3"
job: "test_dispatcher"
2019-07-05 13:31:38 +00:00
- match: "*.signup.*.*"
2017-11-13 12:21:29 +00:00
name: "signup_events_total"
2017-08-01 11:26:44 +00:00
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
```
2017-08-04 22:41:02 +00:00
This would transform these example StatsD metrics into Prometheus metrics as
follows:
test.dispatcher.FooProcessor.send.success
=> dispatcher_events_total{processor="FooProcessor", action="send", outcome="success", job="test_dispatcher"}
foo_product.signup.facebook.failure
=> signup_events_total{provider="facebook", outcome="failure", job="foo_product_server"}
test.web-server.foo.bar
2017-11-10 20:34:10 +00:00
=> test_web_server_foo_bar{}
2017-08-04 22:41:02 +00:00
2018-01-16 13:16:15 +00:00
Each mapping in the configuration file must define a `name` for the metric. The
metric's name can contain `$n` -style references to be replaced by the n-th
wildcard match in the matching line. That allows for dynamic rewrites, such as:
```yaml
mappings:
2019-07-05 13:31:38 +00:00
- match: "test.*.*.counter"
2018-01-17 23:48:42 +00:00
name: "${2}_total"
2018-01-16 13:16:15 +00:00
labels:
provider: "$1"
```
2017-08-04 22:41:02 +00:00
2020-12-18 09:22:45 +00:00
Glob matching offers the best performance for common mappings.
2021-01-22 12:55:37 +00:00
#### Ordering glob rules
2020-12-18 09:22:45 +00:00
2021-01-22 12:55:37 +00:00
List more specific matches before wildcards, from left to right:
a.b.c
a.b.*
a.*.d
a.*.*
This avoids unexpected shadowing of later rules, and performance impact from backtracking.
Alternatively, you can disable mapping ordering altogether.
2020-12-18 09:22:45 +00:00
With unordered mapping, at each hierarchy level the most specific match wins.
2021-01-22 12:55:37 +00:00
This has the same effect as using the recommended ordering.
2020-12-18 09:22:45 +00:00
### Regular expression matching
The `regex` mapping style uses regular expressions to match the full statsd metric name.
Use it if the glob mapping is not flexible enough to pull structured data from the available statsd metric names.
Regular expression matching is significantly slower than glob mapping as all mappings must be tested in order.
Because of this, **regex mappings are only executed after all glob mappings** .
In other words, glob mappings take preference over regex matches, irrespective of the order in which they are specified.
2021-01-22 12:55:37 +00:00
Regular expression matches are always evaluated in order, and the first match wins.
2020-12-18 09:22:45 +00:00
2018-01-17 16:30:40 +00:00
The metric name can also contain references to regex matches. The mapping above
could be written as:
2019-07-05 13:31:38 +00:00
```yaml
2018-01-17 16:30:40 +00:00
mappings:
2019-11-26 08:56:14 +00:00
- match: "test\\.(\\w+)\\.(\\w+)\\.counter"
match_type: regex
name: "${2}_total"
labels:
provider: "$1"
2020-12-18 09:22:45 +00:00
mappings:
2021-03-23 16:48:48 +00:00
- match: "(.*)\\.(.*)--(.*)\\.status\.(.*)\\.count"
2020-12-18 09:22:45 +00:00
match_type: regex
name: "request_total"
labels:
hostname: "$1"
exec: "$2"
protocol: "$3"
code: "$4"
2019-11-26 08:56:14 +00:00
```
2020-05-29 07:59:58 +00:00
Be aware about yaml escape rules as a mapping like the following one will not work.
```yaml
2019-11-26 08:56:14 +00:00
mappings:
2021-03-23 16:48:48 +00:00
- match: "test\\.(\w+)\\.(\w+)\\.counter"
2018-01-17 16:30:40 +00:00
match_type: regex
2018-01-17 23:48:42 +00:00
name: "${2}_total"
2018-01-17 16:30:40 +00:00
labels:
provider: "$1"
```
2021-01-22 12:55:37 +00:00
2022-06-29 08:14:56 +00:00
#### Special match groups
When using regex, the match group `0` is the full match and can be used to attach labels to the metric.
Example:
```yaml
mappings:
- match: ".+"
match_type: regex
name: "$0"
labels:
statsd_metric_name: "$0"
```
If a metric `my.statsd_counter` is received, the metric name will **still** be mapped to `my_statsd_counter` (Prometheus compatible name).
But the metric will also have the label `statsd_metric_name` with the value `my.statsd_counter` (unchanged value).
2022-06-29 08:18:15 +00:00
Note: If you use the `match` like the example (i.e. `.+` ), be aware that it will be a "catch-all" block. So it should come at the very end of the mapping list.
2022-06-29 08:23:33 +00:00
The same is not achievable with glob matching, for more details check [this issue ](https://github.com/prometheus/statsd_exporter/issues/444 ).
2022-06-29 08:14:56 +00:00
2020-12-18 09:22:45 +00:00
### Naming, labels, and help
2018-01-17 16:30:40 +00:00
2018-01-17 16:31:01 +00:00
Please note that metrics with the same name must also have the same set of
2018-01-17 17:08:09 +00:00
label names.
2018-01-17 16:31:01 +00:00
2017-10-04 16:11:58 +00:00
If the default metric help text is insufficient for your needs you may use the YAML
configuration to specify a custom help text for each mapping:
2018-01-17 23:48:42 +00:00
2017-10-04 16:11:58 +00:00
```yaml
mappings:
2019-07-05 13:31:38 +00:00
- match: "http.request.*"
2017-10-04 16:11:58 +00:00
help: "Total number of http requests"
2017-11-13 12:21:29 +00:00
name: "http_requests_total"
2017-10-04 16:11:58 +00:00
labels:
code: "$1"
```
2020-06-19 11:56:55 +00:00
### StatsD timers and distributions
2018-10-03 23:30:12 +00:00
2020-06-19 11:56:55 +00:00
By default, statsd timers and distributions (collectively "observers") are
represented as a Prometheus summary with quantiles. You may optionally
configure the [quantiles and acceptable
error](https://prometheus.io/docs/practices/histograms/#quantiles), as well
as adjusting how the summary metric is aggregated:
2017-08-01 11:26:44 +00:00
```yaml
mappings:
2019-07-05 13:31:38 +00:00
- match: "test.timing.*.*.*"
2020-06-19 11:56:55 +00:00
observer_type: summary
2017-11-13 12:21:29 +00:00
name: "my_timer"
labels:
2017-08-01 11:26:44 +00:00
provider: "$2"
outcome: "$3"
job: "${1}_server"
2020-01-16 16:55:09 +00:00
summary_options:
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
- quantile: 0.9
error: 0.05
- quantile: 0.5
error: 0.005
2021-01-28 18:37:56 +00:00
max_age: 30s
age_buckets: 3
buf_cap: 1000
2017-08-01 11:26:44 +00:00
```
2018-08-09 08:18:39 +00:00
The default quantiles are 0.99, 0.9, and 0.5.
2020-01-27 14:50:34 +00:00
The default summary age is 10 minutes, the default number of buckets
2020-06-19 11:56:55 +00:00
is 5 and the default buffer size is 500.
See also the [`golang_client` docs ](https://godoc.org/github.com/prometheus/client_golang/prometheus#SummaryOpts ).
The `max_summary_age` corresponds to `SummaryOptions.MaxAge` , `summary_age_buckets` to `SummaryOptions.AgeBuckets` and `stream_buffer_size` to `SummaryOptions.BufCap` .
2020-01-27 14:50:34 +00:00
2020-06-19 11:56:55 +00:00
In the configuration, one may also set the observer type to "histogram". For example,
to set the observer type for a single timer metric:
2018-08-09 08:18:39 +00:00
```yaml
mappings:
2019-07-05 13:31:38 +00:00
- match: "test.timing.*.*.*"
2020-06-19 11:56:55 +00:00
observer_type: histogram
2020-01-16 16:55:09 +00:00
histogram_options:
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
2018-08-09 08:18:39 +00:00
name: "my_timer"
labels:
provider: "$2"
outcome: "$3"
job: "${1}_server"
```
2020-09-25 21:00:34 +00:00
If not set, then the default
[Prometheus client
values](https://godoc.org/github.com/prometheus/client_golang/prometheus#pkg-variables)
are used for the histogram buckets:
`[.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]` .
`+Inf` is added automatically.
`observer_type` is only used when the statsd metric type is a timer, histogram, or distribution.
`buckets` is only used when the statsd metric type is one of these, and the `observer_type` is set to `histogram` .
2020-06-19 11:56:55 +00:00
Timers will be accepted with the `ms` statsd type.
Statsd timer data is transmitted in milliseconds, while Prometheus expects the unit to be seconds.
The exporter converts all timer observations to seconds.
2019-05-13 18:30:38 +00:00
2020-06-19 11:56:55 +00:00
Histogram and distribution events (`h` and `d` metric type) are not subject to unit conversion.
2019-09-05 23:44:41 +00:00
2019-09-03 17:02:19 +00:00
### DogStatsD Client Behavior
#### `timed()` decorator
2020-06-19 11:56:55 +00:00
The DogStatsD client's [timed ](https://datadogpy.readthedocs.io/en/latest/#datadog.threadstats.base.ThreadStats.timed ) decorator emits the metric in seconds but uses the `ms` type.
Set [`use_ms=True` ](https://datadogpy.readthedocs.io/en/latest/index.html?highlight=use_ms ) to send the correct units.
2019-08-01 10:22:46 +00:00
2018-10-03 23:30:12 +00:00
### Regular expression matching
2017-09-29 07:57:17 +00:00
Another capability when using YAML configuration is the ability to define matches
using raw regular expressions as opposed to the default globbing style of match.
This may allow for pulling structured data from otherwise poorly named statsd
metrics AND allow for more precise targetting of match rules. When no `match_type`
2020-04-11 23:09:51 +00:00
parameter is specified the default value of `glob` will be assumed:
2017-09-29 07:57:17 +00:00
```yaml
mappings:
2021-03-23 16:48:48 +00:00
- match: "(.*)\\.(.*)--(.*)\\.status\\.(.*)\\.count"
2017-09-29 07:57:17 +00:00
match_type: regex
2017-11-13 12:21:29 +00:00
name: "request_total"
2017-09-29 07:57:17 +00:00
labels:
hostname: "$1"
exec: "$2"
protocol: "$3"
code: "$4"
```
2018-10-03 23:30:12 +00:00
### Global defaults
2021-01-28 18:37:56 +00:00
One may also set defaults for the observer type, histogram options, summary options, and match type.
2020-06-19 11:56:55 +00:00
These will be used by all mappings that do not define them.
2017-08-01 11:26:44 +00:00
2020-06-19 11:56:55 +00:00
An option that can only be configured in `defaults` is `glob_disable_ordering` , which is `false` if omitted.
By setting this to `true` , `glob` match type will not honor the occurance of rules in the mapping rules file and always treat `*` as lower priority than a concrete string.
2018-10-03 23:30:12 +00:00
2021-01-28 18:37:56 +00:00
Setting `buckets` or `quantiles` in the defaults is deprecated in favor of `histogram_options` and `summary_options` , which will override the deprecated values.
If `summary_options` is present in a mapping config, it will only override the fields set in the mapping. Unset fields in the mapping will take the values from the defaults.
2017-08-01 11:26:44 +00:00
```yaml
defaults:
2020-06-19 11:56:55 +00:00
observer_type: histogram
2021-01-28 18:37:56 +00:00
histogram_options:
buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5 ]
summary_options:
quantiles:
- quantile: 0.99
error: 0.001
- quantile: 0.95
error: 0.01
- quantile: 0.9
error: 0.05
- quantile: 0.5
error: 0.005
max_age: 5m
age_buckets: 2
buf_cap: 1000
2017-09-29 07:57:17 +00:00
match_type: glob
2018-10-03 23:30:12 +00:00
glob_disable_ordering: false
2018-12-18 12:16:05 +00:00
ttl: 0 # metrics do not expire
2017-08-01 11:26:44 +00:00
mappings:
# This will be a histogram using the buckets set in `defaults`.
2019-07-05 13:31:38 +00:00
- match: "test.timing.*.*.*"
2017-11-13 12:21:29 +00:00
name: "my_timer"
2018-01-17 23:48:42 +00:00
labels:
2017-08-01 11:26:44 +00:00
provider: "$2"
outcome: "$3"
job: "${1}_server"
2021-01-28 18:37:56 +00:00
# This will be a summary using the summary_options set in `defaults`
2020-06-19 11:56:55 +00:00
- match: "other.distribution.*.*.*"
observer_type: summary
name: "other_distribution"
2018-01-17 23:48:42 +00:00
labels:
2017-08-01 11:26:44 +00:00
provider: "$2"
outcome: "$3"
job: "${1}_server_other"
```
2018-10-03 23:30:12 +00:00
### `drop` action
You may also drop metrics by specifying a "drop" action on a match. For
example:
2018-01-02 22:21:50 +00:00
```yaml
mappings:
# This metric would match as normal.
2019-07-05 13:31:38 +00:00
- match: "test.timing.*.*.*"
2018-01-02 22:21:50 +00:00
name: "my_timer"
2018-01-17 23:48:42 +00:00
labels:
2018-01-02 22:21:50 +00:00
provider: "$2"
outcome: "$3"
job: "${1}_server"
# Any metric not matched will be dropped because "." matches all metrics.
2019-07-05 13:31:38 +00:00
- match: "."
2018-01-02 22:21:50 +00:00
match_type: regex
action: drop
name: "dropped"
```
You can drop any metric using the normal match syntax.
The default action is "map" which does the normal metrics mapping.
2018-10-03 23:30:12 +00:00
### Explicit metric type mapping
2018-06-15 09:10:55 +00:00
StatsD allows emitting of different metric types under the same metric name,
but the Prometheus client library can't merge those. For this use-case the
mapping definition allows you to specify which metric type to match:
```
mappings:
2019-07-05 13:31:38 +00:00
- match: "test.foo.*"
2018-06-15 09:10:55 +00:00
name: "test_foo"
match_metric_type: counter
labels:
provider: "$1"
```
2020-06-19 11:56:55 +00:00
Possible values for `match_metric_type` are `gauge` , `counter` and `observer` .
2018-06-15 09:10:55 +00:00
2019-12-02 05:31:16 +00:00
### Mapping cache size and cache replacement policy
2019-04-03 15:36:34 +00:00
There is a cache used to improve the performance of the metric mapping, that can greatly improvement performance.
The cache has a default maximum of 1000 unique statsd metric names -> prometheus metrics mappings that it can store.
This maximum can be adjust using the `statsd.cache-size` flag.
2020-03-05 09:34:47 +00:00
If the maximum is reached, entries are by default rotated using the [least recently used replacement policy ](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU )). This strategy is optimal when memory is constrained as only the most recent entries are retained.
2019-04-03 15:36:34 +00:00
2020-03-05 09:34:47 +00:00
Alternatively, you can choose a [random-replacement cache strategy ](https://en.wikipedia.org/wiki/Cache_replacement_policies#Random_replacement_(RR )). This is less optimal if the cache is smaller than the cacheable set, but requires less locking. Use this for very high throughput, but make sure to allow for a cache that holds all metrics.
2019-04-03 15:36:34 +00:00
2020-03-05 09:34:47 +00:00
The optimal cache size is determined by the cardinality of the _incoming_ metrics.
2019-04-03 15:36:34 +00:00
2018-12-13 13:53:40 +00:00
### Time series expiration
2018-12-18 12:16:05 +00:00
The `ttl` parameter can be used to define the expiration time for stale metrics.
The value is a time duration with valid time units: "ns", "us" (or "µs"),
2018-12-13 13:53:40 +00:00
"ms", "s", "m", "h". For example, `ttl: 1m20s` . `0` value is used to indicate
2018-12-18 12:16:05 +00:00
metrics that do not expire.
2018-12-13 13:53:40 +00:00
2018-12-20 16:47:22 +00:00
TTL configuration is stored for each mapped metric name/labels combination
whenever new samples are received. This means that you cannot immediately
expire a metric only by changing the mapping configuration. At least one
sample must be received for updated mappings to take effect.
2018-12-13 13:53:40 +00:00
2019-05-26 13:08:54 +00:00
### Event flushing configuration
Internally `statsd_exporter` runs a goroutine for each network listener (UDP, TCP & Unix Socket). These each receive and parse metrics received into an event. For performance purposes, these events are queued internally and flushed to the main exporter goroutine periodically in batches. The size of this queue and the flush criteria can be tuned with the `--statsd.event-queue-size` , `--statsd.event-flush-threshold` and `--statsd.event-flush-interval` . However, the defaults should perform well even for very high traffic environments.
2015-06-07 14:11:38 +00:00
## Using Docker
2020-03-05 05:31:55 +00:00
You can deploy this exporter using the [prom/statsd-exporter ](https://registry.hub.docker.com/r/prom/statsd-exporter ) Docker image.
2015-06-07 14:11:38 +00:00
For example:
```bash
2015-10-10 00:34:28 +00:00
docker pull prom/statsd-exporter
2015-06-07 14:11:38 +00:00
2017-08-02 05:15:53 +00:00
docker run -d -p 9102:9102 -p 9125:9125 -p 9125:9125/udp \
2018-09-07 08:25:38 +00:00
-v $PWD/statsd_mapping.yml:/tmp/statsd_mapping.yml \
prom/statsd-exporter --statsd.mapping-config=/tmp/statsd_mapping.yml
2015-06-07 14:11:38 +00:00
```
2016-01-24 22:38:06 +00:00
2020-04-17 12:02:15 +00:00
## Library packages
Parts of the implementation of this exporter are available as separate packages.
See the [documentation ](https://pkg.go.dev/github.com/prometheus/statsd_exporter/pkg ) for details.
For the time being, there are *no stability guarantees* for library interfaces.
We will try to call out any significant changes in the [changelog ](https://github.com/prometheus/statsd_exporter/blob/master/CHANGELOG.md ).
Semantic versioning of the exporter is based on the impact on users of the exporter, not users of the library.
We encourage re-use of these packages and welcome [issues ](https://github.com/prometheus/statsd_exporter/issues?q=is%3Aopen+is%3Aissue+label%3Alibrary ) related to their usability as a library.
2016-01-24 22:38:06 +00:00
[travis]: https://travis-ci.org/prometheus/statsd_exporter
[circleci]: https://circleci.com/gh/prometheus/statsd_exporter
[quay]: https://quay.io/repository/prometheus/statsd-exporter
2021-07-21 12:46:19 +00:00
[hub]: https://hub.docker.com/r/prom/statsd-exporter/