stacks/monitoring/grafana/dashboards/caddy.json

{
  "title": "Homelab / Caddy",
  "uid": "homelab-caddy",
  "tags": ["homelab", "caddy", "http"],
  "schemaVersion": 39,
  "version": 3,
  "editable": false,
  "refresh": "30s",
  "time": { "from": "now-3h", "to": "now" },
  "templating": {
    "list": [
      {
        "name": "host",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "prom-homelab" },
        "query": "label_values(caddy_http_requests_total, host)",
        "includeAll": true,
        "multi": true,
        "refresh": 2
      }
    ]
  },
  "panels": [
    {
      "type": "stat",
      "title": "Requests/s",
      "id": 1,
      "gridPos": { "x": 0, "y": 0, "w": 6, "h": 4 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "sum(rate(caddy_http_requests_total{host=~\"$host\"}[5m]))",
          "refId": "A"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "reqps" } }
    },
    {
      "type": "stat",
      "title": "5xx rate",
      "id": 2,
      "gridPos": { "x": 6, "y": 0, "w": 6, "h": 4 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "sum(rate(caddy_http_requests_total{host=~\"$host\",code=~\"5..\"}[5m])) / sum(rate(caddy_http_requests_total{host=~\"$host\"}[5m]))",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 0.01 },
              { "color": "red", "value": 0.05 }
            ]
          }
        }
      }
    },
    {
      "type": "stat",
      "title": "p95 latency",
      "id": 3,
      "gridPos": { "x": 12, "y": 0, "w": 6, "h": 4 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "histogram_quantile(0.95, sum by (le) (rate(caddy_http_request_duration_seconds_bucket{host=~\"$host\"}[5m])))",
          "refId": "A"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "s" } }
    },
    {
      "type": "stat",
      "title": "Active connections",
      "id": 4,
      "gridPos": { "x": 18, "y": 0, "w": 6, "h": 4 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        { "expr": "sum(caddy_reverse_proxy_upstreams_healthy)", "refId": "A" }
      ]
    },
    {
      "type": "timeseries",
      "title": "Requests by status class",
      "id": 10,
      "gridPos": { "x": 0, "y": 4, "w": 12, "h": 10 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "sum by (code) (rate(caddy_http_requests_total{host=~\"$host\"}[5m]))",
          "legendFormat": "{{code}}",
          "refId": "A"
        }
      ]
    },
    {
      "type": "timeseries",
      "title": "Latency quantiles",
      "id": 11,
      "gridPos": { "x": 12, "y": 4, "w": 12, "h": 10 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "histogram_quantile(0.50, sum by (le) (rate(caddy_http_request_duration_seconds_bucket{host=~\"$host\"}[5m])))",
          "legendFormat": "p50",
          "refId": "A"
        },
        {
          "expr": "histogram_quantile(0.95, sum by (le) (rate(caddy_http_request_duration_seconds_bucket{host=~\"$host\"}[5m])))",
          "legendFormat": "p95",
          "refId": "B"
        },
        {
          "expr": "histogram_quantile(0.99, sum by (le) (rate(caddy_http_request_duration_seconds_bucket{host=~\"$host\"}[5m])))",
          "legendFormat": "p99",
          "refId": "C"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "s" } }
    },
    {
      "type": "timeseries",
      "title": "Requests by host",
      "id": 12,
      "gridPos": { "x": 0, "y": 14, "w": 12, "h": 10 },
      "datasource": { "type": "prometheus", "uid": "prom-homelab" },
      "targets": [
        {
          "expr": "sum by (host) (rate(caddy_http_requests_total[5m]))",
          "legendFormat": "{{host}}",
          "refId": "A"
        }
      ]
    },
    {
      "type": "logs",
      "title": "Recent 5xx",
      "id": 13,
      "gridPos": { "x": 12, "y": 14, "w": 12, "h": 10 },
      "datasource": { "type": "loki", "uid": "loki-homelab" },
      "targets": [
        {
          "expr": "{service=\"caddy\", status=~\"5..\"}",
          "refId": "A"
        }
      ],
      "options": { "showTime": true, "wrapLogMessage": true, "dedupStrategy": "none" }
    }
  ]
}