{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Prometheus data source scraping the claudectl exporter",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    { "type": "grafana", "id": "grafana", "name": "Grafana", "version": "10.0.0" },
    { "type": "datasource", "id": "prometheus", "name": "Prometheus", "version": "1.0.0" }
  ],
  "annotations": { "list": [] },
  "editable": true,
  "graphTooltip": 1,
  "tags": ["claudectl", "fleet", "supervisor"],
  "templating": { "list": [] },
  "time": { "from": "now-6h", "to": "now" },
  "timepicker": {},
  "title": "claudectl — Fleet Overview",
  "uid": null,
  "version": 1,
  "schemaVersion": 39,
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Running tasks",
      "gridPos": { "h": 4, "w": 6, "x": 0, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false } },
      "fieldConfig": {
        "defaults": {
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "yellow", "value": 8 }, { "color": "red", "value": 16 } ] }
        },
        "overrides": []
      },
      "targets": [
        { "refId": "A", "expr": "sum(claudectl_tasks_by_state{state=\"RUNNING\"})", "legendFormat": "running" }
      ]
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Pending backlog",
      "gridPos": { "h": 4, "w": 6, "x": 6, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false } },
      "fieldConfig": {
        "defaults": {
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "yellow", "value": 10 }, { "color": "red", "value": 25 } ] }
        },
        "overrides": []
      },
      "targets": [
        { "refId": "A", "expr": "sum(claudectl_tasks_by_state{state=\"PENDING\"})", "legendFormat": "pending" }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Fleet spend (total)",
      "gridPos": { "h": 4, "w": 6, "x": 12, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false } },
      "fieldConfig": { "defaults": { "unit": "currencyUSD", "color": { "mode": "fixed", "fixedColor": "blue" } }, "overrides": [] },
      "targets": [
        { "refId": "A", "expr": "sum(claudectl_fleet_cost_usd_total)", "legendFormat": "total" }
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Burn rate ($/hr)",
      "gridPos": { "h": 4, "w": 6, "x": 18, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false } },
      "fieldConfig": {
        "defaults": {
          "unit": "currencyUSD",
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "yellow", "value": 10 }, { "color": "red", "value": 20 } ] }
        },
        "overrides": []
      },
      "targets": [
        { "refId": "A", "expr": "sum(increase(claudectl_fleet_cost_usd_total[1h]))", "legendFormat": "$/hr" }
      ]
    },
    {
      "id": 5,
      "type": "timeseries",
      "title": "Tasks by state",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 4 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "fillOpacity": 20, "stacking": { "mode": "normal", "group": "A" } } }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["lastNotNull"] } },
      "targets": [
        { "refId": "A", "expr": "claudectl_tasks_by_state", "legendFormat": "{{state}}" }
      ]
    },
    {
      "id": 6,
      "type": "timeseries",
      "title": "Verifier pass rate",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 4 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "min": 0,
          "max": 1,
          "custom": { "drawStyle": "line", "fillOpacity": 10, "spanNulls": true },
          "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": null }, { "color": "yellow", "value": 0.6 }, { "color": "green", "value": 0.85 } ] }
        },
        "overrides": []
      },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["lastNotNull", "min"] } },
      "targets": [
        { "refId": "A", "expr": "claudectl_verifier_pass_rate", "legendFormat": "{{kind}}" }
      ]
    },
    {
      "id": 7,
      "type": "timeseries",
      "title": "Retries by cause (per 5m)",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": { "defaults": { "custom": { "drawStyle": "bars", "fillOpacity": 60, "stacking": { "mode": "normal", "group": "A" } } }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["sum"] } },
      "targets": [
        { "refId": "A", "expr": "increase(claudectl_retries_total[5m])", "legendFormat": "{{cause}}" }
      ]
    },
    {
      "id": 8,
      "type": "timeseries",
      "title": "Cumulative fleet spend",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "fieldConfig": { "defaults": { "unit": "currencyUSD", "custom": { "drawStyle": "line", "fillOpacity": 15 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" } },
      "targets": [
        { "refId": "A", "expr": "sum(claudectl_fleet_cost_usd_total)", "legendFormat": "total spend" }
      ]
    }
  ]
}
