{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Источник данных, который собирает метрики Hubris",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "annotations": { "list": [] },
  "editable": true,
  "graphTooltip": 1,
  "links": [],
  "panels": [
    {
      "type": "stat",
      "title": "Баланс",
      "description": "Остаток на балансе Hubris. Метрика приходит в копейках, панель делит на 100.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 0, "y": 0 },
      "id": 1,
      "targets": [
        {
          "refId": "A",
          "expr": "hubris_balance_kopecks / 100",
          "legendFormat": "баланс"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
        "colorMode": "value",
        "graphMode": "area",
        "textMode": "auto"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "currencyRUB",
          "decimals": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "orange", "value": 500 },
              { "color": "green", "value": 2000 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "type": "stat",
      "title": "Расход за сутки",
      "description": "Сколько списано за последние 24 часа: прирост счётчика расхода.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 6, "y": 0 },
      "id": 2,
      "targets": [
        {
          "refId": "A",
          "expr": "sum(increase(hubris_spend_kopecks_total[24h])) / 100",
          "legendFormat": "за 24 часа"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
        "colorMode": "none",
        "graphMode": "area"
      },
      "fieldConfig": {
        "defaults": { "unit": "currencyRUB", "decimals": 0, "thresholds": { "mode": "absolute", "steps": [{ "color": "text", "value": null }] } },
        "overrides": []
      }
    },
    {
      "type": "stat",
      "title": "Запросы в час",
      "description": "Скорость запросов, приведённая к часу.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 12, "y": 0 },
      "id": 3,
      "targets": [
        {
          "refId": "A",
          "expr": "sum(rate(hubris_requests_total[15m])) * 3600",
          "legendFormat": "запросов/час"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
        "colorMode": "none",
        "graphMode": "area"
      },
      "fieldConfig": {
        "defaults": { "unit": "short", "decimals": 0, "thresholds": { "mode": "absolute", "steps": [{ "color": "text", "value": null }] } },
        "overrides": []
      }
    },
    {
      "type": "stat",
      "title": "Доля ошибок",
      "description": "Какая часть запросов за 15 минут закончилась ошибкой модели или отказом.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 5, "w": 6, "x": 18, "y": 0 },
      "id": 4,
      "targets": [
        {
          "refId": "A",
          "expr": "100 * sum(rate(hubris_requests_total{outcome!=\"success\"}[15m])) / clamp_min(sum(rate(hubris_requests_total[15m])), 0.0001)",
          "legendFormat": "ошибок"
        }
      ],
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
        "colorMode": "value",
        "graphMode": "area"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "decimals": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 2 },
              { "color": "red", "value": 5 }
            ]
          }
        },
        "overrides": []
      }
    },
    {
      "type": "timeseries",
      "title": "Расход по моделям, ₽/час",
      "description": "Во что обходится каждая модель. Хорошо видно, кто именно разогнал счёт.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 9, "w": 12, "x": 0, "y": 5 },
      "id": 5,
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (model) (rate(hubris_spend_kopecks_total[30m])) * 3600 / 100",
          "legendFormat": "{{model}}"
        }
      ],
      "options": {
        "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean", "max"], "showLegend": true },
        "tooltip": { "mode": "multi", "sort": "desc" }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "currencyRUB",
          "custom": { "fillOpacity": 12, "lineWidth": 2, "showPoints": "never", "stacking": { "mode": "normal", "group": "A" } }
        },
        "overrides": []
      }
    },
    {
      "type": "timeseries",
      "title": "Запросы по исходам",
      "description": "success — выполнен, client_error — отклонён, upstream_error — модель не ответила.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 9, "w": 12, "x": 12, "y": 5 },
      "id": 6,
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (outcome) (rate(hubris_requests_total[15m])) * 60",
          "legendFormat": "{{outcome}}"
        }
      ],
      "options": {
        "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true },
        "tooltip": { "mode": "multi", "sort": "desc" }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": { "fillOpacity": 10, "lineWidth": 2, "showPoints": "never" }
        },
        "overrides": [
          {
            "matcher": { "id": "byName", "options": "success" },
            "properties": [{ "id": "color", "value": { "mode": "fixed", "fixedColor": "green" } }]
          },
          {
            "matcher": { "id": "byName", "options": "upstream_error" },
            "properties": [{ "id": "color", "value": { "mode": "fixed", "fixedColor": "red" } }]
          },
          {
            "matcher": { "id": "byName", "options": "client_error" },
            "properties": [{ "id": "color", "value": { "mode": "fixed", "fixedColor": "orange" } }]
          }
        ]
      }
    },
    {
      "type": "timeseries",
      "title": "Время ответа",
      "description": "Медиана и 95-й перцентиль за последний час — как их видит Hubris.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 14 },
      "id": 7,
      "targets": [
        {
          "refId": "A",
          "expr": "hubris_request_latency_seconds",
          "legendFormat": "перцентиль {{quantile}}"
        }
      ],
      "options": {
        "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true },
        "tooltip": { "mode": "multi" }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": { "fillOpacity": 8, "lineWidth": 2, "showPoints": "never" }
        },
        "overrides": []
      }
    },
    {
      "type": "timeseries",
      "title": "Токены по видам",
      "description": "Чтение кэша дешевле обычного ввода: если cache_read стабильно выше prompt — кэш работает.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 14 },
      "id": 8,
      "targets": [
        {
          "refId": "A",
          "expr": "sum by (kind) (rate(hubris_tokens_total[30m])) * 60",
          "legendFormat": "{{kind}}"
        }
      ],
      "options": {
        "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true },
        "tooltip": { "mode": "multi", "sort": "desc" }
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": { "fillOpacity": 10, "lineWidth": 2, "showPoints": "never" }
        },
        "overrides": []
      }
    },
    {
      "type": "table",
      "title": "Лимиты ключей",
      "description": "Сколько разрешено ключу и сколько уже истрачено в текущем окне лимита.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 24, "x": 0, "y": 22 },
      "id": 9,
      "targets": [
        {
          "refId": "A",
          "expr": "hubris_key_limit_kopecks / 100",
          "legendFormat": "{{key}}",
          "instant": true,
          "format": "table"
        },
        {
          "refId": "B",
          "expr": "hubris_key_spent_kopecks / 100",
          "legendFormat": "{{key}}",
          "instant": true,
          "format": "table"
        }
      ],
      "transformations": [
        { "id": "merge", "options": {} },
        {
          "id": "organize",
          "options": {
            "excludeByName": { "Time": true, "__name__": true, "instance": true, "job": true },
            "renameByName": {
              "key": "Ключ",
              "period": "Период",
              "Value #A": "Лимит, ₽",
              "Value #B": "Истрачено, ₽"
            }
          }
        }
      ],
      "fieldConfig": {
        "defaults": { "unit": "currencyRUB", "decimals": 0 },
        "overrides": [
          {
            "matcher": { "id": "byName", "options": "Ключ" },
            "properties": [{ "id": "unit", "value": "string" }]
          },
          {
            "matcher": { "id": "byName", "options": "Период" },
            "properties": [{ "id": "unit", "value": "string" }]
          }
        ]
      }
    }
  ],
  "refresh": "1m",
  "schemaVersion": 39,
  "tags": ["hubris", "llm"],
  "templating": { "list": [] },
  "time": { "from": "now-24h", "to": "now" },
  "timezone": "browser",
  "title": "Hubris — расход и запросы",
  "uid": "hubris-usage",
  "version": 1,
  "weekStart": ""
}
