Skip to content

Commit

Permalink
promethus: new discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Feb 28, 2024
1 parent b6f38cc commit 0e528ba
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions imageroot/bin/metrics_exporter_handler
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import json
import os
import sys

import agent

if len(sys.argv) <= 1:
raise ValueError('Missing path to generate provider from.')

Expand All @@ -20,15 +18,17 @@ data = {
}

with os.scandir(sys.argv[1]) as it:
redis_client = agent.redis_connect(privileged=True)
for entry in it:
if entry.is_file():
data = {}
host = None
with open(entry, 'r', encoding='utf-8') as file:
host = file.readline()
module_id = os.environ["MODULE_ID"]
data['hosts'].append(f"{host}:19999")
redis_client.hset(
f'module/{module_id}/{entry.name}/srv/http/prometheus-metrics',
'config', json.dumps(data))
redis_client.publish(
f'module/{module_id}/event/service-prometheus-metrics-updated', '{}')
if data and host:
with open(f"prometheus.d/{host}.yml", 'w', encoding='utf-8') as file:
file.write('- targets:\n')
for target in data['hosts']:
file.write(f" - '{target}'\n")
file.write(' labels:\n')
file.write(f" unit: {entry.name}\n")

0 comments on commit 0e528ba

Please sign in to comment.