{
  "__inputs": [],
  "__requires": [
    { "type": "grafana", "id": "grafana", "name": "Grafana", "version": "10.4.0" },
    { "type": "datasource", "id": "prometheus", "name": "Prometheus", "version": "1.0.0" }
  ],
  "uid": "xzonas-supervisor-v1",
  "title": "XZonas · Supervisor IA",
  "description": "Monitor de propuestas, automatizaciones, agentes y sistema del supervisor multiagente.",
  "tags": ["supervisor", "xzonas", "ia"],
  "style": "dark",
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "time": { "from": "now-6h", "to": "now" },
  "timepicker": {},
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "panels": [
    {
      "id": 1, "type": "row", "collapsed": false,
      "title": "📊 KPIs — Estado actual",
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }
    },
    {
      "id": 2, "type": "stat",
      "title": "⏳ Propuestas pendientes",
      "description": "Propuestas generadas por agentes que esperan aprobación.",
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_pending_proposals",
          "instant": true,
          "legendFormat": "Pendientes"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": 0 },
              { "color": "yellow", "value": 3 },
              { "color": "red", "value": 8 }
            ]
          },
          "mappings": []
        }
      }
    },
    {
      "id": 3, "type": "stat",
      "title": "✅ Propuestas aprobadas",
      "gridPos": { "h": 4, "w": 4, "x": 4, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"approved\"}",
          "instant": true,
          "legendFormat": "Aprobadas"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "green", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 4, "type": "stat",
      "title": "🔴 Propuestas rechazadas",
      "gridPos": { "h": 4, "w": 4, "x": 8, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"rejected\"}",
          "instant": true,
          "legendFormat": "Rechazadas"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "red", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 5, "type": "stat",
      "title": "📚 Estudios generados",
      "gridPos": { "h": 4, "w": 4, "x": 12, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_studies_total",
          "instant": true,
          "legendFormat": "Estudios"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "purple", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 6, "type": "stat",
      "title": "🧠 Memorias activas",
      "gridPos": { "h": 4, "w": 4, "x": 16, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_memories_total",
          "instant": true,
          "legendFormat": "Memorias"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "blue", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 7, "type": "stat",
      "title": "🟢 Scheduler activo",
      "gridPos": { "h": 4, "w": 4, "x": 20, "y": 1 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_scheduler_running",
          "instant": true,
          "legendFormat": "Scheduler"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "mappings": [
            { "type": "value", "options": { "0": { "text": "Detenido", "color": "red" }, "1": { "text": "Activo", "color": "green" } } }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": 0 },
              { "color": "green", "value": 1 }
            ]
          }
        }
      }
    },
    {
      "id": 10, "type": "row", "collapsed": false,
      "title": "⚙️ Automatización",
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 }
    },
    {
      "id": 11, "type": "stat",
      "title": "🤖 Reglas habilitadas",
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 6 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_automation_rules_enabled",
          "instant": true,
          "legendFormat": "Reglas activas"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "orange", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 12, "type": "timeseries",
      "title": "📈 Runs de automatización en el tiempo",
      "gridPos": { "h": 8, "w": 20, "x": 4, "y": 6 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_automation_runs_total{status=\"done\"}",
          "legendFormat": "✅ Completados"
        },
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_automation_runs_total{status=\"error\"}",
          "legendFormat": "❌ Error"
        },
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_automation_runs_total{status=\"pending\"}",
          "legendFormat": "⏳ Pendientes"
        }
      ],
      "options": {
        "tooltip": { "mode": "multi", "sort": "none" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["lastNotNull", "max"] }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": {
            "lineWidth": 2,
            "fillOpacity": 8,
            "spanNulls": true
          }
        }
      }
    },
    {
      "id": 20, "type": "row", "collapsed": false,
      "title": "💬 Propuestas y Agentes",
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 14 }
    },
    {
      "id": 21, "type": "timeseries",
      "title": "📋 Propuestas por estado (acumulado)",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 15 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"pending\"}",
          "legendFormat": "⏳ Pendientes"
        },
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"approved\"}",
          "legendFormat": "✅ Aprobadas"
        },
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"executed\"}",
          "legendFormat": "🚀 Ejecutadas"
        },
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_proposals_total{status=\"rejected\"}",
          "legendFormat": "🔴 Rechazadas"
        }
      ],
      "options": {
        "tooltip": { "mode": "multi", "sort": "none" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["lastNotNull"] }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": {
            "lineWidth": 2,
            "fillOpacity": 6,
            "spanNulls": true
          }
        }
      }
    },
    {
      "id": 22, "type": "timeseries",
      "title": "🤖 Chats por tipo de agente",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 15 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_agent_chat_total",
          "legendFormat": "{{kind}}"
        }
      ],
      "options": {
        "tooltip": { "mode": "multi", "sort": "desc" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["lastNotNull", "sum"] }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": {
            "lineWidth": 2,
            "fillOpacity": 8,
            "spanNulls": true
          }
        }
      }
    },
    {
      "id": 30, "type": "row", "collapsed": false,
      "title": "🖥️ Sistema y Comandos",
      "gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 }
    },
    {
      "id": 31, "type": "stat",
      "title": "🔧 Comandos SSH ejecutados",
      "gridPos": { "h": 4, "w": 6, "x": 0, "y": 24 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_commands_total",
          "instant": true,
          "legendFormat": "Comandos"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "cyan", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 32, "type": "stat",
      "title": "📡 Eventos entrantes",
      "gridPos": { "h": 4, "w": 6, "x": 6, "y": 24 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_inbound_events_total",
          "instant": true,
          "legendFormat": "Eventos"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "background",
        "graphMode": "none"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "color": { "fixedColor": "teal", "mode": "fixed" },
          "mappings": []
        }
      }
    },
    {
      "id": 33, "type": "gauge",
      "title": "📊 Total propuestas (todas)",
      "gridPos": { "h": 8, "w": 6, "x": 12, "y": 24 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "sum(supervisor_proposals_total)",
          "instant": true,
          "legendFormat": "Total"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "blue", "value": 0 },
              { "color": "green", "value": 10 },
              { "color": "yellow", "value": 50 }
            ]
          },
          "mappings": []
        }
      }
    },
    {
      "id": 34, "type": "gauge",
      "title": "🤖 Reglas activas / total",
      "gridPos": { "h": 8, "w": 6, "x": 18, "y": 24 },
      "targets": [
        {
          "datasource": { "type": "prometheus", "uid": "xzonas-prom" },
          "expr": "supervisor_automation_rules_enabled",
          "instant": true,
          "legendFormat": "Activas"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "min": 0,
          "max": 6,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": 0 },
              { "color": "yellow", "value": 2 },
              { "color": "green", "value": 4 }
            ]
          },
          "mappings": []
        }
      }
    }
  ],
  "annotations": {
    "list": []
  },
  "links": []
}
