##
## Grafana Dashboard ConfigMap — Fogbreak AI Inference
##
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-dashboards
  namespace: fogbreak-ai
data:
  fogbreak-ai.json: |
    {
      "dashboard": {
        "id": null,
        "uid": "fogbreak-ai-inference",
        "title": "Fogbreak AI Inference",
        "tags": ["fogbreak", "ai", "vllm"],
        "timezone": "browser",
        "refresh": "30s",
        "time": {
          "from": "now-1h",
          "to": "now"
        },
        "panels": [
          {
            "id": 1,
            "title": "Total Requests / min",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 0, "y": 0 },
            "targets": [
              {
                "expr": "rate(fogbreak_ai_requests_total[1m]) * 60",
                "legendFormat": "req/min"
              }
            ]
          },
          {
            "id": 2,
            "title": "Error Rate",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 6, "y": 0 },
            "targets": [
              {
                "expr": "rate(fogbreak_ai_errors_total[5m]) / rate(fogbreak_ai_requests_total[5m])",
                "legendFormat": "error %"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "unit": "percentunit",
                "thresholds": {
                  "mode": "absolute",
                  "steps": [
                    { "color": "green", "value": null },
                    { "color": "yellow", "value": 0.01 },
                    { "color": "red", "value": 0.05 }
                  ]
                }
              }
            }
          },
          {
            "id": 3,
            "title": "Token Throughput",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 12, "y": 0 },
            "targets": [
              {
                "expr": "rate(fogbreak_ai_tokens_out_total[1m]) * 60",
                "legendFormat": "tokens/min"
              }
            ]
          },
          {
            "id": 4,
            "title": "Endpoint Health",
            "type": "stat",
            "gridPos": { "h": 4, "w": 6, "x": 18, "y": 0 },
            "targets": [
              {
                "expr": "fogbreak_ai_endpoint_healthy",
                "legendFormat": "{{ endpoint }}"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "mappings": [
                  { "type": "value", "options": { "0": { "text": "DOWN", "color": "red" }, "1": { "text": "UP", "color": "green" } } }
                ]
              }
            }
          },
          {
            "id": 5,
            "title": "Inference Latency by Endpoint",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 0, "y": 4 },
            "targets": [
              {
                "expr": "fogbreak_ai_endpoint_latency_ms",
                "legendFormat": "{{ endpoint }} ({{ type }})"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "unit": "ms",
                "custom": {
                  "drawStyle": "line",
                  "lineInterpolation": "smooth"
                }
              }
            }
          },
          {
            "id": 6,
            "title": "Requests by Endpoint",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 12, "y": 4 },
            "targets": [
              {
                "expr": "rate(fogbreak_ai_endpoint_requests[5m])",
                "legendFormat": "{{ endpoint }}"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "custom": {
                  "drawStyle": "bars",
                  "stacking": { "mode": "normal" }
                }
              }
            }
          },
          {
            "id": 7,
            "title": "GPU Memory Usage",
            "type": "gauge",
            "gridPos": { "h": 6, "w": 12, "x": 0, "y": 12 },
            "targets": [
              {
                "expr": "DCGM_FI_DEV_FB_USED / DCGM_FI_DEV_FB_TOTAL",
                "legendFormat": "GPU {{ gpu }}"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "unit": "percentunit",
                "min": 0,
                "max": 1,
                "thresholds": {
                  "mode": "absolute",
                  "steps": [
                    { "color": "green", "value": null },
                    { "color": "yellow", "value": 0.8 },
                    { "color": "red", "value": 0.95 }
                  ]
                }
              }
            }
          },
          {
            "id": 8,
            "title": "GPU Utilization",
            "type": "gauge",
            "gridPos": { "h": 6, "w": 12, "x": 12, "y": 12 },
            "targets": [
              {
                "expr": "DCGM_FI_DEV_GPU_UTIL",
                "legendFormat": "GPU {{ gpu }}"
              }
            ],
            "fieldConfig": {
              "defaults": {
                "unit": "percent",
                "min": 0,
                "max": 100,
                "thresholds": {
                  "mode": "absolute",
                  "steps": [
                    { "color": "green", "value": null },
                    { "color": "yellow", "value": 70 },
                    { "color": "red", "value": 90 }
                  ]
                }
              }
            }
          },
          {
            "id": 9,
            "title": "Tokens In vs Out",
            "type": "timeseries",
            "gridPos": { "h": 6, "w": 24, "x": 0, "y": 18 },
            "targets": [
              {
                "expr": "rate(fogbreak_ai_tokens_in_total[5m])",
                "legendFormat": "Tokens In (prompt)"
              },
              {
                "expr": "rate(fogbreak_ai_tokens_out_total[5m])",
                "legendFormat": "Tokens Out (completion)"
              }
            ]
          }
        ]
      }
    }
