{
  "uid": "scrabble-messages",
  "title": "Scrabble — Messages",
  "tags": ["scrabble"],
  "timezone": "",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "time": { "from": "now-24h", "to": "now" },
  "panels": [
    {
      "type": "timeseries",
      "title": "Chat entries posted (rate by kind)",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "refId": "A", "expr": "sum(rate(chat_messages_total[15m])) by (kind)", "legendFormat": "{{kind}}" }]
    },
    {
      "type": "timeseries",
      "title": "Unread chat entries (backlog)",
      "description": "Chat entries with at least one recipient seat that has not read them yet (chat_unread_messages gauge).",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "refId": "A", "expr": "sum(chat_unread_messages)", "legendFormat": "unread" }]
    },
    {
      "type": "timeseries",
      "title": "Publish → read latency (avg by kind)",
      "description": "Mean time from a chat entry being posted to a recipient reading it (move-history / chat open, or a nudge answered by moving). A born-read message to a robot records no read, so it does not enter this average.",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
      "fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [{ "refId": "A", "expr": "sum(rate(chat_read_duration_sum[15m])) by (kind) / sum(rate(chat_read_duration_count[15m])) by (kind)", "legendFormat": "{{kind}}" }]
    },
    {
      "type": "timeseries",
      "title": "Publish → read latency (p50 / p95)",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
      "fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
      "datasource": { "type": "prometheus", "uid": "prometheus" },
      "targets": [
        { "refId": "A", "expr": "histogram_quantile(0.5, sum(rate(chat_read_duration_bucket[15m])) by (le))", "legendFormat": "p50" },
        { "refId": "B", "expr": "histogram_quantile(0.95, sum(rate(chat_read_duration_bucket[15m])) by (le))", "legendFormat": "p95" }
      ]
    }
  ]
}
