{
  "annotations": {
    "list": []
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "links": [
    {
      "asDropdown": false,
      "icon": "external link",
      "includeVars": true,
      "keepTime": true,
      "tags": ["llmhosts"],
      "targetBlank": false,
      "title": "LLMHosts Dashboards",
      "type": "dashboards"
    }
  ],
  "panels": [
    {
      "title": "Backend Health Status",
      "type": "stat",
      "gridPos": { "h": 6, "w": 24, "x": 0, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "llmhost_backend_healthy",
          "legendFormat": "{{ backend }}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "mappings": [
            { "type": "value", "options": { "0": { "text": "DOWN", "color": "red" }, "1": { "text": "UP", "color": "green" } } }
          ],
          "thresholds": {
            "steps": [
              { "color": "red", "value": null },
              { "color": "green", "value": 1 }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "graphMode": "none",
        "colorMode": "background",
        "textMode": "auto",
        "orientation": "horizontal"
      }
    },
    {
      "title": "Active Backends",
      "type": "stat",
      "gridPos": { "h": 6, "w": 6, "x": 0, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "active_backends",
          "legendFormat": "Active"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "steps": [
              { "color": "red", "value": null },
              { "color": "green", "value": 1 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "title": "Total Cost (USD)",
      "type": "stat",
      "gridPos": { "h": 6, "w": 6, "x": 6, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "llmhost_cost_dollars_total",
          "legendFormat": "Total Cost"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "currencyUSD",
          "color": { "mode": "thresholds" },
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 10 },
              { "color": "red", "value": 100 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "title": "Total Savings (USD)",
      "type": "stat",
      "gridPos": { "h": 6, "w": 6, "x": 12, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "llmhost_savings_dollars_total",
          "legendFormat": "Total Savings"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "currencyUSD",
          "color": { "mode": "thresholds" },
          "thresholds": {
            "steps": [
              { "color": "green", "value": null }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "title": "Total Tokens",
      "type": "stat",
      "gridPos": { "h": 6, "w": 6, "x": 18, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum(llm_tokens_total)",
          "legendFormat": "Tokens"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "short"
        },
        "overrides": []
      }
    },
    {
      "title": "Requests by Backend",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 0, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum by (backend) (rate(llm_requests_total[5m]))",
          "legendFormat": "{{ backend }}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "custom": { "drawStyle": "bars", "fillOpacity": 80, "lineWidth": 0, "stacking": { "mode": "normal" } }
        },
        "overrides": []
      }
    },
    {
      "title": "Requests by Model",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 12, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum by (model) (rate(llm_requests_total[5m]))",
          "legendFormat": "{{ model }}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "custom": { "drawStyle": "bars", "fillOpacity": 80, "lineWidth": 0, "stacking": { "mode": "normal" } }
        },
        "overrides": []
      }
    },
    {
      "title": "Tokens by Backend",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 0, "y": 22 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum by (backend) (rate(llm_tokens_total[5m]))",
          "legendFormat": "{{ backend }}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": { "drawStyle": "line", "fillOpacity": 15, "lineWidth": 2 }
        },
        "overrides": []
      }
    },
    {
      "title": "Cost by Backend (USD)",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 12, "y": 22 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum by (backend) (rate(llm_cost_usd_total[5m])) * 3600",
          "legendFormat": "{{ backend }} $/hr"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "currencyUSD",
          "custom": { "drawStyle": "line", "fillOpacity": 15, "lineWidth": 2 }
        },
        "overrides": []
      }
    },
    {
      "title": "Request Latency (P50 / P95 / P99)",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 0, "y": 32 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "histogram_quantile(0.50, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))",
          "legendFormat": "P50"
        },
        {
          "expr": "histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))",
          "legendFormat": "P95"
        },
        {
          "expr": "histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))",
          "legendFormat": "P99"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": { "drawStyle": "line", "fillOpacity": 5, "lineWidth": 2 }
        },
        "overrides": []
      }
    },
    {
      "title": "Error Rate by Status Code",
      "type": "timeseries",
      "gridPos": { "h": 10, "w": 12, "x": 12, "y": 32 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "sum by (status) (rate(http_requests_total{status=~\"4..|5..\"}[5m]))",
          "legendFormat": "HTTP {{ status }}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "custom": { "drawStyle": "bars", "fillOpacity": 80, "lineWidth": 0, "stacking": { "mode": "normal" } }
        },
        "overrides": []
      }
    },
    {
      "title": "CPU Usage",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 8, "x": 0, "y": 42 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "100 - (avg(rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)",
          "legendFormat": "CPU %"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "min": 0,
          "max": 100,
          "custom": { "drawStyle": "line", "fillOpacity": 20, "lineWidth": 2 },
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 60 },
              { "color": "red", "value": 80 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "title": "Memory Usage",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 8, "x": 8, "y": 42 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100",
          "legendFormat": "Memory %"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "min": 0,
          "max": 100,
          "custom": { "drawStyle": "line", "fillOpacity": 20, "lineWidth": 2 },
          "thresholds": {
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 70 },
              { "color": "red", "value": 85 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "title": "Uptime",
      "type": "stat",
      "gridPos": { "h": 8, "w": 8, "x": 16, "y": 42 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "targets": [
        {
          "expr": "llmhost_uptime_seconds",
          "legendFormat": "Uptime"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s"
        },
        "overrides": []
      }
    }
  ],
  "schemaVersion": 39,
  "tags": ["llmhosts", "backends", "cost"],
  "templating": {
    "list": [
      {
        "name": "DS_PROMETHEUS",
        "type": "datasource",
        "query": "prometheus",
        "current": { "text": "Prometheus", "value": "Prometheus" }
      }
    ]
  },
  "time": { "from": "now-6h", "to": "now" },
  "timepicker": {},
  "timezone": "browser",
  "title": "LLMHosts Backend Health & Cost",
  "uid": "llmhosts-backends",
  "version": 1
}
