{
  "uid": "smithers",
  "title": "Smithers",
  "tags": ["smithers", "observability"],
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "10s",
  "time": { "from": "now-6h", "to": "now" },
  "editable": true,
  "panels": [
    {
      "type": "row",
      "title": "Overview",
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 },
      "id": 1
    },
    {
      "type": "stat",
      "title": "Active Runs",
      "id": 2,
      "gridPos": { "h": 4, "w": 3, "x": 0, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_runs_active) or vector(0)", "refId": "A" }],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Completed Runs",
      "id": 3,
      "gridPos": { "h": 4, "w": 3, "x": 3, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_runs_finished_total) or vector(0)", "refId": "A" }],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Failed Runs",
      "id": 4,
      "gridPos": { "h": 4, "w": 3, "x": 6, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_runs_failed_total) or vector(0)", "refId": "A" }],
      "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "red", "value": 1 }] } } },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Active Nodes",
      "id": 5,
      "gridPos": { "h": 4, "w": 3, "x": 9, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_nodes_active) or vector(0)", "refId": "A" }],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Finished Nodes",
      "id": 6,
      "gridPos": { "h": 4, "w": 3, "x": 12, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_nodes_finished) or vector(0)", "refId": "A" }],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Failed Nodes",
      "id": 7,
      "gridPos": { "h": 4, "w": 3, "x": 15, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_nodes_failed) or vector(0)", "refId": "A" }],
      "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "red", "value": 1 }] } } },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Pending Approvals",
      "id": 8,
      "gridPos": { "h": 4, "w": 3, "x": 18, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(smithers_approval_pending) or vector(0)", "refId": "A" }],
      "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 1 }, { "color": "red", "value": 5 }] } } },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background", "graphMode": "none" }
    },
    {
      "type": "stat",
      "title": "Error Rate",
      "id": 9,
      "gridPos": { "h": 4, "w": 3, "x": 21, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "expr": "sum(rate(smithers_errors_total[5m])) or vector(0)", "refId": "A" }],
      "fieldConfig": { "defaults": { "unit": "ops" } },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }
    },
    {
      "type": "row",
      "title": "Lifecycle",
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 },
      "id": 10
    },
    {
      "type": "timeseries",
      "title": "Run Lifecycle",
      "id": 11,
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "rate(smithers_runs_total[5m])", "legendFormat": "Started", "refId": "A" },
        { "expr": "rate(smithers_runs_finished_total[5m])", "legendFormat": "Finished", "refId": "B" },
        { "expr": "rate(smithers_runs_failed_total[5m])", "legendFormat": "Failed", "refId": "C" }
      ],
      "fieldConfig": { "defaults": { "unit": "ops", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "timeseries",
      "title": "Node Lifecycle",
      "id": 12,
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "rate(smithers_nodes_started[5m])", "legendFormat": "Started", "refId": "A" },
        { "expr": "rate(smithers_nodes_finished[5m])", "legendFormat": "Finished", "refId": "B" },
        { "expr": "rate(smithers_nodes_failed[5m])", "legendFormat": "Failed", "refId": "C" }
      ],
      "fieldConfig": { "defaults": { "unit": "ops", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "row",
      "title": "Latency",
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 14 },
      "id": 20
    },
    {
      "type": "timeseries",
      "title": "Task Duration",
      "id": 21,
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 15 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "histogram_quantile(0.50, sum(rate(smithers_node_duration_ms_bucket[5m])) by (le))", "legendFormat": "p50", "refId": "A" },
        { "expr": "histogram_quantile(0.95, sum(rate(smithers_node_duration_ms_bucket[5m])) by (le))", "legendFormat": "p95", "refId": "B" }
      ],
      "fieldConfig": { "defaults": { "unit": "ms", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "timeseries",
      "title": "DB Query Latency",
      "id": 22,
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 15 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "histogram_quantile(0.50, sum(rate(smithers_db_query_ms_bucket[5m])) by (le))", "legendFormat": "p50", "refId": "A" },
        { "expr": "histogram_quantile(0.95, sum(rate(smithers_db_query_ms_bucket[5m])) by (le))", "legendFormat": "p95", "refId": "B" }
      ],
      "fieldConfig": { "defaults": { "unit": "ms", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "row",
      "title": "Agents",
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 },
      "id": 30
    },
    {
      "type": "timeseries",
      "title": "Agent Tokens by Engine / Model",
      "id": 31,
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        {
          "expr": "sum by (engine, model) (rate(smithers_agent_tokens_total{kind=\"total\"}[5m]))",
          "legendFormat": "{{engine}} / {{model}}",
          "refId": "A"
        }
      ],
      "fieldConfig": { "defaults": { "unit": "ops", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "timeseries",
      "title": "Approval Decisions",
      "id": 32,
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 24 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "rate(smithers_approvals_requested[5m])", "legendFormat": "Requested", "refId": "A" },
        { "expr": "rate(smithers_approvals_granted[5m])", "legendFormat": "Granted", "refId": "B" },
        { "expr": "rate(smithers_approvals_denied[5m])", "legendFormat": "Denied", "refId": "C" }
      ],
      "fieldConfig": { "defaults": { "unit": "ops", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "row",
      "title": "Errors",
      "collapsed": false,
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 32 },
      "id": 40
    },
    {
      "type": "timeseries",
      "title": "Error Counters",
      "id": 41,
      "gridPos": { "h": 8, "w": 24, "x": 0, "y": 33 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "expr": "rate(smithers_errors_total[5m])", "legendFormat": "Errors", "refId": "A" },
        { "expr": "rate(smithers_tool_calls_errors_total[5m])", "legendFormat": "Tool call errors", "refId": "B" },
        { "expr": "rate(smithers_runs_failed_total[5m])", "legendFormat": "Failed runs", "refId": "C" },
        { "expr": "rate(smithers_nodes_failed[5m])", "legendFormat": "Failed nodes", "refId": "D" }
      ],
      "fieldConfig": { "defaults": { "unit": "ops", "color": { "mode": "palette-classic" } } },
      "options": { "tooltip": { "mode": "multi", "sort": "desc" }, "legend": { "displayMode": "list", "placement": "bottom" } }
    }
  ]
}
