{
  "dashboard": {
    "title": "CFN Operational Dashboard - Phase 3",
    "tags": ["cfn", "operations", "phase-3", "c-suite"],
    "timezone": "browser",
    "refresh": "30s",
    "time": {
      "from": "now-24h",
      "to": "now"
    },
    "templating": {
      "list": [
        {
          "name": "team",
          "type": "custom",
          "query": "marketing,sales,support,engineering,finance,ceo,cfo,cto",
          "current": {
            "text": "All",
            "value": "$__all"
          },
          "multi": true,
          "includeAll": true
        },
        {
          "name": "coordinator",
          "type": "custom",
          "query": "marketing-hybrid,sales-coordinator,support-coordinator,engineering-coordinator,finance-coordinator,ceo-coordinator,cfo-coordinator,cto-coordinator",
          "current": {
            "text": "All",
            "value": "$__all"
          },
          "multi": true,
          "includeAll": true
        }
      ]
    },
    "panels": [
      {
        "id": 1,
        "title": "Z.ai Cost Per Team (24h)",
        "type": "graph",
        "gridPos": {"x": 0, "y": 0, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum by (team) (zai_api_cost_usd{team=~\"$team\"})",
            "legendFormat": "{{team}}",
            "refId": "A"
          }
        ],
        "yaxes": [
          {
            "format": "currencyUSD",
            "label": "Cost (USD)"
          }
        ],
        "tooltip": {
          "shared": true,
          "value_type": "individual"
        },
        "legend": {
          "show": true,
          "values": true,
          "min": true,
          "max": true,
          "current": true,
          "total": true
        }
      },
      {
        "id": 2,
        "title": "Z.ai Cost Breakdown by Provider",
        "type": "piechart",
        "gridPos": {"x": 12, "y": 0, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum by (provider) (zai_api_cost_usd{team=~\"$team\"})",
            "legendFormat": "{{provider}}",
            "refId": "A"
          }
        ],
        "options": {
          "pieType": "pie",
          "legend": {
            "displayMode": "table",
            "placement": "right",
            "values": ["value", "percent"]
          }
        }
      },
      {
        "id": 3,
        "title": "Coordinator Health Status",
        "type": "stat",
        "gridPos": {"x": 0, "y": 8, "w": 6, "h": 4},
        "targets": [
          {
            "expr": "count(coordinator_health_status{coordinator=~\"$coordinator\", status=\"healthy\"})",
            "refId": "A"
          }
        ],
        "options": {
          "colorMode": "background",
          "graphMode": "area",
          "orientation": "auto",
          "textMode": "value_and_name",
          "reduceOptions": {
            "values": false,
            "calcs": ["lastNotNull"]
          }
        },
        "fieldConfig": {
          "defaults": {
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "red"},
                {"value": 1, "color": "yellow"},
                {"value": 5, "color": "green"}
              ]
            }
          }
        }
      },
      {
        "id": 4,
        "title": "Z.ai Rate Limit Usage (%)",
        "type": "gauge",
        "gridPos": {"x": 6, "y": 8, "w": 6, "h": 4},
        "targets": [
          {
            "expr": "(zai_rate_limit_used / zai_rate_limit_total) * 100",
            "refId": "A"
          }
        ],
        "options": {
          "showThresholdLabels": true,
          "showThresholdMarkers": true
        },
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "min": 0,
            "max": 100,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "green"},
                {"value": 70, "color": "yellow"},
                {"value": 80, "color": "orange"},
                {"value": 90, "color": "red"}
              ]
            }
          }
        }
      },
      {
        "id": 5,
        "title": "Request Success Rate (24h)",
        "type": "stat",
        "gridPos": {"x": 12, "y": 8, "w": 6, "h": 4},
        "targets": [
          {
            "expr": "(sum(rate(zai_requests_total{status=\"success\"}[24h])) / sum(rate(zai_requests_total[24h]))) * 100",
            "refId": "A"
          }
        ],
        "options": {
          "colorMode": "background",
          "graphMode": "area",
          "textMode": "value"
        },
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "decimals": 2,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "red"},
                {"value": 95, "color": "yellow"},
                {"value": 99, "color": "green"}
              ]
            }
          }
        }
      },
      {
        "id": 6,
        "title": "Cost Anomaly Alerts (7d)",
        "type": "stat",
        "gridPos": {"x": 18, "y": 8, "w": 6, "h": 4},
        "targets": [
          {
            "expr": "count(ALERTS{alertname=\"CostAnomalyDetected\", alertstate=\"firing\"})",
            "refId": "A"
          }
        ],
        "options": {
          "colorMode": "background",
          "textMode": "value_and_name"
        },
        "fieldConfig": {
          "defaults": {
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {"value": 0, "color": "green"},
                {"value": 1, "color": "yellow"},
                {"value": 5, "color": "red"}
              ]
            }
          }
        }
      },
      {
        "id": 7,
        "title": "Request Rate by Team (req/s)",
        "type": "graph",
        "gridPos": {"x": 0, "y": 12, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum by (team) (rate(zai_requests_total{team=~\"$team\"}[5m]))",
            "legendFormat": "{{team}}",
            "refId": "A"
          }
        ],
        "yaxes": [
          {
            "format": "reqps",
            "label": "Requests/sec"
          }
        ]
      },
      {
        "id": 8,
        "title": "Response Latency P95 by Team",
        "type": "graph",
        "gridPos": {"x": 12, "y": 12, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "histogram_quantile(0.95, sum by (team, le) (rate(zai_request_duration_seconds_bucket{team=~\"$team\"}[5m])))",
            "legendFormat": "{{team}} p95",
            "refId": "A"
          }
        ],
        "yaxes": [
          {
            "format": "s",
            "label": "Duration"
          }
        ]
      },
      {
        "id": 9,
        "title": "Coordinator Task Throughput",
        "type": "graph",
        "gridPos": {"x": 0, "y": 20, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum by (coordinator) (rate(coordinator_tasks_completed_total{coordinator=~\"$coordinator\"}[5m]))",
            "legendFormat": "{{coordinator}}",
            "refId": "A"
          }
        ],
        "yaxes": [
          {
            "format": "ops",
            "label": "Tasks/sec"
          }
        ]
      },
      {
        "id": 10,
        "title": "Cost Per Request Trend (7d)",
        "type": "graph",
        "gridPos": {"x": 12, "y": 20, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum(zai_api_cost_usd{team=~\"$team\"}) / sum(zai_requests_total{team=~\"$team\"})",
            "legendFormat": "Cost/Request",
            "refId": "A"
          }
        ],
        "yaxes": [
          {
            "format": "currencyUSD",
            "label": "USD per request"
          }
        ]
      },
      {
        "id": 11,
        "title": "Active Coordinators",
        "type": "table",
        "gridPos": {"x": 0, "y": 28, "w": 24, "h": 8},
        "targets": [
          {
            "expr": "coordinator_health_status{coordinator=~\"$coordinator\"}",
            "format": "table",
            "instant": true,
            "refId": "A"
          }
        ],
        "transformations": [
          {
            "id": "organize",
            "options": {
              "excludeByName": {
                "Time": true,
                "__name__": true
              },
              "indexByName": {
                "coordinator": 0,
                "status": 1,
                "team": 2,
                "last_heartbeat": 3,
                "tasks_pending": 4,
                "tasks_completed": 5
              }
            }
          }
        ]
      }
    ],
    "annotations": {
      "list": [
        {
          "name": "Deployments",
          "datasource": "Prometheus",
          "enable": true,
          "expr": "deployment_event",
          "tagKeys": "phase,team",
          "textFormat": "{{phase}}: {{team}}",
          "iconColor": "blue"
        },
        {
          "name": "Cost Anomalies",
          "datasource": "Prometheus",
          "enable": true,
          "expr": "ALERTS{alertname=\"CostAnomalyDetected\"}",
          "tagKeys": "team",
          "textFormat": "Cost spike: {{team}}",
          "iconColor": "red"
        }
      ]
    }
  },
  "overwrite": true
}
