Drux
Drux

Reputation: 12660

Change address where Prometheus node exporter listens in systemd drop-in unit

I have a this drop-in unit:

# /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
[Service]
Environment=ARGS=--web.listen-address=localhost:9101

It is relative to this unit from Debian package prometheus-node-exporter (stretch-backports version):

# /lib/systemd/system/prometheus-node-exporter.service
[Unit]
Description=Prometheus exporter for machine metrics
Documentation=https://github.com/prometheus/node_exporter

[Service]
Restart=always
User=prometheus
EnvironmentFile=/etc/default/prometheus-node-exporter
ExecStart=/usr/bin/prometheus-node-exporter $ARGS
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

/etc/default/prometheus-node-exporter sets ARGS="", i.e. the node exporter's default port 9100 applies. The drop-in is meant to change this to 9101 and let the service listen only on localhost.

After systemctl start prometheus-node-exporter the service listens on :::9100 (tcp6). However, if I comment-out EnvironmentFile in the unit file it listens on 127.0.0.1:9101 (tcp), as I want it to. So it seems as if EnvironmentFile from the unit keeps precedence over Environment in the drop-in unit.

Why does the drop-in not override the unit in choosing the value of ARGS? What am I missing and can I change the default listening address with a custom drop-in unit?

Upvotes: 7

Views: 17539

Answers (1)

Jürgen Hötzel
Jürgen Hötzel

Reputation: 19727

From man systemd.exec:

EnvironmentFile= ... Settings from these files override settings made with Environment=. If the same variable is set twice from these files, the files will be read in the order they are specified and the later setting will override the earlier setting.

So you need to specify an EnvironmentFile to override the setting in the unit file:

# /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
[Service]
EnvironmentFile=/etc/prometheus.conf

and actual config:

# cat /etc/prometheus.conf
ARGS=--web.listen-address=localhost:9101

Upvotes: 8

Related Questions