{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Prometheus datasource scraping the entroly proxy /metrics endpoint",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "title": "Entroly Proxy",
  "uid": "entroly-proxy",
  "tags": ["entroly", "llm", "context"],
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "time": { "from": "now-6h", "to": "now" },
  "panels": [
    {
      "type": "stat",
      "title": "Tokens saved (lifetime)",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 0, "y": 0 },
      "targets": [
        {
          "expr": "entroly_tokens_original_total - entroly_tokens_optimized_total",
          "legendFormat": "tokens saved"
        }
      ],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value" },
      "fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "green" } }, "overrides": [] }
    },
    {
      "type": "stat",
      "title": "Input-token savings ratio (5m)",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 6, "y": 0 },
      "targets": [
        {
          "expr": "1 - (rate(entroly_tokens_optimized_total[5m]) / rate(entroly_tokens_original_total[5m]))",
          "legendFormat": "savings ratio"
        }
      ],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value" },
      "fieldConfig": { "defaults": { "unit": "percentunit", "min": 0, "max": 1 }, "overrides": [] }
    },
    {
      "type": "stat",
      "title": "Optimized share of requests",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 12, "y": 0 },
      "targets": [
        {
          "expr": "entroly_requests_optimized / entroly_requests_total",
          "legendFormat": "optimized share"
        }
      ],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value" },
      "fieldConfig": { "defaults": { "unit": "percentunit", "min": 0, "max": 1 }, "overrides": [] }
    },
    {
      "type": "stat",
      "title": "Circuit breaker",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 18, "y": 0 },
      "targets": [{ "expr": "entroly_circuit_breaker", "legendFormat": "breaker" }],
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background" },
      "fieldConfig": {
        "defaults": {
          "mappings": [
            { "type": "value", "options": { "0": { "text": "CLOSED", "color": "green" } } },
            { "type": "value", "options": { "1": { "text": "OPEN", "color": "red" } } }
          ]
        },
        "overrides": []
      }
    },
    {
      "type": "timeseries",
      "title": "Request rate by disposition",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 5 },
      "targets": [
        { "expr": "rate(entroly_requests_optimized[5m])", "legendFormat": "optimized" },
        { "expr": "rate(entroly_requests_bypassed[5m])", "legendFormat": "bypassed" },
        { "expr": "rate(entroly_requests_subscription_blocked[5m])", "legendFormat": "subscription-blocked" }
      ],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] }
    },
    {
      "type": "timeseries",
      "title": "Token throughput: original vs optimized",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 5 },
      "targets": [
        { "expr": "rate(entroly_tokens_original_total[5m])", "legendFormat": "original tok/s" },
        { "expr": "rate(entroly_tokens_optimized_total[5m])", "legendFormat": "optimized tok/s" }
      ],
      "fieldConfig": { "defaults": { "unit": "short" }, "overrides": [] }
    },
    {
      "type": "timeseries",
      "title": "Pipeline latency (mean)",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 7, "w": 12, "x": 0, "y": 13 },
      "targets": [{ "expr": "entroly_pipeline_latency_ms", "legendFormat": "mean ms" }],
      "fieldConfig": { "defaults": { "unit": "ms" }, "overrides": [] }
    },
    {
      "type": "timeseries",
      "title": "Recorded outcomes",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 7, "w": 12, "x": 12, "y": 13 },
      "targets": [
        { "expr": "rate(entroly_outcome_success[15m])", "legendFormat": "success" },
        { "expr": "rate(entroly_outcome_failure[15m])", "legendFormat": "failure" }
      ],
      "fieldConfig": { "defaults": { "unit": "short" }, "overrides": [] }
    }
  ]
}
