monitoring: loki ruler and log-based alerts #393
No reviewers
Labels
No labels
audit-work
bug
docs
general-admin
major-upgrade
needs-vps-sync
new-service
on-hold
outside-work
post-podman
renovate
upstream
vps
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mysticalsoap/docker!393
Loading…
Reference in a new issue
No description provided.
Delete branch "monitoring/loki-ruler"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Promtail ships Traefik, Authelia and Jellyfin logs into Loki, but Loki had no
rulerblock and no Alertmanager URL, so the logs could only be queried by hand. Closes #105.Fix
loki/config.yml:ruler.alertmanager_url, rules dir moved to/etc/loki/rulesand bind-mounted frommonitoring/loki/rules/(directory mount, so edits are live within the ruler's 1m poll). Thefake/tenant dir is explained in the config comment.monitoring/loki/rules/fake/alerts.yml,logsgroup:TraefikLogSilent(30m),AutheliaLogSilent(12h),JellyfinLogSilent(6h),AutheliaUnexpectedError. Windows and exclusions come from 7 days of Loki data; details in the commit body andMonitoring.md.loki:3100andpromtail:9080(TargetDown covers a dead ruler) and getsLokiRuleEvaluationFailing/LokiAlertmanagerNotifyFailing. There is no CI lint for the Loki rules file: the image ships nolokitooland promtool rejects LogQL.job=docker;docker_sd_configssets nojoblabel, so{job="docker"}matched nothing before.Monitoring.md: architecture line,logsgroup table, the Loki query-log gotcha (a container-wide pattern rule matches its own query text in{container="loki"}).Left out on purpose: a Traefik 5xx rule (status codes are already a metric label, belongs in
alerts.ymlif wanted) and any container-wide error-pattern rule (self-matching per the gotcha, anderror-ish lines run to hundreds a day for several containers).New mount is git-tracked, nothing for
includes.sh.Verification
just up monitoring, thenjust recreate prometheusandjust recreate promtail(bind-mounted single files, compose doesn't recreate on content change)./prometheus/api/v1/ruleson Loki: grouplogs, all four ruleshealth: ok,state: inactive;loki_ruler_managers_total 1,loki_prometheus_rule_evaluation_failures_total 0.LokiRulerTestrule (absent_over_time({job="nonexistent"}[5m]) == 1) appended to the rules file was picked up by the ruler without a restart, fired, and showed up in Alertmanager's/api/v2/alertswith its labels and annotations intact;loki_prometheus_notifications_sent_total 1,errors_total 0. Pre-silenced in Alertmanager so it never reached ntfy; rule and silence removed afterwards.absent_over_timeon a live job returns nothing, on a missing job returns 1. The Authelia rule returns nothing for the current 10m window; over the past 7 days it would have fired on five distinct messages (two OIDC client misconfigs, one LDAP startup-check failure and its fatal follow-up, one benignprompt=nonecase)./api/v1/targets:lokiandpromtailup; both new rulesok/inactive;promtool check rulespasses (36 rules)./loki/api/v1/label/job/valuesnow listsdocker.🤖 Generated with Claude Code
docker_sd_configs targets carry no job label, unlike static_configs, so {job="docker"} matched nothing and the container streams were only reachable through the compose labels. Chunks already written keep their old label set and age out with the 30d retention; no dashboard queries Loki yet, so nothing depends on either shape. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>