The Ansible Tour, Part 6: Monitoring – Exporters, Prometheus, Grafana and a Monit Watchdog

Part 6 of the Ansible Tour: how metrics flow, how the watchdog decides when to mail, and a table of every alarm mail with what to do.

Comic in the Ansible Tour series, route map with station 6: a watchdog sits in front of a wall of dashboards, the man at the desk reads an alert letter

🌐 Also available in: Deutsch · Français · Español · Italiano · Português · Nederlands · Polski

Part 6 of the Ansible Tour, and the last. After the platform, the applications and security, this part is about knowing what is going on. The series describes release v3.3.0 (opens in a new tab), with later changes added as addenda.

In short: Part 6, the last one of the Ansible (opens in a new tab) tour: this is about knowing what is going on. The setup watches in four ways – metrics with Prometheus (opens in a new tab) and Grafana (opens in a new tab), states with Monit, logs with Loki and Alloy, heartbeats for rare jobs –, all silent while everything is healthy. And all of them fell for the same mistake: they stayed quiet for a while because they could not speak.

A server nobody watches fails silently. The setup here watches in four ways, and it helps to keep them apart:

KindQuestionTool
MetricsHow is the server doing over time?exporters, Prometheus, Grafana
StatesIs something broken right now?Monit
LogsWhat happened, and why?Loki and Grafana Alloy
Signs of lifeIs what rarely reports anything still running at all?job timestamps, a weekly mail

All of them follow the rule from part 5: silent while everything is healthy, so that every mail means something. And all of them fell into the same trap: for a while they were silent because they could not speak, not because nothing was happening.

Table of Contents

📈 Metrics: exporters, Prometheus, Grafana

Where a point describes a change, a link leads to the commit that made it.

The model is pull: exporters offer their numbers as a text page over HTTP, Prometheus collects them every 15 seconds and keeps them for 30 days, Grafana draws the curves. Nothing leaves the server. The node exporter reports the host, a MariaDB exporter the database, a PHP-FPM exporter as a sidecar the PHP workers, cAdvisor in the kubelet every container, and kube-state-metrics limits, restarts and termination reasons from the API. Everything listens only locally or on ports the firewall drops from outside; only Grafana is reachable, through the ingress, with its own login and only from Germany.

The exporters are the clearest example of the pinned-binary pattern from part 2: read the installed version, download only on a mismatch with versions.yml, then restart. The downloaded archive in /tmp used to be the marker for “already installed” – after every reboot /tmp was empty, and every run downloaded again. Comparing the installed version with the pin is the honest test.

Prometheus evaluates its own alert rules but sends no mail; that would need Alertmanager, which is deliberately absent. The mails come from Grafana and Monit, and the configuration says so in its first lines, so that nobody waits for a mail that cannot come. Until the scrape jobs were split by stack, every server showed two targets permanently as “down” – the ports of the other stack. Harmless, but noise exactly where you look for real problems.

ansible-core ships no Grafana module (there is the community.grafana collection, which the repository does not use); the role talks to its HTTP API with the pattern “check first, then create”, because creating a data source twice creates two data sources. Dashboards are imported with a fixed ID, so that a re-import overwrites instead of copying. Three lessons are in this role:

  • Rules that could never fire. In September 2026 a check showed that no alert rule had ever fired – they lacked the field condition, and because an evaluation error counted as “OK”, they looked green. Since then the final check verifies the state of every rule.
  • A dashboard that never showed a number. The PHP-FPM dashboard 4912 from grafana.com filtered on labels from its authors’ own cluster; here every panel stayed empty. Since 26 October 2026 it is 25545, whose queries all return data here. The Grafana deep dive tells both stories. → d45ee44 (opens in a new tab)
  • A mail path that broke silently. The SMTP password contained a #, which started a comment in the configuration. Since 26 October a rule fires on purpose all the time and sends a mail once a week; if it is missing on Monday, the mail path is broken. → 5ab9bed (opens in a new tab), 6d50c21 (opens in a new tab)

Since release v3.3.0 there are curves per container as well: cAdvisor through a ServiceAccount whose only right is reading metrics, and kube-state-metrics with read-only rights. A dedicated dashboard sets every container against its limit, and four alerts watch memory, throttling, OOM kills and restart loops. A trap when reading: a query that sums over the container name adds the old and the new pod during a rollout – the right sum is per pod.

The takeaway: an alert that never fires and a panel that shows nothing look exactly like a healthy server. Check their state instead of trusting the silence.

🐕 common_monit: the watchdog

