{
  "dashboard": {
    "panels": [
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "max": 100,
            "min": 0,
            "thresholds": {
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 70
                },
                {
                  "color": "red",
                  "value": 90
                }
              ]
            },
            "unit": "percent"
          }
        },
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 0,
          "y": 0
        },
        "id": 1,
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "100 - (avg by(instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)",
            "legendFormat": "{{instance}} CPU %",
            "refId": "A"
          }
        ],
        "title": "CPU 使用率 %",
        "type": "timeseries"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "max": 100,
            "min": 0,
            "thresholds": {
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 75
                },
                {
                  "color": "red",
                  "value": 90
                }
              ]
            },
            "unit": "percent"
          }
        },
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 0
        },
        "id": 2,
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100",
            "legendFormat": "{{instance}} Memory %",
            "refId": "A"
          }
        ],
        "title": "記憶體使用率 %",
        "type": "timeseries"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "unit": "short"
          }
        },
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 0,
          "y": 8
        },
        "id": 3,
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "count by(namespace) (kube_pod_info)",
            "legendFormat": "{{namespace}}",
            "refId": "A"
          }
        ],
        "title": "K3s Pod 數量 (by namespace)",
        "type": "timeseries"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "thresholds": {
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 1
                }
              ]
            },
            "unit": "short"
          }
        },
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 8
        },
        "id": 4,
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "increase(kube_pod_container_status_restarts_total[1h])",
            "legendFormat": "{{namespace}}/{{pod}}",
            "refId": "A"
          }
        ],
        "title": "K3s Pod 重啟次數",
        "type": "timeseries"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "thresholds"
            },
            "thresholds": {
              "steps": [
                {
                  "color": "red",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 10
                },
                {
                  "color": "green",
                  "value": 14
                }
              ]
            },
            "unit": "short"
          }
        },
        "gridPos": {
          "h": 6,
          "w": 6,
          "x": 0,
          "y": 16
        },
        "id": 5,
        "options": {
          "colorMode": "background",
          "reduceOptions": {
            "calcs": [
              "lastNotNull"
            ]
          },
          "textMode": "auto"
        },
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "count(up == 1)",
            "legendFormat": "UP",
            "refId": "A"
          }
        ],
        "title": "Prometheus Targets UP 數量",
        "type": "stat"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "thresholds"
            },
            "thresholds": {
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 1
                }
              ]
            },
            "unit": "short"
          }
        },
        "gridPos": {
          "h": 6,
          "w": 6,
          "x": 6,
          "y": 16
        },
        "id": 6,
        "options": {
          "colorMode": "background",
          "reduceOptions": {
            "calcs": [
              "lastNotNull"
            ]
          },
          "textMode": "auto"
        },
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "count(up == 0) or vector(0)",
            "legendFormat": "DOWN",
            "refId": "A"
          }
        ],
        "title": "Prometheus Targets DOWN",
        "type": "stat"
      },
      {
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "unit": "reqpm"
          }
        },
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 16
        },
        "id": 7,
        "targets": [
          {
            "datasource": "Prometheus",
            "expr": "rate(http_requests_total{job=\"awoooi-api\"}[5m]) * 60",
            "legendFormat": "{{method}} {{endpoint}}",
            "refId": "A"
          }
        ],
        "title": "API 請求速率 (req/min)",
        "type": "timeseries"
      }
    ],
    "refresh": "30s",
    "schemaVersion": 39,
    "tags": [
      "awoooi",
      "infra",
      "node",
      "k3s"
    ],
    "time": {
      "from": "now-3h",
      "to": "now"
    },
    "timezone": "Asia/Taipei",
    "title": "AWOOOI 基礎設施監控 — Node + K3s",
    "uid": "awoooi-infra-monitoring"
  },
  "folderId": 0,
  "overwrite": true
}
