👌 IMPROVE: Add heartbeat targets configuration for Prometheus monitoring and save to new JSON file

This commit is contained in:
2025-08-04 16:58:39 +02:00
parent 7f9f7b1aa4
commit ddfdb91401
3 changed files with 438 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ if not HETZNER_API_TOKEN:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
HEARTBEAT_TARGETS_FILE = os.path.join(BASE_DIR, "config/hetzner_heartbeat_targets.json")
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")
@@ -95,6 +96,7 @@ def generate_prometheus_sd_config():
error_servers = []
excluded_servers = []
dns_mappings = [] # New list for storing DNS-IP mappings
heartbeat_targets = []
for server in servers:
ipv4 = server.get("public_net", {}).get("ipv4", {}).get("ip")
@@ -129,6 +131,15 @@ def generate_prometheus_sd_config():
}
})
# Add Pushgateway heartbeat endpoint (default Pushgateway port is 9091)
heartbeat_targets.append({
"targets": [f"{ipv4}:9091"], # assuming Pushgateway is running on each server
"labels": {
"instance": server_name,
"job": "heartbeat"
}
})
# Phoenix System metrics (port 3000)
# phx_system_targets.append({
# "targets": [f"{ipv4}:3000"],
@@ -173,6 +184,10 @@ def generate_prometheus_sd_config():
json.dump(phx_health_exporter_targets, f, indent=4)
print(f"✅ phoenix-health-exporter targets saved to {PHX_HEALTH_EXPORTER_FILE}")
with open(HEARTBEAT_TARGETS_FILE, "w") as f:
json.dump(heartbeat_targets, f, indent=4)
print(f"✅ heartbeat targets saved to {HEARTBEAT_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}")