Monit exists because of an incident: fail2ban had died on the blog, and for two days nobody noticed. A dead service does not show up as a curve. Monit checks states: every two minutes it runs a list of checks, and it mails only when one changes from ok to failed or back. Because the same role runs on both stacks, it first asks with systemctl cat which services exist on this host and writes a check only for those.

  • Services and firewall: SSH, K3s, the exporters, Prometheus, Grafana; the firewall table with its ban sets; whether fail2ban and the sets have banned the same addresses.
  • Pods: crash loop, image pull error, OOM – short waiting states during a restart do not count.
  • fail2ban jails: whether every jail reads a log file that still exists.
  • Mail: since 26 October 2026, every mail msmtp could not deliver. Monit sends its own mails over its own SMTP connection, so that this alert gets through even when the msmtp path is broken.
  • Certificates: less than 21 days left. Renewal starts at 30 days; 21 means it has been failing for over a week. This threshold came about when an image policy silently blocked cert-manager’s challenge pod and it was only noticed shortly before expiry.
  • Backups: the external backup job updates a file on the server after every success; if it is older than three days, Monit raises an alert. The server cannot see the backup, but it can see that nobody told it about one.

Whether the watchdog barks is checked by a self-test on request: it briefly stops the node exporter, waits until Monit reports the failure, and starts it again – a real alert mail and a real all-clear mail.

The takeaway: states and metrics answer different questions. What does not show as a curve needs a check that reports only when something changes.

🔎 Logs, vulnerabilities and signs of life

Since 20 October 2026 two more roles run on all three servers. Loki and Grafana Alloy collect the journal, pod logs, the audit log and fail2ban’s log, for 14 days, searchable next to the metrics. Five log alerts report a blocked SELinux access, fail2ban errors, kernel OOM kills, missing logs and – since 26 October – an exceeded error budget: more than 100 error and warning lines of one service in an hour, known noise excluded. Before that, two exporters had written up to 240 such lines an hour each for days without anything raising an alert. Trivy scans all running images every night and mails only new fixable findings. Both have their own deep dives on Loki and Trivy. → b3b9e82 (opens in a new tab), 6b648fd (opens in a new tab)

The fourth kind of watching came last. Jobs that mail only on a finding – AIDE, rkhunter, ClamAV, the auditd notifier – are also silent when they no longer run at all; the auditd notifier once did that for six weeks. Since 26 October 2026 each of these jobs writes a timestamp after a successful run, Prometheus collects it, and an alert reports every job that is overdue. From the outside, a weekly script checks what a visitor sees: names, certificates, open ports, and whether a ban really takes effect.

The takeaway: silence is only good news if you know the sender is still alive.

🛠️ Running it: who mails what

FromMeaningWhat to do
Verify roleResult after every playbook runall green, or look at the failed checks
Grafanaa resource is getting short, a job is overdue, PHP-FPM is busyplan, do not panic; for an overdue job, find out why it did not run
Grafana “heartbeat”once a week, on purposenothing – if it is missing, the mail path is broken
Monitsomething is broken right nowlook at once
LokiSELinux denial, fail2ban error, OOM, no logs, error budgetread the matching lines in Grafana’s Explore
dnf-automatic, SSH alert, auditd, AIDE, rkhunter, ClamAV, Trivysee part 2 and part 5see there
  • Disk: look at the slope, not the level. A line that rises two percent a week reaches the 80 % alert on a predictable day.
  • Memory: “used” is always high because of the file cache; what counts is “available”.
  • PHP-FPM: when all workers are busy, requests queue up, however fast the server is. Two early warnings report 80 % busy workers and reaching max_children.

🎯 Conclusion: The lessons of part 6

  • Metrics, states, logs and signs of life answer different questions; you need all four.
  • An alert rule needs a checked state, not just a definition.
  • Check an imported dashboard against your own data first.
  • Every path that alerts travel needs a regular sign of life itself.
  • Aggregate container metrics per pod, not per container name.

🏁 The end of the tour

That is every role of the repository, the four playbooks, the inventory and the checks around them. Whoever has read all six parts knows what runs on these servers, why it is built this way, what went wrong along the way and what to do when a mail arrives. That was the goal: not that you copy this setup, but that it becomes understandable enough to run it – or to build your own and avoid the mistakes written down here.

The technology under the roles is explained in the deep dives, from SELinux and nftables through K3s to performance with measurements. The links in the tour point to release v3.3.0, so that they keep showing the code the text describes.

Addendum (28 November 2026): The www_k3s repository is now archived and has been split: the Nextcloud part lives on in nextcloud_k3s (opens in a new tab), the blog server in www_hugo (opens in a new tab). The links in this post point to the state at the time and still work.

Some text, images, videos and audio on this site are AI-assisted or AI-generated. Details