Files
ERP/monitoring/grafana/dashboards/bot-trace-explorer.json
T
whqreza 0adadd2cf8 feat(monitoring): bot observability dashboards — Grafana + Persian RTL ERP page
Grafana (full use of the existing monitoring/ stack, per OSS policy):
- datasources.yml: BotPostgres (uid bot-postgres) over the shared network;
  grafana service joins 'shared' + carries the datasource env
- db_init.py: idempotent read-only role obs_reader (USAGE on schema public +
  SELECT on bot_traces/bot_trace_events; skipped when
  OBS_READER_PASSWORD empty; ALTER ROLE for rotation) + composite index
  ix_bot_trace_events_stage_time (stage, created_at DESC) — senior-engineer
  review applied with the column-name fix (event_type -> stage); (trace_id)
  already covered by the existing (trace_id, created_at) index
- dashboards/bot-observability.json: KPI row (real traffic, events, Jev/
  fallback errors, Jev p95, tokens, commits, archive guard), events/day,
  per-stage p50/p95, mention statuses (arbiter+fallback aggregates + legacy
  rows), DeepSeek arbiter actions, tokens/day, model-drift vs jev-1.13.0,
  user-choice A/B, STT + audio.enhance health, archive size guard
- dashboards/bot-trace-explorer.json: trace table + full event drill-down
  via the trace_id variable

ERP page (admin-only, Persian RTL, recharts@^3 for React 19):
- backend bot_metrics.py: read-only require_role('admin') endpoints
  (summary/routing/quality/jev/stt/traces + trace detail); aggregates count
  real traffic only (calibration/demo/chat_id=0 excluded)
- frontend BotMonitorPage at /bot-monitor (KPI cards, daily events,
  status donut, arbiter actions, user-choice A/B, STT/enhance tables,
  stage latency, tokens chart, traces table + detail drawer with payload
  viewer); entry link from the admin panel; MobileTabBar hidden there
- api.ts: typed botMetrics client section

Tooling/docs:
- tools/seed_observability_demo.py: deterministic demo traces (source='demo',
  every current pipeline stage incl. audio.enhance/jev.failure/arbitration/
  fallback/user choices) — excluded from real-traffic aggregates
- monitoring/README.md + bot/docs/DEPLOY-AND-MONITORING.md: setup, seed and
  rollback notes; alerts deliberately deferred (owner decision 2026-10-24)

Verified locally: obs_reader SELECT ok / INSERT denied; panels' SQL run as
obs_reader with data; datasource health OK; both dashboards survive a grafana
restart; endpoints 200 as admin and 403 without role; tsc + vite build clean;
page renders in-browser (admin session); bot startup provisions role+index.
2026-10-24 15:09:01 +03:30

44 lines
2.2 KiB
JSON

{
"annotations": { "list": [] },
"editable": true,
"graphTooltip": 1,
"refresh": "30s",
"schemaVersion": 41,
"tags": ["erp", "bot"],
"time": { "from": "now-24h", "to": "now" },
"timezone": "browser",
"title": "بات — اکسپلورر ترس‌ها",
"uid": "bot-trace-explorer",
"version": 1,
"panels": [
{
"type": "table", "title": "آخرین ترس‌ها", "id": 1,
"datasource": { "type": "postgres", "uid": "bot-postgres" },
"gridPos": { "h": 12, "w": 24, "x": 0, "y": 0 },
"targets": [{ "refId": "A", "format": "table", "rawSql": "SELECT t.id::text AS \"trace_id\", t.created_at AS \"زمان\", coalesce(t.source,'bale') AS \"منبع\", t.chat_id AS \"چت\", t.kind AS \"نوع\", coalesce(t.status,'—') AS \"وضعیت\", (SELECT count(*) FROM bot_trace_events e WHERE e.trace_id=t.id) AS \"رخدادها\" FROM bot_traces t WHERE ($trace_id = '' OR t.id::text = $trace_id) AND $__timeFilter(t.created_at) ORDER BY t.created_at DESC LIMIT 100" }],
"fieldConfig": { "defaults": { "custom": { "align": "auto" } }, "overrides": [] }
},
{
"type": "table", "title": "رویدادهای ترس انتخاب‌شده (به ترتیب زمان)", "id": 2,
"datasource": { "type": "postgres", "uid": "bot-postgres" },
"gridPos": { "h": 14, "w": 24, "x": 0, "y": 12 },
"targets": [{ "refId": "A", "format": "table", "rawSql": "SELECT e.created_at AS \"زمان\", e.stage AS \"مرحله\", e.ok AS \"ok\", coalesce(e.latency_ms::text,'—') AS \"تأخیر (ms)\", coalesce(e.model,'—') AS \"مدل\", coalesce(e.field,'—') AS \"فیلد\", left(e.payload::text, 700) AS \"payload\" FROM bot_trace_events e WHERE e.trace_id::text = $trace_id ORDER BY e.created_at ASC LIMIT 500" }],
"fieldConfig": { "defaults": { "custom": { "align": "auto", "cellOptions": { "type": "text" } } }, "overrides": [] }
}
],
"templating": {
"list": [
{
"name": "trace_id",
"label": "شناسه ترس",
"type": "textbox",
"hide": 0,
"current": { "selected": false, "text": "", "value": "" },
"options": [],
"query": "",
"description": "trace_id را از جدول بالا کپی و اینجا بچسبانید"
}
]
}
}