Skip to content

docs(ns8): add Prometheus troubleshooting - #44

Open
Stell0 wants to merge 3 commits into
NethServer:mainfrom
Stell0:docs/ns8-prometheus
Open

Stell0 wants to merge 3 commits into
NethServer:mainfrom
Stell0:docs/ns8-prometheus

Conversation

@Stell0

@Stell0 Stell0 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A live health check can miss short spikes that ended before a support investigation started. The NS8 admin skill now shows how to compare an incident with a baseline using the Metrics module’s Prometheus history. It covers the local authentication change in NethServer/dev#8390.

Run the read-only queries on the cluster leader in the Metrics module shell. The guide reads credentials from the module state for authenticated installations and uses the configured path on older installations. It shows how to check retention, find disk and container labels, and tell an empty result from an access failure.

How to test

  1. On a leader running legacy Metrics, run the retention and instant queries. Pick a disk and a container from the results and save both range queries for a UTC window within retention.
  2. Update Core first, then Metrics. An anonymous request to http://127.0.0.1:9091/-/healthy should return HTTP 401. Run the same guide commands with the module credentials and compare the results for the saved window.
  3. Check that Prometheus, Alertmanager, and Grafana are active and that the Core actions list-nodes and list-alerts succeed.

Verified on a single-node cluster upgraded from Core 3.25.1 and Metrics 1.7.1 to Core 3.26.0-dev.6 and Metrics 1.7.2-dev.2. Prometheus returned HTTP 401 anonymously and 200 with credentials. Both range queries returned all 16 samples for the same 15-minute window, with identical timestamps and values before and after the upgrade. The retention and instant queries, service checks, and both Core actions passed. A local fixture also covered a configured legacy prefix and a stale prefix with authenticated Metrics.


Generated by Codex:gpt-6.2-astra with nethserver-pr

Show how to use historical Metrics data to investigate an NS8 incident
after it ends. Include read-only examples for comparing disk activity
with container I/O and correlating the results with logs.

Assisted-by: Codex:gpt-6.2-sol
@Stell0 Stell0 self-assigned this Nov 24, 2026

@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.

The proposed skill is not accurate: the promtool queries fail when a Prometheus path is configured, the disk and container queries mix series from different nodes and modules, and some steps rely on wrong assumptions about how the Metrics module runs Prometheus. See the inline comments.

Please test the skill in a real multi-node cluster before submitting it again.

its Prometheus history to compare the affected window with a baseline before
and after it. Resolve the module ID and node from `api-cli run
list-installed-modules`, then confirm the running Prometheus container in that
module's Podman context. The commands below use `metrics1` as an example.

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.

Suggested change
module's Podman context. The commands below use `metrics1` as an example.
module's Podman context. The commands below use `metrics1` as an example.
Note that a Metrics instance always run on the leader node.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The guide now states that Metrics runs on the cluster leader and tells the reader to run the checks there.

Comment on lines +47 to +50
runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (job) (up)'
runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (__name__) ({__name__=~"ns8_container_.*|node_disk_.*_total"})'
runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 '100 * max(rate(node_disk_io_time_seconds_total[3m]))'
runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 'max(rate(ns8_container_blkio_bytes_total{container="mariadb",device="sda",op="read"}[3m]))/1048576'

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.

These queries return 404 when the Metrics module has a Prometheus path configured (prometheus_path). prometheus.service hardcodes --web.external-url=/${PROMETHEUS_PATH}/ --web.listen-address=127.0.0.1:9091, so the HTTP API is always at http://127.0.0.1:9091/${PROMETHEUS_PATH}, not at the bare address. The agent would then wrongly conclude that the history is unavailable.

Suggestion: read the path with runagent -m metrics1 printenv PROMETHEUS_PATH (empty when Prometheus is not exposed through Traefik) and use http://127.0.0.1:9091/<path> as the base URL, as provision-grafana and reload-prometheus-rules do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The examples now read PROMETHEUS_PATH in the Metrics module context and reuse the resulting base URL for each query. I tested both the root URL and a configured prefix with local Prometheus and promtool, using synthetic metrics for multiple nodes and modules. The real multi-node NS8 test is still pending.

