-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(monitoring): integrate metrics inside the core (#816)
Changes: - removed the node-monitor service - node_exporter is now a core module and installed on all modules: virtual filesystems are not monitored to avoid false alerts on partition free space - on update, install the new metrics module and remove existing node_exporter instances to avoid conflicts on port 9100 - metrics module is installed and running only on the leader node - switch-leader makes sure there is only one instance of metrics module inside the cluster --------- Co-authored-by: Davide Principi <[email protected]>
- Loading branch information
1 parent
06c1fe7
commit f535979
Showing
18 changed files
with
253 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[Unit] | ||
Description=Prometheus node_exporter | ||
|
||
[Service] | ||
Type=forking | ||
Environment=PODMAN_SYSTEMD_UNIT=%n | ||
EnvironmentFile=-/etc/nethserver/core.env | ||
WorkingDirectory=/var/lib/nethserver/node/state | ||
Restart=always | ||
ExecStartPre=/bin/rm -f %t/%N.pid %t/%N.cid | ||
ExecStartPre=/usr/bin/mkdir -p /run/node_exporter | ||
ExecStart=/usr/bin/podman run \ | ||
--conmon-pidfile %t/%N.pid \ | ||
--cidfile %t/%N.cid \ | ||
--cgroups=no-conmon \ | ||
--replace \ | ||
--name %N \ | ||
--network=host \ | ||
--pid=host \ | ||
-d \ | ||
-v /:/host:ro,rslave \ | ||
${NODE_EXPORTER_IMAGE} \ | ||
--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|run)($|/) \ | ||
--collector.textfile.directory=/host/run/node_exporter \ | ||
--path.rootfs=/host | ||
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/%N.cid -t 10 | ||
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/%N.cid | ||
PIDFile=%t/%N.pid | ||
|
||
[Install] | ||
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
core/imageroot/var/lib/nethserver/cluster/actions/create-cluster/70start_node_exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
set -e | ||
exec 1>&2 | ||
|
||
systemctl enable --now node_exporter.service |
1 change: 1 addition & 0 deletions
1
core/imageroot/var/lib/nethserver/cluster/actions/join-node/70start_node_exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../create-cluster/70start_node_exporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/imageroot/var/lib/nethserver/cluster/update-core-post-modules.d/70metrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import agent | ||
import agent.tasks | ||
import os | ||
import re | ||
|
||
rdb = agent.redis_connect(privileged=True) | ||
is_metrics_installed = rdb.exists(f"node/{os.getenv('NODE_ID')}/default_instance/metrics") | ||
|
||
if not is_metrics_installed: | ||
# Remove node_exporter modules: they will conflict with the new metrics module | ||
for module in rdb.hgetall("cluster/module_node").items(): | ||
# if module name matches node_exporter<number>, remove it | ||
if re.match(r"node_exporter\d+", module[0]): | ||
agent.tasks.run('cluster', 'remove-module', data={ | ||
"module_id": module[0], | ||
"preserve_data": False, | ||
"force": True, | ||
}, endpoint="redis://cluster-leader") | ||
|
||
# Install metrics module | ||
add_module_failures = agent.tasks.runp_brief([ | ||
{"agent_id": "cluster", "action": "add-module", "data": { | ||
'image': 'metrics', | ||
'node': int(os.getenv("NODE_ID")), | ||
}}], | ||
endpoint = "redis://cluster-leader", | ||
) | ||
agent.assert_exp(add_module_failures == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.