← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Prometheus & Grafana

Observability PHP 7.0+ Advanced
debt(d8/e5/b4/t6)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production' (d8) — missing metrics or high-cardinality labels won't surface until production incidents or Prometheus itself crashes; no automated tool flags absence of a /metrics endpoint.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' to 'multiple files' (e5) — adding promphp/prometheus_client_php and exposing /metrics is straightforward, but instrumenting meaningful business metrics (histograms, counters, gauges) touches multiple components across web/cli/queue contexts.

b4 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' to 'persistent tax' (b4) — metrics instrumentation is mostly additive and isolated to instrumentation points, but cardinality discipline and dashboard maintenance impose ongoing tax across the codebase per applies_to scope.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t6) — per misconception, devs assume Prometheus is K8s-only; plus the high-cardinality label trap (user_id as label) is catastrophic and counterintuitive since labels feel like normal tags, slightly less than t7.

About DEBT scoring →

Also Known As

PromQL Prometheus metrics Grafana dashboard

TL;DR

Prometheus scrapes and stores time-series metrics; Grafana visualises them — together they provide open-source metrics monitoring and alerting for any application.

Explanation

Prometheus pulls metrics from /metrics endpoints exposed by applications (pull model). Metric types: Counter (monotonically increasing, e.g. request count), Gauge (current value, e.g. active connections), Histogram (distribution, e.g. request duration percentiles), Summary. PromQL queries aggregate and alert on metrics. Grafana connects to Prometheus as a data source and provides dashboards. For PHP, the prometheus_client_php library exposes metrics; Blackfire and Datadog offer hosted alternatives.

Diagram

flowchart LR
    APP[PHP App] -->|expose /metrics| PROM[(Prometheus<br/>scrapes every 15s)]
    PROM -->|PromQL queries| GRAF[Grafana<br/>dashboards]
    PROM -->|alert rules| ALERT[Alertmanager]
    ALERT -->|PagerDuty Slack| ONCALL[On-call engineer]
    subgraph Metrics_Flow
        COUNTER[Counter<br/>requests_total]
        HIST[Histogram<br/>request_duration]
        GAUGE[Gauge<br/>active_connections]
    end
    APP --> COUNTER & HIST & GAUGE
style PROM fill:#d29922,color:#fff
style GRAF fill:#1f6feb,color:#fff
style ALERT fill:#f85149,color:#fff
style ONCALL fill:#238636,color:#fff

Common Misconception

Prometheus is only for Kubernetes — it works with any application that exposes a /metrics endpoint; PHP apps running on VMs or Docker can expose metrics just as easily.

Why It Matters

Without metrics, you cannot answer 'is this slow right now?', 'how many 500 errors per minute?', or 'what is our 99th percentile response time?' — Prometheus makes these questions instant.

Common Mistakes

  • High-cardinality label values — using user_id or request_id as Prometheus labels creates millions of time series, crashing Prometheus.
  • Not using histograms for latency — average latency hides tail latency; histograms expose P95/P99.
  • Scrape interval too long — 60s interval misses sub-minute spikes; 15s is typical.
  • Not setting alert thresholds based on historical data — arbitrary thresholds create alert fatigue.

Code Examples

✗ Vulnerable
// High-cardinality label — DO NOT DO THIS:
$histogram->observe($duration, ['user_id' => $userId]); // 1M users = 1M time series
// Prometheus OOMs and crashes with too many series
✓ Fixed
// Low-cardinality labels only:
$histogram->observe($duration, [
    'route'  => '/api/users',    // ~20 routes — OK
    'method' => 'GET',           // ~5 methods — OK
    'status' => '200',           // ~10 status codes — OK
]);
// NOT: user_id, request_id, session_id — too many unique values

Added 15 Mar 2026
Edited 22 Mar 2026
Views 75
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 1 ping M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 1 ping W 1 ping T 0 pings F
No pings yet today
SEMrush 1
Scrapy 14 Amazonbot 7 SEMrush 6 Ahrefs 5 Perplexity 5 Google 4 Bing 4 PetalBot 3 Unknown AI 2 ChatGPT 2 Twitter/X 2 Meta AI 1 Applebot 1
crawler 52 crawler_json 4
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Expose a /metrics endpoint with promphp/prometheus_client_php — track request_duration_seconds histogram, error_total counter, and queue_depth gauge as your starting three metrics
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
No /metrics endpoint; no custom business metrics; only infrastructure CPU memory metrics without request latency error rate
Auto-detectable: ✗ No prometheus grafana promtail loki
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant