Skip to content

feat(metrics): publish module metric files - #1365

Merged
gsanchietti merged 2 commits into
mainfrom
simple_metrics
Oct 20, 2026
Merged

gsanchietti merged 2 commits into
mainfrom
simple_metrics

Conversation

@gsanchietti

@gsanchietti gsanchietti commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Applications need to publish small metrics of their own, like the result of the last backup, without running an extra exporter and opening a port for it. Related to NethServer/dev#8093.

A module ships an export-metrics command that prints its metrics in the Prometheus text format. Every 5 minutes a core timer on each node runs it for every module that has it, like module-dump-state for backups, and serves the output through the node exporter, which Prometheus already scrapes. No new port and no new scrape target are needed. The node adds a module="<id>" label to every sample. It does not check the format: module metrics are reviewed with the module code, and the node exporter skips invalid output of one module without affecting the others.

Changes

Added:

  • refresh-module-metrics node command, with its systemd service and a timer that runs it every 5 minutes. It runs runagent -m <id> export-metrics for each module that ships the command and writes node_exporter/module-<id>.prom
  • Rules: 30 seconds timeout per module, up to 4 modules at once in random order, each after a random delay of up to 5 seconds, no module or module_id label set by the module. A failed run keeps the last output and is logged. A run started while another one is in progress fails at once
  • prometheus-client 0.26.0 in the agent Python environment, so Python export-metrics commands can build valid output with the official library
  • Robot test
  • Developer manual page: docs/modules/metrics.md

Changed:

  • node_exporter.service wants the new timer; uninstall.sh stops it

Fixed:

  • generate-promtail-config used the missing agent.SD_ERROR constant, so its error paths crashed instead of logging

How to test

  • Add a command to a module: runagent -m traefik1 sh -c 'printf "#!/bin/sh\necho demo_value 42\n" > ../bin/export-metrics && chmod +x ../bin/export-metrics'
  • Run runagent -m node refresh-module-metrics, or wait up to 5 minutes: curl -s localhost:9100/metrics shows demo_value{module="traefik1"} 42
  • Make the command fail (exit 1): the value stays, and journalctl -u refresh-module-metrics logs the failure
  • Remove the command: its series disappear at the next run

See also


Generated by Claude Code:claude-opus-5-5 with nethserver-pr

@gsanchietti gsanchietti self-assigned this Oct 16, 2026
@gsanchietti
gsanchietti marked this pull request as ready for review October 16, 2026 12:10
@gsanchietti
gsanchietti force-pushed the simple_metrics branch 5 times, most recently from 62ba54a to 136ab07 Compare October 16, 2026 15:34

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments...

Comment thread docs/modules/metrics.md Resolved

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please just add a missing information in the docs.

Comment thread docs/modules/metrics.md Resolved
Modules can publish their own Prometheus metrics with an
export-metrics command, with no exporter and no open port.

Every 5 minutes refresh-module-metrics.timer runs
"runagent -m <id> export-metrics" for each module that ships the
command, like module-dump-state for backups. The output gets a
module="<id>" label and is written to
node_exporter/module-<id>.prom, so Prometheus scrapes it with the
node series.

- A failed or timed out run (30 seconds) keeps the last output
- Output that sets the module or module_id label is rejected
- node_exporter skips invalid output of one module only
- prometheus-client joins the agent Python environment

Assisted-by: Claude Code:claude-opus-5-5
agent.SD_ERROR does not exist: the two subuid error paths raised
AttributeError instead of logging the problem.

Assisted-by: Claude Code:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants