{
  "__inputs": [],
  "__requires": [
    { "type": "grafana", "id": "grafana", "name": "Grafana", "version": "8.0.0" },
    { "type": "datasource", "id": "prometheus", "name": "Prometheus", "version": "1.0.0" },
    { "type": "panel", "id": "stat", "name": "Stat", "version": "" },
    { "type": "panel", "id": "timeseries", "name": "Time series", "version": "" },
    { "type": "panel", "id": "gauge", "name": "Gauge", "version": "" }
  ],
  "annotations": { "list": [] },
  "description": "Dashboard principal del XZonas Multiagent Supervisor",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": null,
  "links": [],
  "panels": [
    {
      "id": 1,
      "title": "Propuestas (total)",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_proposals_total", "legendFormat": "Propuestas" }]
    },
    {
      "id": 2,
      "title": "Propuestas pendientes",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 4, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 3 }, { "color": "red", "value": 10 }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "colorMode": "background", "graphMode": "none", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_pending_proposals", "legendFormat": "Pendientes" }]
    },
    {
      "id": 3,
      "title": "Estudios (total)",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 8, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_studies_total", "legendFormat": "Estudios" }]
    },
    {
      "id": 4,
      "title": "Ejecuciones de automatización",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 12, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_automation_runs_total", "legendFormat": "Runs" }]
    },
    {
      "id": 5,
      "title": "Memorias almacenadas",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 16, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "blue", "value": null }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_memories_total", "legendFormat": "Memorias" }]
    },
    {
      "id": 6,
      "title": "Scheduler activo",
      "type": "stat",
      "gridPos": { "h": 4, "w": 4, "x": 20, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": {
          "mappings": [{ "options": { "0": { "text": "PARADO" }, "1": { "text": "ACTIVO" } }, "type": "value" }],
          "thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 1 }] },
          "unit": "short"
        },
        "overrides": []
      },
      "options": { "colorMode": "background", "graphMode": "none", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_scheduler_running", "legendFormat": "Scheduler" }]
    },
    {
      "id": 7,
      "title": "Propuestas por minuto",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 4 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "custom": { "lineWidth": 2, "fillOpacity": 15 }, "unit": "reqps" },
        "overrides": []
      },
      "options": { "tooltip": { "mode": "single" } },
      "targets": [
        { "expr": "rate(supervisor_proposals_total[5m])", "legendFormat": "Propuestas/s" },
        { "expr": "rate(supervisor_studies_total[5m])", "legendFormat": "Estudios/s" }
      ]
    },
    {
      "id": 8,
      "title": "Eventos entrantes (Telegram / WhatsApp / API)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 4 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "custom": { "lineWidth": 2, "fillOpacity": 15 }, "unit": "reqps" },
        "overrides": []
      },
      "options": { "tooltip": { "mode": "single" } },
      "targets": [
        { "expr": "rate(supervisor_inbound_events_total[5m])", "legendFormat": "Eventos/s" },
        { "expr": "rate(supervisor_automation_runs_total[5m])", "legendFormat": "Automation runs/s" }
      ]
    },
    {
      "id": 9,
      "title": "Reglas de automatización habilitadas",
      "type": "gauge",
      "gridPos": { "h": 6, "w": 6, "x": 0, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "max": 10, "min": 0, "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] }, "unit": "short" },
        "overrides": []
      },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [{ "expr": "supervisor_automation_rules_enabled", "legendFormat": "Habilitadas" }]
    },
    {
      "id": 10,
      "title": "Chats por agente (rate 5m)",
      "type": "timeseries",
      "gridPos": { "h": 6, "w": 18, "x": 6, "y": 12 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "fieldConfig": {
        "defaults": { "custom": { "lineWidth": 2 }, "unit": "reqps" },
        "overrides": []
      },
      "options": { "tooltip": { "mode": "multi" } },
      "targets": [
        { "expr": "rate(supervisor_agent_chat_total[5m])", "legendFormat": "{{kind}}" }
      ]
    }
  ],
  "refresh": "30s",
  "schemaVersion": 38,
  "tags": ["xzonas", "ops", "supervisor"],
  "templating": {
    "list": [
      {
        "current": {},
        "hide": 0,
        "includeAll": false,
        "label": "Datasource",
        "multi": false,
        "name": "datasource",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "type": "datasource"
      }
    ]
  },
  "time": { "from": "now-3h", "to": "now" },
  "timepicker": {},
  "timezone": "browser",
  "title": "XZonas Multiagent Supervisor",
  "uid": "xzonas-supervisor-main",
  "version": 1
}
