Skip to content

Commit fff1376

Browse files
authored
Merge pull request #25 from thomasjpfan/env
Adds flexible env configuration options
2 parents d6a374e + 8d227a3 commit fff1376

File tree

6 files changed

+988
-413
lines changed

6 files changed

+988
-413
lines changed

docs/config.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The formatting rules for the `ARG` variables are as follows:
1515
For example, if environment variables `ARG_WEB_ROUTE-PREFIX=/monitor` and `ARG_WEB_EXTERNAL-URL=http://localhost/monitor` are defined, Prometheus will be started with the arguments `web.route-prefix=/monitor` and `web.external-url=http://localhost/monitor`. The result would be Prometheus initialization equivalent to the command that follows.
1616

1717
```bash
18-
prometheus web.route-prefix=/monitor web.external-url=http://localhost/monitor
18+
prometheus --web.route-prefix=/monitor --web.external-url=http://localhost/monitor
1919
```
2020

2121
`ARG` variables defined by default are as follows.
@@ -27,31 +27,65 @@ ARG_WEB_CONSOLE_LIBRARIES=/usr/share/prometheus/console_libraries
2727
ARG_WEB_CONSOLE_TEMPLATES=/usr/share/prometheus/consoles
2828
```
2929

30-
## Global Configuration
30+
## Configuration
3131

32-
Environment variables prefixed with `GLOBAL_` are used instead Prometheus global entries in the configuration.
32+
Environment variables prefixed with `GLOBAL__`, `ALERTING__`, `SCRAPE_CONFIGS__`, `REMOTE_WRITE__`, and `REMOTE_READ__` are used to configure Prometheus.
3333

34-
The formatting rules for the `GLOBAL` variables are as follows:
34+
The formatting rules for these variable are as follows:
3535

36-
1. Variable name has to be prefixed with `GLOBAL_`.
37-
2. Capital letters will be transformed to lower case.
36+
1. Environment keys will be transformed to lowercase.
37+
2. Double underscore is used to go one level deeper in a yaml dictionary.
38+
3. A single underscore followed by a number indicates the position of an array.
3839

39-
For example, if environment variable `GLOBAL_SCRAPE_INTERVAL=10s` is defined, the resulting Prometheus configuration would be as follows.
40+
### Examples
4041

41-
```
42+
The following are examples of using environmental variables to configure Prometheus. Pleaes consult the Prometheus configuration [documentation](https://prometheus.io/docs/prometheus/latest/configuration/configuration) for all configuration options.
43+
44+
- `GLOBAL__SCRAPE_INTERVAL=10s`
45+
46+
```yaml
4247
global:
4348
scrape_interval: 10s
4449
```
4550
46-
Nested values can be specified by separating them with `-`. For example, if environment variables `GLOBAL_EXTERNAL_LABELS-CLUSTER=swarm` and `GLOBAL_EXTERNAL_LABELS-TYPE=production` are defined, the resulting Prometheus configuration would be as follows.
51+
- `GLOBAL__EXTERNAL_LABELS=cluster=swarm`
4752

48-
```
53+
```yaml
4954
global:
5055
external_labels:
5156
cluster: swarm
5257
type: production
5358
```
5459

60+
This is *NOT* `GLOBAL__EXTERNAL_LABELS__CLUSTER=swarm` because `CLUSTER` is not a standard Prometheus configuration. The `external_labels` option is a list of key values as shown in their documentation:
61+
62+
```yaml
63+
external_labels:
64+
[ <labelname>: <labelvalue> ... ]
65+
```
66+
67+
- `REMOTE_WRITE_1__URL=http://first.acme.com/write`, `REMOTE_WRITE_1__REMOTE_TIMEOUT=10s`,
68+
`REMOTE_WRITE_2__URL=http://second.acme.com/write`
69+
70+
```yaml
71+
remote_write:
72+
- url: http://acme.com/write
73+
remote_timeout: 30s
74+
- url: http://second.acme.com/write
75+
```
76+
77+
Trailing numbers in the `REMOTE_WRITE_1` and `REMOTE_WRITE_2` prefixes dictates the position of the array of dictionaries.
78+
79+
- `REMOTE_WRITE_1__WRITE_RELABEL_CONFIGS_1__SOURCE_LABELS_1=label1`
80+
81+
```yaml
82+
remote_write:
83+
- write_relabel_configs:
84+
- source_labels: [label1]
85+
```
86+
87+
## Scrape Environment Configuration
88+
5589
It is possible to add servers that are not part of the Docker Swarm Cluster just adding the variables `SCRAPE_PORT` and `SERVICE_NAME` on the environment. The project is going to use the [static_configs](https://prometheus.io/docs/operating/configuration/#<static_config>) configuration.
5690

5791
```
@@ -69,18 +103,6 @@ curl `[IP_OF_ONE_OF_SWARM_NODES]:8080/v1/docker-flow-monitor/reconfigure?scrapeP
69103

70104
Please consult [Prometheus Configuration](https://prometheus.io/docs/operating/configuration/) for more information about the available options.
71105

72-
## Remote Read Configuration
73-
74-
Environment variables prefixed with `REMOTE_READ_` are used instead Prometheus `remote_read` entries in the configuration.
75-
76-
The formatting rules for the `REMOTE_READ` variables follow the same pattern as those used for [Global Configuration](#global-configuration)
77-
78-
## Remote Write Configuration
79-
80-
Environment variables prefixed with `REMOTE_WRITE_` are used instead Prometheus `remote_write` entries in the configuration.
81-
82-
The formatting rules for the `REMOTE_WRITE` variables follow the same pattern as those used for [Global Configuration](#global-configuration)
83-
84106
## Scrapes
85107

86108
Additional scrapes can be added through files prefixed with `scrape_`. By default, all such files located in `/run/secrets` are automatically added to the `scrape_configs` section of the configuration. The directory can be changed by setting a different value to the environment variable `CONFIGS_DIR`.

0 commit comments

Comments
 (0)