66from src .config import app , db
77from src .models import ExternalMonitornig
88from src .utils import ROOT_DIR
9- from src .routes .helper .prometheus_helper import load_yaml , save_yaml , is_valid_file , show_targets , prometheus_yml_path
9+ from src .routes .helper .prometheus_helper import (
10+ load_yaml ,
11+ save_yaml ,
12+ is_valid_file ,
13+ show_targets ,
14+ prometheus_yml_path ,
15+ update_prometheus_container )
16+
1017
1118# Define the Prometheus Blueprint
1219prometheus_bp = Blueprint ('prometheus' , __name__ )
@@ -57,6 +64,7 @@ def targets():
5764 targets_info = show_targets ()
5865 return render_template ('other/targets.html' , targets_info = targets_info )
5966
67+
6068@app .route ('/targets/add_target' , methods = ['POST' ])
6169def add_target ():
6270 job_name = request .form .get ('job_name' )
@@ -75,7 +83,8 @@ def add_target():
7583 'scrape_interval' : scrape_interval # Set the specific interval
7684 }
7785 config ['scrape_configs' ].append (new_job )
78-
86+
87+ update_prometheus_container ()
7988 save_yaml (config , prometheus_yml_path )
8089 flash ('Target added successfully!' , 'success' )
8190 return redirect (url_for ('targets' ))
@@ -92,7 +101,8 @@ def remove_target():
92101 if target_to_remove in targets :
93102 targets .remove (target_to_remove )
94103 flash (f'Target { target_to_remove } removed successfully!' , 'success' )
95-
104+
105+ update_prometheus_container ()
96106 # Check if this was the last target, then remove the job
97107 if not targets : # If the list is now empty
98108 config ['scrape_configs' ].remove (scrape_config )
@@ -116,6 +126,7 @@ def change_interval():
116126 if scrape_config ['job_name' ] == job_name :
117127 scrape_config ['scrape_interval' ] = new_interval
118128 flash ('Scrape interval updated successfully!' , 'success' )
129+ update_prometheus_container ()
119130 break
120131
121132 save_yaml (config , prometheus_yml_path )
0 commit comments