# Grafana Dashboard: Prewarm Performance
# Import this JSON into Grafana to create a prewarm monitoring dashboard

{
  "dashboard": {
    "id": null,
    "title": "Prewarm Performance",
    "tags": ["prewarm", "performance", "worker"],
    "panels": [
      {
        "id": 1,
        "title": "Environment Prewarm Hit Rate (%)",
        "type": "stat",
        "targets": [
          {
            "expr": "100 * (fetchml_prewarm_env_hit_total / clamp_min(fetchml_prewarm_env_hit_total + fetchml_prewarm_env_miss_total, 1))",
            "legendFormat": "{{worker_id}}"
          }
        ],
        "gridPos": {"h": 6, "w": 6, "x": 0, "y": 0},
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "thresholds": {
              "steps": [
                {"color": "red", "value": 0},
                {"color": "yellow", "value": 50},
                {"color": "green", "value": 80}
              ]
            }
          }
        }
      },
      {
        "id": 2,
        "title": "Snapshot Prewarm Hit Rate (%)",
        "type": "stat",
        "targets": [
          {
            "expr": "100 * (fetchml_prewarm_snapshot_hit_total / clamp_min(fetchml_prewarm_snapshot_hit_total + fetchml_prewarm_snapshot_miss_total, 1))",
            "legendFormat": "{{worker_id}}"
          }
        ],
        "gridPos": {"h": 6, "w": 6, "x": 6, "y": 0},
        "fieldConfig": {
          "defaults": {
            "unit": "percent",
            "thresholds": {
              "steps": [
                {"color": "red", "value": 0},
                {"color": "yellow", "value": 50},
                {"color": "green", "value": 80}
              ]
            }
          }
        }
      },
      {
        "id": 3,
        "title": "Environment Prewarm Hits vs Misses",
        "type": "graph",
        "targets": [
          {"expr": "rate(fetchml_prewarm_env_hit_total[5m])", "legendFormat": "hits {{worker_id}}"},
          {"expr": "rate(fetchml_prewarm_env_miss_total[5m])", "legendFormat": "misses {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
        "yAxes": [{"unit": "reqps"}]
      },
      {
        "id": 4,
        "title": "Snapshot Prewarm Hits vs Misses",
        "type": "graph",
        "targets": [
          {"expr": "rate(fetchml_prewarm_snapshot_hit_total[5m])", "legendFormat": "hits {{worker_id}}"},
          {"expr": "rate(fetchml_prewarm_snapshot_miss_total[5m])", "legendFormat": "misses {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
        "yAxes": [{"unit": "reqps"}]
      },
      {
        "id": 5,
        "title": "Environment Build Time",
        "type": "graph",
        "targets": [
          {"expr": "rate(fetchml_prewarm_env_time_seconds_total[5m])", "legendFormat": "build time {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8},
        "yAxes": [{"unit": "seconds"}]
      },
      {
        "id": 6,
        "title": "Snapshot Prewarm Time",
        "type": "graph",
        "targets": [
          {"expr": "rate(fetchml_prewarm_snapshot_time_seconds_total[5m])", "legendFormat": "prewarm time {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16},
        "yAxes": [{"unit": "seconds"}]
      },
      {
        "id": 7,
        "title": "Environment Images Built",
        "type": "graph",
        "targets": [
          {"expr": "increase(fetchml_prewarm_env_built_total[1h])", "legendFormat": "built {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 6, "x": 12, "y": 16},
        "yAxes": [{"unit": "short"}]
      },
      {
        "id": 8,
        "title": "Snapshots Prewarmed",
        "type": "graph",
        "targets": [
          {"expr": "increase(fetchml_prewarm_snapshot_built_total[1h])", "legendFormat": "prewarmed {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 6, "x": 18, "y": 16},
        "yAxes": [{"unit": "short"}]
      },
      {
        "id": 9,
        "title": "Prewarm Efficiency",
        "type": "graph",
        "targets": [
          {"expr": "fetchml_prewarm_env_hit_total + fetchml_prewarm_snapshot_hit_total", "legendFormat": "total hits {{worker_id}}"},
          {"expr": "fetchml_prewarm_env_miss_total + fetchml_prewarm_snapshot_miss_total", "legendFormat": "total misses {{worker_id}}"}
        ],
        "gridPos": {"h": 8, "w": 24, "x": 0, "y": 24},
        "yAxes": [{"unit": "short"}]
      }
    ],
    "time": {"from": "now-1h", "to": "now"},
    "refresh": "5s"
  }
}
