Saturday, 14 June 2025

How to Reload Prometheus Configuration Without Restarting the Server?

When you change the prometheus.yml configuration file (e.g., to add new targets or update scrape intervals), Prometheus does not automatically pick up the changes. But the good news is, you don’t always have to restart it. Restarting can interrupt metrics collection, so it's better to reload the configuration at runtime.

 

There are two easy ways to do this.

1.   Using the SIGHUP Signal

2.   Using a POST Request to the Reload Endpoint

 

1. Using the SIGHUP Signal

This works on Linux systems.

 

Step 1: Find the Prometheus process ID (PID):

ps ax | grep prometheus

Step 2: Send the SIGHUP signal to reload the config.

kill -HUP {process_id}

Replace {process_id} with the actual PID from step 1.

 

Make sure the user running this command has permission to send signals to the Prometheus process.

 

-HUP stands for "Hang UP" — it's a signal used in Unix-like operating systems.

 

When you run:

kill -HUP <process_id>

You're not killing the process in the way it sounds. Instead, you're sending it the SIGHUP signal, which is short for "Signal Hang Up".

 

Originally, SIGHUP was used to notify a process that a terminal (like a remote session) was disconnected. But today, many programs (like Prometheus, nginx, Apache, etc.) use it as a way to tell the process to reload its configuration file without restarting.

 

prometheus.yml

 

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

 

Start the Prometheus app by executing following command.

prometheus --config.file=./prometheus.yml

Let’s navigate to Prometheus targets section and confirm whether the job prometheus is configured or not.  

 


Let’s add one more job 'node_exporter' to prometheus configuration file.

 

prometheus.yml 

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9100']

These changes will not be reflected automatically. We need to send the -HUP signal to the prometheus process.

 

Let’s get the prometheus process id.

 

$ps -ax | grep prometheus
68661 ttys000    0:00.54 prometheus --config.file=./prometheus.yml
70902 ttys002    0:00.01 grep prometheus

Process id is 68661 from the above output.

 

Let’s execute following command to send the -HUP signal to Prometheus.

 

kill -HUP 68661

 Reload Prometheus targets page, you can observe that node_exporter job is reflected. 


 

2. Using a POST Request to the Reload Endpoint

This is a clean and modern way to reload Prometheus using an HTTP request. But you need to enable it first.

 

Step 1: Start Prometheus with lifecycle endpoint enabled.

prometheus --config.file=./prometheus.yml --web.enable-lifecycle

 

Step 2: Send a POST request to reload the config:

curl -X POST http://localhost:9090/-/reload

 

Replace localhost:9090 with your Prometheus server’s host and port if it's different.

 

To confirm this behavior, let’s remove node_exporter job from prometheus yml file.

 

prometheus.yml

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

 

Execute following curl to reload the configurations.

curl -X POST http://localhost:9090/-/reload

Reload Prometheus targets page, you can observe that node_exporter job is removed.  

  

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment