{
  "dashboard": {
    "title": "DBIS Core - API Performance",
    "tags": ["api", "performance", "latency"],
    "timezone": "browser",
    "schemaVersion": 27,
    "version": 1,
    "refresh": "30s",
    "panels": [
      {
        "id": 1,
        "title": "Request Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total{job=\"dbis-core\"}[5m])) by (endpoint)",
            "legendFormat": "{{endpoint}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}
      },
      {
        "id": 2,
        "title": "Response Time Percentiles",
        "type": "graph",
        "targets": [
          {
            "expr": "histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket{job=\"dbis-core\"}[5m])) by (le, endpoint))",
            "legendFormat": "{{endpoint}} - P50"
          },
          {
            "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job=\"dbis-core\"}[5m])) by (le, endpoint))",
            "legendFormat": "{{endpoint}} - P95"
          },
          {
            "expr": "histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket{job=\"dbis-core\"}[5m])) by (le, endpoint))",
            "legendFormat": "{{endpoint}} - P99"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}
      },
      {
        "id": 3,
        "title": "Error Rate by Endpoint",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total{job=\"dbis-core\",status=~\"5..\"}[5m])) by (endpoint)",
            "legendFormat": "{{endpoint}} - 5xx"
          },
          {
            "expr": "sum(rate(http_requests_total{job=\"dbis-core\",status=~\"4..\"}[5m])) by (endpoint)",
            "legendFormat": "{{endpoint}} - 4xx"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}
      },
      {
        "id": 4,
        "title": "Top Endpoints by Request Volume",
        "type": "bargraph",
        "targets": [
          {
            "expr": "topk(10, sum(rate(http_requests_total{job=\"dbis-core\"}[5m])) by (endpoint))",
            "legendFormat": "{{endpoint}}"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}
      },
      {
        "id": 5,
        "title": "Request Rate by Method",
        "type": "piechart",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total{job=\"dbis-core\"}[5m])) by (method)",
            "legendFormat": "{{method}}"
          }
        ],
        "gridPos": {"h": 8, "w": 8, "x": 0, "y": 16}
      },
      {
        "id": 6,
        "title": "Request Rate by Status Code",
        "type": "piechart",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total{job=\"dbis-core\"}[5m])) by (status)",
            "legendFormat": "{{status}}"
          }
        ],
        "gridPos": {"h": 8, "w": 8, "x": 8, "y": 16}
      },
      {
        "id": 7,
        "title": "SLO Compliance - Availability",
        "type": "stat",
        "targets": [
          {
            "expr": "(1 - (sum(rate(http_requests_total{job=\"dbis-core\",status=~\"5..\"}[5m])) / sum(rate(http_requests_total{job=\"dbis-core\"}[5m])))) * 100",
            "legendFormat": "Availability %"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "red"},
                {"value": 99.9, "color": "yellow"},
                {"value": 99.99, "color": "green"}
              ]
            },
            "unit": "percent"
          }
        },
        "gridPos": {"h": 4, "w": 4, "x": 16, "y": 16}
      },
      {
        "id": 8,
        "title": "SLO Compliance - P95 Latency",
        "type": "stat",
        "targets": [
          {
            "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job=\"dbis-core\"}[5m])) by (le))",
            "legendFormat": "P95 Latency"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "green"},
                {"value": 0.5, "color": "yellow"},
                {"value": 1.0, "color": "red"}
              ]
            },
            "unit": "s"
          }
        },
        "gridPos": {"h": 4, "w": 4, "x": 20, "y": 16}
      },
      {
        "id": 9,
        "title": "Request Duration Distribution",
        "type": "heatmap",
        "targets": [
          {
            "expr": "sum(rate(http_request_duration_seconds_bucket{job=\"dbis-core\"}[5m])) by (le)",
            "legendFormat": "{{le}}"
          }
        ],
        "gridPos": {"h": 8, "w": 24, "x": 0, "y": 24}
      }
    ]
  }
}