```bash
runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (job) (up)'
runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (__name__) ({__name__=~"ns8_container_.*|node_disk_.*_total"})'
runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 '100 * max(rate(node_disk_io_time_seconds_total[3m]))'

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.

max(rate(node_disk_io_time_seconds_total[3m])) has no node or device filter, so it takes the peak across all cluster nodes and all block devices (sda, dm-*, loop, sr...). A busy disk on a worker would be blamed on the node where the incident happened, and with LVM the max hides which layer was busy, against the "choose one device layer" advice below.

Suggestion: filter with {node="<node>",device="<dev>"}, or use max by (node, device) so the result names the busy node and device.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The disk query now selects the affected node and device. In the local test it returned the intended disk’s 50% busy time even with busier disks on the same node and on another node.

runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (job) (up)'
runagent -m metrics1 podman exec prometheus promtool query instant http://127.0.0.1:9091 'count by (__name__) ({__name__=~"ns8_container_.*|node_disk_.*_total"})'
runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 '100 * max(rate(node_disk_io_time_seconds_total[3m]))'
runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 'max(rate(ns8_container_blkio_bytes_total{container="mariadb",device="sda",op="read"}[3m]))/1048576'

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.

The container label is only the container name and is not unique: several modules can run a container named mariadb, possibly on different nodes. max() drops the module and node labels, so the result can come from another module without saying so.

Suggestion: also filter on module="<module_id>" (and node), or use max by (node, module), as the ns8-metrics containers dashboard does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The container query now filters by node, module, container, device, and operation. The local test selected the intended container even when other modules on the same node and on another node also had a mariadb container.

Comment on lines +60 to +61
diagnostics. Through Gate, submit each command separately and honor its
approval result.

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.

"Gate" is not defined anywhere in this skill or repo: it looks carried over from a specific agent setup. An agent following this sentence cannot know what Gate is or how to honor its approval result. Please remove it, or reference where it is defined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the Gate instruction.

Comment on lines +41 to +42
An empty port listing can mean the listener is available only inside the
container. Use the loopback address and port confirmed by

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.

prometheus.service runs Prometheus with --network=host and hardcodes --web.listen-address=127.0.0.1:9091, so podman port prometheus is always empty and the listener is always the host loopback, not "only inside the container". There is nothing to discover here: drop the podman port step (line 36) and state the fixed address directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed podman port and documented host networking and the fixed listener at 127.0.0.1:9091 on the leader.

```bash
runagent -m metrics1 podman ps -a
runagent -m metrics1 podman port prometheus
runagent -m metrics1 podman inspect prometheus --format '{{json .Args}}'

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.

This step is unnecessary: prometheus.service hardcodes both --web.listen-address=127.0.0.1:9091 and --web.external-url=/${PROMETHEUS_PATH}/, so the args carry nothing the agent cannot know already. Dumping them also exposes the Traefik path, which is meant to be hard to guess, and it could end up in the incident report. Suggestion: remove the podman inspect line and the "Inspect only the needed startup argument" sentence; get the path from PROMETHEUS_PATH instead (see the comment on the promtool queries).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed podman inspect. The guide reads only PROMETHEUS_PATH and tells the reader to omit the path and full URL from the incident report.

runagent -m metrics1 podman exec prometheus promtool query range --start=2026-01-01T10:00:00Z --end=2026-01-01T11:00:00Z --step=60s http://127.0.0.1:9091 'max(rate(ns8_container_blkio_bytes_total{container="mariadb",device="sda",op="read"}[3m]))/1048576'
```

Replace the example interval with the incident timestamps in UTC, and use

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.

"Within the available retention" is not actionable as written: the agent has no way to tell expired or missing history from "no activity". Retention is 15 days by default, and the ns8-metrics README says the module is removed from a leader that becomes a worker, so history can also end at a leader switch.

Suggestion: add a check of the oldest sample, e.g. prometheus_tsdb_lowest_timestamp_seconds, and mention both cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The guide now checks prometheus_tsdb_lowest_timestamp_seconds and explains how default retention and leader changes can limit the available history. Missing samples leave that part of the window unverified.

@DavidePrincipi

Copy link
Copy Markdown
Member

See NethServer/dev#8390

Use the Metrics leader and configured path for local queries.
Scope disk and container results to the affected series and check
how much of the incident window the server still has.

Assisted-by: Codex:gpt-6.2-sol
Use the Metrics instance credentials for local history queries and
keep the configured path usable on older installations. Distinguish
access failures from a successful query with no samples.

Assisted-by: Codex:gpt-6.2-astra
@Stell0
Stell0 requested a review from DavidePrincipi December 3, 2026 17:59
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