用 gcloud 對 GCP 專案做 Cloud Monitoring 被動根因排查。當服務出事、收到告警、或要查「現在哪些告警在燒 / 哪個 pod 燒資源 / uptime 失敗 / 指標斷線」時使用。預設告警驅動掃描,支援確認後安全修復。僅適用具 gcloud 認證的環境。
How this skill is triggered — by the user, by Claude, or both
Slash command
/gcp-monitoring-diagnose:gcp-monitoring-diagnoseThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
用 `gcloud` + Monitoring REST API 對任意 GCP 專案做**被動根因排查**。
用 gcloud + Monitoring REST API 對任意 GCP 專案做被動根因排查。
gcloud 已認證且為個人帳號(修復動作要可追溯)roles/monitoring.viewer(讀);修復另需寫入權限scripts/ 路徑下有 lib.sh、metrics.sh、snapshot.sh、safe-apply.sh入口判斷
告警掃描(預設起點)
bash scripts/snapshot.sh <project>
會重放所有 enabled 告警(PromQL + threshold 兩種)算出「🔥 正在燒的告警」,並列 uptime 狀態。 threshold 重放會完整套用 policy 的 aggregations,避免累積型指標誤判。
下鑽 root cause:對 firing 的告警,依下表用 metrics.sh 拉證據。
bash scripts/metrics.sh <project> '<filter>' [minutes] # 拉 time series
bash scripts/metrics.sh <project> '<promql>' [minutes] --promql # PromQL instant
報告:輸出根因 + 證據(指標值、告警條件、近期 audit log 誰動過)。查誰改過設定:
gcloud logging read 'logName="projects/<project>/logs/cloudaudit.googleapis.com%2Factivity" AND protoPayload.serviceName="monitoring.googleapis.com"' --project=<project> --limit=5 --freshness=7d --format="table(timestamp,protoPayload.authenticationInfo.principalEmail,protoPayload.methodName)"
修復(可選,需使用者確認):只在白名單內,透過 safe-apply。
bash scripts/safe-apply.sh "<動作描述>" "<gcloud/kubectl 指令>" "<rollback 指令>"
| 症狀 | 下鑽手法 |
|---|---|
| uptime check 失敗 | metrics.sh <p> 'metric.type="monitoring.googleapis.com/uptime_check/check_passed"' 看哪個 checker_location 為 false |
| 告警該觸發沒觸發 / 觸發找不到原因 | 讀該 policy 條件(gcloud alpha monitoring policies list),用 metrics 拉同指標跟閾值比對 |
| pod 燒 CPU | metrics.sh <p> 'metric.type="kubernetes.io/container/cpu/core_usage_time"' |
| pod 燒記憶體 | metrics.sh <p> 'metric.type="kubernetes.io/container/memory/used_bytes"' |
| CrashLoopBackOff / Pending / 重啟 | metrics.sh <p> 'kube_pod_container_status_waiting_reason{...}' --promql;kubectl 看事件 |
| Deployment 副本不足 | 比對 desired vs ready replica 指標 |
| PVC 使用率高 | metrics.sh <p> 'metric.type="kubernetes.io/pod/volume/utilization"' |
| 指標斷線(沒資料) | 先確認 filter 正確、再確認 metrics-scope 是否涵蓋來源 project(非「沒資料」就是 scope 錯) |
| 告警通知沒收到 | gcloud alpha monitoring channels list 看 channel 是否 enabled |
| ✅ Monitoring 設定 | ✅ GKE 輕量(可逆) | ⛔ 絕不碰(只給手動建議) |
|---|---|---|
| 建/修 uptime check、調告警閾值、啟用停用、補通知管道、snooze、建 dashboard | kubectl rollout restart、kubectl scale --replicas | 刪非自建資源、改 IAM、改/刪 PVC/StatefulSet 資料、改 secret、改 image/env/limit、apply 任意 manifest |
超出白名單 → 只輸出建議的手動步驟,不執行。
safe-apply.sh,不要直接執行變更指令(確保 guard + 留痕 + 確認)。gcloud config get-value account 是個人帳號;safe-apply 會擋 SA。delete)時,務必帶 --quiet;否則 gcloud 自己的互動確認會卡住(stdin 已被 safe-apply 的確認消耗),指令以非 0 退出。safe-apply 的確認應是唯一確認點。Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub cm-ailab-cc-plugins/marketplace --plugin gcp-monitoring-diagnose