homek8s/infrastructure/logging/monitoring.yaml
Lance Walters e307f9dfd2 docs(logging): audit source, corrected measurements, pitfalls and acceptance evidence
- audit log section: allowlist fields, the two-retention-policies note, and the
  05:52-05:58 UTC incident (stage.pack leaked _entry; fixed, purged by wiping
  the PVC and resetting positions).
- measurements: 7.0x compression on the fresh store; two regimes (quiet 360
  MB/day, osint crawl 3.2 GB/day raw) -> <=3.7 GiB over 192h against an 8Gi PVC.
- pitfalls that cost real time: alloy validate does not catch component build
  errors, stage.json is JMESPath, stage.pack keeps _entry, file source needs an
  explicit timestamp stage, alloy positions path permissions.
- acceptance evidence: the real 7-day lines, per-source retained depth (incl.
  the honest 5d9h pod-log ceiling) and the restart test.
- alert threshold: 200 kB/s (was 12 MiB/s, which was ~50x too lax to mean
  anything against an 8Gi PVC).
2026-11-27 01:06:11 -05:00

72 lines
2.7 KiB
YAML

# Loki's own metrics -> Prometheus (scrape + ingest-rate guard).
#
# The ServiceMonitor sits in the monitoring namespace (where the Prometheus
# serviceMonitorSelector lives) and reaches the Service in `logging` through
# namespaceSelector, mirroring monitoring/controllers/home/garage.yaml.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: loki
namespace: monitoring
labels:
release: kube-prometheus-stack
app.kubernetes.io/part-of: logging
spec:
namespaceSelector:
matchNames:
- logging
selector:
matchLabels:
app.kubernetes.io/name: loki
endpoints:
- port: http
path: /metrics
interval: 60s
scrapeTimeout: 20s
---
# Storage is bounded by retention + the 8Gi PVC, but local-path does not
# enforce the PVC request, so the one number worth watching is the ingest rate:
# sustained ingest far above the measured baseline (~100 MiB/day) is what would
# eventually outrun chunk deletion. No Alertmanager is deployed in this stack,
# so this surfaces under Prometheus -> /alerts (the same posture as every other
# rule in monitoring/controllers/home/prune-alerts.yaml).
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: loki-ingest-guard
namespace: monitoring
labels:
release: kube-prometheus-stack
app.kubernetes.io/part-of: logging
spec:
groups:
- name: logging-storage
rules:
- alert: LokiIngestRateAboveBudget
# 200 kB/s raw ~= 17 GB/day ~= 2 GB/day compressed, which fills the
# 8Gi PVC inside the 192h window. Measured baselines: 4 kB/s quiet,
# ~37 kB/s during an osint crawl (2026-11-27, see docs/logging.md),
# so this only fires on a real runaway (log loop, debug left on).
expr: |
sum(rate(loki_distributor_bytes_received_total[30m])) > 200 * 1024
for: 1h
labels:
severity: warning
annotations:
summary: Loki ingest is above the storage budget
description: >-
Loki is receiving {{ $value | humanize1024 }}B/s (>200 kB/s), which
is ~17 GB/day raw — enough to fill the 8Gi PVC before the 192h
retention can delete anything. Either a workload started logging in
a loop, or retention / limits need revisiting before the disk does.
- alert: LokiDown
expr: up{job="loki"} == 0
for: 10m
labels:
severity: critical
annotations:
summary: Loki is not being scraped
description: >-
The log store is down: nothing is being written or queried, and
the 192h retention clock is no longer being maintained by the
compactor.