Skip to content

Commit 6d1e64a

Browse files
feat: announce metrics enpoint
Publish the Prometheus metrics endpoint configuration in Redis.
1 parent 3938755 commit 6d1e64a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) 2026 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
import os
9+
import yaml
10+
import agent
11+
12+
module_id = os.environ['MODULE_ID']
13+
agent_id = os.environ['AGENT_ID']
14+
node_id = int(os.environ['NODE_ID'])
15+
16+
def main():
17+
global module_id, node_id
18+
targets = [{
19+
"targets": [f"127.0.0.1:{os.environ['TCP_PORT']}"],
20+
"labels": {
21+
"module_id": module_id,
22+
"node": node_id, # no "_id" suffix for Metrics
23+
},
24+
}]
25+
update_metrics(targets)
26+
27+
def update_metrics(targets):
28+
global module_id, agent_id
29+
trx = agent.redis_connect(privileged=True).pipeline()
30+
trx.hset(f"module/{module_id}/metrics_targets", "loki", yaml.dump(targets))
31+
trx.publish(f"{agent_id}/event/metrics-target-changed", "{}")
32+
trx.execute()
33+
34+
if __name__ == "__main__":
35+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../actions/create-module/80provision_metrics

0 commit comments

Comments
 (0)