| 1 |
# Name |
| 2 |
|
| 3 |
_metrics_ - enable [prometheus](https://prometheus.io/) metrics |
| 4 |
|
| 5 |
# Description |
| 6 |
|
| 7 |
With _metrics_ metrics are exported from atomdns and any handler that adds extra ones. |
| 8 |
The default address for the metrics server is `localhost:9153`. The metrics path is fixed to `/metrics`. |
| 9 |
See the _global_ handler for details on how to change the address, and other properties. |
| 10 |
|
| 11 |
You must also enable metrics in the handler block, this allows you to specify where in the handler chain the |
| 12 |
metrics are gathered. Usually this is the first handler. If the global block doesn't specify _metrics_ the |
| 13 |
metrics will not be able to be scraped, but they are still gathered. |
| 14 |
|
| 15 |
Enabling metrics means taking a (severe) performance hit (50 Kqps, seen in [limited] testing), to alleviate |
| 16 |
this, by default, only 1 in 10 queries will be monitored. See the _global_ handler's documentation on how to change this. |
| 17 |
When displaying these metrics in (e.g.) Grafana, be sure to \*10, otherwise your queries per second is lower |
| 18 |
then you hoped for. Other handlers that use metrics on a per-query basis also adhere to this limit, for |
| 19 |
instance the _acl_ handler gathers one in `N`. |
| 20 |
|
| 21 |
In addition to the default Go metrics exported by the [prometheus Go |
| 22 |
client](https://prometheus.io/docs/guides/go-application/), the following metrics are exported: |
| 23 |
|
| 24 |
- `atomdns_dns_dropped_total{}` - total count of dropped queries, because they are invalid, these will always |
| 25 |
be reported even with `metrics disable`, as this happens before the query hits this handler. |
| 26 |
- `atomdns_dns_requests_total{zone, network, family, flags}` - total query count. |
| 27 |
- `atomdns_dns_responses_total{zone, network, family, rcode}` - response per, among other things, the response code. |
| 28 |
- `atomdns_dns_request_duration_seconds{zone, network, family}` - duration to process each query. |
| 29 |
- `atomdns_dns_request_size_bytes{zone, network, family}` - size of the request in bytes. |
| 30 |
- `atomdns_dns_response_size_bytes{zone, network, family}` - response size in bytes. |
| 31 |
|
| 32 |
* `network` which holds the transport of the response ("udp" or "tcp") |
| 33 |
* The address family (`family`) of the transport (1 = IP (IP version 4), 2 = IP6 (IP version 6)). |
| 34 |
* `flags` is a string that consists out of header flags mnemonics seperated by spaces: |
| 35 |
- `flags="co do"` means the CO (compact answers) and DO (dnssec ok) are set. |
| 36 |
- The recognized flags are: co - compact answers, do - dnssec ok, de - deleg ok, ad - authenticated data, |
| 37 |
and cd - checking disabled. |
| 38 |
|
| 39 |
If a server want to not partake in the metrics collection it sets `metrics disable` in the configuration. The default is |
| 40 |
to allow metrics gathering. |
| 41 |
|
| 42 |
# Syntax |
| 43 |
|
| 44 |
```txt |
| 45 |
metrics [|enable|disable] |
| 46 |
``` |
| 47 |
|
| 48 |
Where: |
| 49 |
|
| 50 |
- _empty_ or `enable` will enable metrics gathering, only `disable` will disable it. |
| 51 |
|
| 52 |
# Examples |
| 53 |
|
| 54 |
Start a server on the default port and load the _whoami_ handler and disable metrics. |
| 55 |
|
| 56 |
```txt |
| 57 |
{ |
| 58 |
metrics |
| 59 |
debug |
| 60 |
} |
| 61 |
|
| 62 |
example.org { |
| 63 |
metrics disable |
| 64 |
whoami |
| 65 |
} |
| 66 |
``` |
| 67 |
|
| 68 |
To scrape metrics with prometheus you need something like this in the main `prometheus.yaml` configuration |
| 69 |
file: |
| 70 |
|
| 71 |
```yaml |
| 72 |
global: |
| 73 |
scrape_interval: 1m |
| 74 |
|
| 75 |
scrape_configs: |
| 76 |
- job_name: atomdns |
| 77 |
static_configs: |
| 78 |
- targets: ["localhost:9153"] |
| 79 |
``` |
| 80 |
|
| 81 |
# See Also |
| 82 |
|
| 83 |
[Getting Started with Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/). |