{
    "title": "HTTP Service Health",
    "description": "RED method golden signals — request rate, error rate, and latency for HTTP services",
    "tags": ["http", "grafana-lens", "service"],
    "timezone": "browser",
    "editable": true,
    "schemaVersion": 39,
    "time": { "from": "now-6h", "to": "now" },
    "refresh": "30s",
    "templating": {
        "list": [
            {
                "name": "datasource",
                "type": "datasource",
                "query": "prometheus",
                "current": {},
                "hide": 0
            },
            {
                "name": "job",
                "type": "query",
                "datasource": { "type": "prometheus", "uid": "$datasource" },
                "query": "label_values(http_requests_total, job)",
                "refresh": 1,
                "includeAll": true,
                "multi": true,
                "current": {},
                "hide": 0,
                "sort": 1
            }
        ]
    },
    "panels": [
        {
            "id": 1,
            "title": "Request Rate",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 0, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(http_requests_total{job=~\"$job\"}[5m]))",
                    "legendFormat": "req/s",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "reqps"
                }
            }
        },
        {
            "id": 2,
            "title": "Error Rate %",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 6, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(http_requests_total{job=~\"$job\",code=~\"5..\"}[5m])) / sum(rate(http_requests_total{job=~\"$job\"}[5m])) * 100",
                    "legendFormat": "errors %",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            { "color": "green", "value": null },
                            { "color": "yellow", "value": 1 },
                            { "color": "red", "value": 5 }
                        ]
                    }
                }
            }
        },
        {
            "id": 3,
            "title": "P95 Latency",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 12, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job=~\"$job\"}[5m])) by (le))",
                    "legendFormat": "p95",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "s"
                }
            }
        },
        {
            "id": 4,
            "title": "Availability",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 18, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "(1 - (sum(rate(http_requests_total{job=~\"$job\",code=~\"5..\"}[5m])) / sum(rate(http_requests_total{job=~\"$job\"}[5m])))) * 100",
                    "legendFormat": "uptime",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            { "color": "red", "value": null },
                            { "color": "yellow", "value": 99 },
                            { "color": "green", "value": 99.9 }
                        ]
                    }
                }
            }
        },
        {
            "id": 5,
            "title": "Request Rate Over Time",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 0, "y": 4 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(http_requests_total{job=~\"$job\"}[5m])) by (handler)",
                    "legendFormat": "{{ handler }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "reqps",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        },
        {
            "id": 6,
            "title": "Error Rate Over Time",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 12, "y": 4 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(http_requests_total{job=~\"$job\",code=~\"5..\"}[5m])) by (handler)",
                    "legendFormat": "{{ handler }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "reqps",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        },
        {
            "id": 7,
            "title": "Latency Percentiles",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 0, "y": 12 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket{job=~\"$job\"}[5m])) by (le))",
                    "legendFormat": "p50",
                    "refId": "A"
                },
                {
                    "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job=~\"$job\"}[5m])) by (le))",
                    "legendFormat": "p95",
                    "refId": "B"
                },
                {
                    "expr": "histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket{job=~\"$job\"}[5m])) by (le))",
                    "legendFormat": "p99",
                    "refId": "C"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "s",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        },
        {
            "id": 8,
            "title": "Response Codes",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 12, "y": 12 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(http_requests_total{job=~\"$job\"}[5m])) by (code)",
                    "legendFormat": "{{ code }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "reqps",
                    "custom": {
                        "fillOpacity": 50,
                        "stacking": { "mode": "normal" }
                    }
                }
            }
        }
    ]
}
