👌 IMPROVE: Add new health exporter targets configuration and update Prometheus to include the new health exporter job

This commit is contained in:
2025-05-23 09:30:33 +00:00
parent 945cae3908
commit 7f9f7b1aa4
4 changed files with 395 additions and 421 deletions

View File

@@ -28,6 +28,7 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PROMETHEUS_TARGETS_FILE = os.path.join(BASE_DIR, "config/hetzner_targets.json")
PHX_SYSTEM_FILE = os.path.join(BASE_DIR, "config/phoenix_system_hetzner_targets.json")
PHX_WORKER_FILE = os.path.join(BASE_DIR, "config/phoenix_worker_hetzner_targets.json")
PHX_HEALTH_EXPORTER_FILE = os.path.join(BASE_DIR, "config/phoenix_health_exporter_hetzner_targets.json")
DNS_MAPPING_FILE = os.path.join(BASE_DIR, "config/hetzner_dns_mapping.json")
ERROR_LOG_FILE = os.path.join(BASE_DIR, "config/hetzner_error_servers.json")
EXCLUDED_SERVERS_FILE = os.path.join(BASE_DIR, "config/hetzner_excluded_servers.json")
@@ -90,6 +91,7 @@ def generate_prometheus_sd_config():
targets = []
phx_system_targets = []
phx_worker_targets = []
phx_health_exporter_targets = []
error_servers = []
excluded_servers = []
dns_mappings = [] # New list for storing DNS-IP mappings
@@ -119,12 +121,11 @@ def generate_prometheus_sd_config():
})
# This is with Python Flask server for health checks
targets.append({
phx_health_exporter_targets.append({
"targets": [f"{ipv4}:9800"],
"labels": {
"instance": f"{server_name}",
"datacenter": datacenter,
"job": "health-exporter"
"instance": f"{server_name}-health-exporter",
"datacenter": datacenter
}
})
@@ -168,13 +169,17 @@ def generate_prometheus_sd_config():
print(f"✅ Updated Prometheus targets in {PROMETHEUS_TARGETS_FILE}")
with open(PHX_SYSTEM_FILE, "w") as f:
json.dump(phx_system_targets, f, indent=4)
print(f"✅ phoenix-system targets saved to {PHX_SYSTEM_FILE}")
with open(PHX_HEALTH_EXPORTER_FILE, "w") as f:
json.dump(phx_health_exporter_targets, f, indent=4)
print(f"✅ phoenix-health-exporter targets saved to {PHX_HEALTH_EXPORTER_FILE}")
with open(PHX_WORKER_FILE, "w") as f:
json.dump(phx_worker_targets, f, indent=4)
print(f"✅ phoenix-worker targets saved to {PHX_WORKER_FILE}")
# with open(PHX_SYSTEM_FILE, "w") as f:
# json.dump(phx_system_targets, f, indent=4)
# print(f"✅ phoenix-system targets saved to {PHX_SYSTEM_FILE}")
# with open(PHX_WORKER_FILE, "w") as f:
# json.dump(phx_worker_targets, f, indent=4)
# print(f"✅ phoenix-worker targets saved to {PHX_WORKER_FILE}")
# Save DNS Mappings file
with open(DNS_MAPPING_FILE, "w") as f: