mcpField
I
infrastructure

infrastructure

github.com/grafana云与 DevOps2954.4k 次安装1 天前更新
代码仓库

关于 infrastructure

用于配置 Grafana Cloud 基础设施监控的技能,覆盖 Kubernetes、主机、容器和云服务商遥测。内容介绍通过 k8s-monitoring Helm chart 或 Alloy 接入,并提供验证与故障排查指引。

主要功能

  1. 01Helm chart 部署 Kubernetes 监控
  2. 02使用 Alloy 采集主机指标
  3. 03配置 AWS、Azure、GCP 数据源
  4. 04检查采集状态并排查故障

适用场景

  1. 01将 Kubernetes 集群接入 Grafana Cloud
  2. 02采集 Linux 主机指标
  3. 03查询 AWS、Azure 或 GCP 指标

安装

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

$npx skills add https://github.com/grafana/skills --skill infrastructure

安装后在 Claude Code 中输入/infrastructure确认已加载。

附带文件references/clouds-and-hosts.mdreferences/k8s-monitoring-values.md

详细介绍

Grafana Cloud 基础设施监控

文档:https://grafana.com/docs/grafana-cloud/monitor-infrastructure/

K8s、主机、容器和云提供商遥测数据,大多通过 grafana/k8s-monitoring Helm chart 或 Alloy 获取。

前提条件

  • Grafana Cloud 堆栈,包含 Prometheus / Loki / Tempo 端点和 API 密钥(metrics:write、logs:write、traces:write)
  • 对于 Kubernetes:集群、helm 3.x,以及指向该集群的 kubectl context
  • 对于主机 / Docker:在节点上安装 Alloy

常见工作流

1. 接入 Kubernetes 集群(k8s-monitoring chart)
# 1. Create the namespace + secret
kubectl create namespace monitoring
kubectl create secret generic grafana-cloud-secret \
  -n monitoring --from-literal=api-key=<your-api-key>

# 2. Install — values.yaml in references/k8s-monitoring-values.md
helm repo add grafana https://grafana.github.io/helm-charts && helm repo update
helm install k8s-monitoring grafana/k8s-monitoring \
  --version 4.1.4 -n monitoring -f values.yaml

# 3. Verify every pod is Running
kubectl get pods -n monitoring
# Expect alloy-*, kube-state-metrics-*, node-exporter-*, etc. all Ready.

# 4. Verify no error logs in the metrics/logs/traces Alloys
kubectl -n monitoring logs deploy/k8s-monitoring-alloy-metrics --tail=50 | grep -iE 'error|level=err' || echo "clean"

# 5. Verify telemetry landed in Grafana Cloud
#    PromQL on the metrics datasource (should be > 0):
#      sum(up{cluster="production-us-east"})
#    LogQL on Loki:
#      sum(count_over_time({cluster="production-us-east"}[5m]))

完整的 values.yaml、关键 PromQL、仪表板 ID(15520、1860、14282…)和告警规则:references/k8s-monitoring-values.md。

2. 监控 Linux 主机
# 1. /etc/alloy/config.alloy — see references/clouds-and-hosts.md for the full block
prometheus.exporter.unix "host"  { rootfs_path = "/" }
prometheus.scrape         "node" { targets = prometheus.exporter.unix.host.targets
                                   forward_to = [prometheus.remote_write.cloud.receiver] }
# 2. Reload Alloy and verify the unix exporter is up
systemctl reload alloy
curl -s http://localhost:12345/api/v0/web/components | jq '.[] | select(.id|contains("prometheus.exporter.unix"))'

# 3. Verify in Grafana Cloud — open the "Node Exporter Full" dashboard (ID 1860)
#    and pick your host from the `instance` dropdown.
3. 拉取 AWS / Azure / GCP 指标

配置数据源(完整 YAML 见 [references/clouds-and-hosts.md](references/clouds-and-hosts.md),然后:

# 1. After provisioning, restart Grafana to pick up the file
# 2. Verify the datasource — Grafana → Connections → Data sources → "Test"
#    Expect "Successfully queried the CloudWatch metrics API" (or equivalent).
# 3. Confirm a query — Explore → datasource → metric e.g.
#    CloudWatch namespace AWS/EC2 metric CPUUtilization, last 1h.

故障排除

  • chart 已安装,但 Cloud 中没有指标 → 检查 grafana-cloud-secret 的 api-key 值;检查 Alloy 日志中是否有 401
  • kube-state-metrics Pod 处于 Pending 状态 → 可能是 RBAC 问题;重新应用 chart 的 CRDs/CRBs
  • Node-exporter Pod 处于 CrashLoopBackOff 状态 → 通常是 hostNetwork: true 与主机的 :9100 端口冲突;更改端口
  • CloudWatch “拒绝访问” → IAM 角色缺少 cloudwatch:GetMetricData、cloudwatch:ListMetrics

资源

评论

支持 Markdown