Prometheus server reload rules automatically using python script

214 views
Skip to first unread message

Renuka Alai

unread,
Sep 17, 2021, 12:58:55 PM9/17/21
to Prometheus Users
I'm using the Prometheus community.

I am creating my custom python script. It can generate the rules and update them and store them as a YAML file that will be read by Prometheus in the server. but when I am running my python script and update the rule but in the Prometheus server does not reload the rules automatically. It is possible?
Thank you

Brian Candler

unread,
Sep 17, 2021, 1:13:51 PM9/17/21
to Prometheus Users
Yes, there is a management REST API call to do this:
which you need to enable with "--web.enable-lifecycle"

Alternatively, you can send a HUP to the process (although you'll need permissions to do this, i.e. run your script as the same user as prometheus, or as root).

With systemd I use

[Unit]
Description=Prometheus Server
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

and then "systemctl reload prometheus" will reload the config (without doing a full restart)

Reply all
Reply to author
Forward
0 new messages