mcpField
G
gcp-logs-monitoring

gcp-logs-monitoring

github.com/bcrema云与 DevOps048 次安装32 周前更新
代码仓库

关于 gcp-logs-monitoring

通过终端检查 Google Cloud Logging 和 Cloud Monitoring 数据的 Skill。它根据项目与时间范围查询日志和指标,并通过时间戳关联结果,辅助排查问题。

主要功能

  1. 01检查前置条件和项目访问
  2. 02按过滤条件查询 Cloud Logging
  3. 03读取 Cloud Monitoring 时间序列
  4. 04关联日志与指标的时间戳
  5. 05选择表格或 JSON 输出

适用场景

  1. 01排查 Cloud Run 或 GKE 错误
  2. 02查看负载均衡器 HTTP 5xx 日志
  3. 03对照请求延迟与服务日志
  4. 04检查虚拟机 CPU 使用率

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/bcrema/runwarapp --skill gcp-logs-monitoring

安装后在 Claude Code 中输入/gcp-logs-monitoring确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

agents/
openai.yaml
scripts/
check_prereqs.sh
read_logs.sh
read_metrics.sh

详细介绍

目标

从终端快速、可重复地检查 Cloud Logging 和 Cloud Monitoring 数据。

需要收集的输入(仅在缺少时询问)

  • project_id
  • 调查的 time_window(例如,最近 30m、2h,或明确的 UTC start/end)
  • service/resource context(cloud_run_revision、k8s_container、gce_instance、负载均衡器等)
  • signals of interest(错误、延迟、CPU、内存、请求数、重启)
  • output_format(快速扫描用 table,深入分析用 json)

执行工作流

  1. 验证先决条件: bash .agents/skills/gcp-logs-monitoring/scripts/check_prereqs.sh --project <project_id>
  2. 查询 Cloud Logging: bash .agents/skills/gcp-logs-monitoring/scripts/read_logs.sh --project <project_id> --filter '<LOG_FILTER>' --freshness 1h --limit 100 --format json
  3. 查询 Cloud Monitoring 时间序列: bash .agents/skills/gcp-logs-monitoring/scripts/read_metrics.sh --project <project_id> --filter '<METRIC_FILTER>' --start <UTC_ISO8601> --end <UTC_ISO8601> --format json
  4. 关联日志与指标中的时间戳,然后总结可能的根本原因和后续检查项。

常用过滤器模板

Cloud Logging
  • Cloud Run 错误: resource.type="cloud_run_revision" severity>=ERROR
  • GKE 容器错误: resource.type="k8s_container" severity>=ERROR
  • 负载均衡器日志中的 HTTP 5xx: resource.type="http_load_balancer" jsonPayload.statusDetails=~"5.."
  • 超时文本搜索: textPayload:"timeout" OR jsonPayload.message:"timeout"
Cloud Monitoring
  • Cloud Run 请求数: metric.type="run.googleapis.com/request_count" AND resource.type="cloud_run_revision"
  • Cloud Run 请求延迟: metric.type="run.googleapis.com/request_latencies" AND resource.type="cloud_run_revision"
  • VM CPU 利用率: metric.type="compute.googleapis.com/instance/cpu/utilization" AND resource.type="gce_instance"

防护措施

  • 优先在每条命令中传入 --project,而不是更改全局 gcloud 配置。
  • 从较短的时间窗口(15m 至 2h)开始,仅在需要时扩大范围。
  • 如果输出需要解析或跨来源比较,请使用 --format json。
  • 如果身份验证或项目检查失败,请先修复环境,然后重新运行查询。

评论

支持 Markdown