How to change a default port of Prometheus.

388 views
Skip to first unread message

Abhishek Kurmi

unread,
Aug 16, 2023, 9:21:15 AM8/16/23
to Prometheus Users
How to change a default port of Prometheus?
I all ready tried some steps but those are not working.
I tried to change a port form prometheus.service file --web.listen-address=:9500
but it is not working , even after that it is running on the default port.

please suggest me how can i can a port?

Brian Candler

unread,
Aug 16, 2023, 10:05:45 AM8/16/23
to Prometheus Users
That's the correct way to do it - and I've just tested with prometheus 2.45.0 to be sure.

Therefore, if it's not working, it means you're not applying this option correctly. 

Use "ps auxwwww | grep prometheus" to see what actual command line options you're passing.

If this is in a .service file, you will need to run "systemctl daemon-reload" to get systemd to re-read your modified file, before "systemctl restart prometheus"

I prefer to do it like this:

--------
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=prometheus
Restart=on-failure
RestartSec=5
TimeoutStopSec=300
WorkingDirectory=/opt/prometheus
EnvironmentFile=/etc/default/prometheus
ExecStart=/opt/prometheus/prometheus $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
--------

where /etc/default/prometheus contains

OPTIONS='--web.enable-admin-api --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data/ --storage.tsdb.wal-compression --log.level=info --storage.tsdb.retention.time=366d --web.enable-remote-write-receiver'

When you change the options here, no "daemon-reload" is necessary, just a restart.
Reply all
Reply to author
Forward
0 new messages