{
  "title": "Planner",
  "uid": "trails-planner",
  "annotations": {
    "list": [
      {
        "name": "Deploys",
        "enable": true,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "iconColor": "rgba(0, 211, 255, 1)",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [
            "deploy"
          ],
          "type": "tags"
        }
      }
    ]
  },
  "timezone": "browser",
  "refresh": "30s",
  "panels": [
    {
      "title": "Active Sessions",
      "type": "stat",
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 0,
        "y": 0
      },
      "targets": [
        {
          "expr": "planner_active_sessions",
          "legendFormat": "Sessions"
        }
      ]
    },
    {
      "title": "Connected Clients",
      "type": "stat",
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "targets": [
        {
          "expr": "planner_connected_clients",
          "legendFormat": "Clients"
        }
      ]
    },
    {
      "title": "BRouter Latency",
      "type": "timeseries",
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "targets": [
        {
          "expr": "histogram_quantile(0.50, rate(brouter_request_duration_seconds_bucket[5m]))",
          "legendFormat": "p50"
        },
        {
          "expr": "histogram_quantile(0.95, rate(brouter_request_duration_seconds_bucket[5m]))",
          "legendFormat": "p95"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s"
        }
      }
    },
    {
      "title": "Request Rate by Route",
      "type": "timeseries",
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 6
      },
      "targets": [
        {
          "expr": "sum(rate(http_request_duration_seconds_count{job=\"planner\"}[5m])) by (route)",
          "legendFormat": "{{route}}"
        }
      ]
    },
    {
      "title": "POI Index Age",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 6,
        "x": 0,
        "y": 14
      },
      "targets": [
        {
          "expr": "poi_index_age_seconds",
          "legendFormat": "age"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 3024000 },
              { "color": "red", "value": 3628800 }
            ]
          }
        }
      }
    },
    {
      "title": "POI Index Rows (total)",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 6,
        "x": 6,
        "y": 14
      },
      "targets": [
        {
          "expr": "sum(poi_index_rows)",
          "legendFormat": "rows"
        }
      ]
    },
    {
      "title": "Last Import Status",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 6,
        "x": 12,
        "y": 14
      },
      "targets": [
        {
          "expr": "poi_import_last_status",
          "legendFormat": "status"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "mappings": [
            { "type": "value", "options": { "0": { "text": "FAIL", "color": "red" }, "1": { "text": "OK", "color": "green" } } }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "green", "value": 1 }
            ]
          }
        }
      }
    },
    {
      "title": "POI API Error Rate (5m)",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 6,
        "x": 18,
        "y": 14
      },
      "targets": [
        {
          "expr": "(sum(rate(poi_api_requests_total{status=~\"rate_limited|error\"}[5m])) or vector(0)) / clamp_min(sum(rate(poi_api_requests_total[5m])), 0.001)",
          "legendFormat": "error ratio"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "min": 0,
          "max": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "orange", "value": 0.05 },
              { "color": "red", "value": 0.2 }
            ]
          }
        }
      }
    },
    {
      "title": "POI API Requests (5m by status)",
      "type": "timeseries",
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 0,
        "y": 19
      },
      "targets": [
        {
          "expr": "sum by (status) (rate(poi_api_requests_total[5m]))",
          "legendFormat": "{{status}}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops"
        }
      }
    },
    {
      "title": "POI Index Rows by Category",
      "type": "timeseries",
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 12,
        "y": 19
      },
      "targets": [
        {
          "expr": "poi_index_rows",
          "legendFormat": "{{category}}"
        }
      ]
    }
  ]
}
