Configure Prometheus to use non-default port
Asked Answered
M

3

17

I would like to install Prometheus on port 8080 instead of 9090 (its normal default). To this end I have edited /etc/systemd/system/prometheus.service to contain this line:

ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus.yaml --web.enable-admin-api \
  --web.listen-address=":8080"

I.e., I am using option --web.listen-address to specifiy the non-default port.

However, when I start Prometheus (2.0 beta) with systemctl start prometheus I receive this error message:

parse external URL "": invalid external URL "http://<myhost>:8080\"/"

So how can I configure Prometheus such that I can reach its web UI at http://<myhost>:8080/ (instead of http://<myhost>:9090)?

Merely answered 21/11, 2017 at 13:42 Comment(0)
M
28

The quotes were superfluous. This line will work:

ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus.yaml --web.enable-admin-api \
  --web.listen-address=:8080
Merely answered 21/11, 2017 at 13:44 Comment(0)
C
2

I'm using Ubuntu 20.02. It requires:

--web.listen-address=:8080  #defaults to  IPv6
--web.listen-address=*:8080 # does not work
--web.listen-address=192.168.1.X:8080 # for IPv4
Clowers answered 9/9, 2021 at 17:22 Comment(2)
does config file really not have option for this? I can't believe it.Asaph
look into /etc/default/prometheus @AsaphHeavyladen
H
2

There is a default config location for prometheus & prometheus-node-exporter.

Both support --web.listen-address=host:port in their respective config files in /etc/default/prometheus and /etc/default/prometheus-node-exporter

It is noteworthy that prometheus & node-exporter will prefer to bind to an ipv6 (if ipv6 interface is present) using the default config value:

--web.listen-address=:9090

In that case, Prometheus will not bind to ipv4 interface and is only available with ipv6. Many people do not want this, and should set default listener interface explicitly.

These files in /etc/default/ are automatically read by the service units when starting up. It is not paradigmatic to modify the service unit, if there is a config file for the purpose.

Counterintuitively, it is not /etc/prometheus/prometheus.yml, because this file only describes prometheus workloads not the system service configuration.

Heavyladen answered 21/2, 2024 at 10:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.