Add mon-exporter as scrape target in Prometheus
[osm/devops.git] / docker / Prometheus / src / app.py
index ff29151..b06f448 100755 (executable)
@@ -70,9 +70,20 @@ def generate_prometheus_config(prometheus_jobs, config_file_path):
     if "scrape_configs" not in config_file_yaml:
         config_file_yaml["scrape_configs"] = []
 
+    prometheus_jobs_to_be_added = []
+
     for prometheus_job in prometheus_jobs:
         cleaned_up_job = clean_up_job(prometheus_job)
-        config_file_yaml["scrape_configs"].append(cleaned_up_job)
+        job_to_be_added = True
+        for sc in config_file_yaml["scrape_configs"]:
+            if sc.get("job_name") == cleaned_up_job.get("job_name"):
+                job_to_be_added = False
+                break
+        if job_to_be_added:
+            prometheus_jobs_to_be_added.append(cleaned_up_job)
+
+    for job in prometheus_jobs_to_be_added:
+        config_file_yaml["scrape_configs"].append(job)
 
     return config_file_yaml
 
@@ -127,6 +138,7 @@ async def main_task(client):
     print(f"Writing new config file to {prometheus_config_file}")
     config_file = open(prometheus_config_file, "w")
     config_file.truncate(0)
+    print(yaml.safe_dump(generated_prometheus_config))
     config_file.write(yaml.safe_dump(generated_prometheus_config))
     config_file.close()
     print("New config written, updating prometheus")