mcpField
F
fleet-management

fleet-management

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

关于 fleet-management

通过 Grafana Fleet Management 管理 Alloy 配置的技能,指导运维人员编写和验证管道、按目标分发配置并排查问题。

主要功能

  1. 01编写并验证 Alloy 管道
  2. 02使用匹配器选择采集器
  3. 03热应用远程配置
  4. 04检查采集器配置失败
  5. 05通过 remotecfg 引导 Alloy

适用场景

  1. 01向指定采集器部署管道
  2. 02调查远程配置失败
  3. 03接入 Alloy 采集器

安装

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

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

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

附带文件references/api.mdreferences/bootstrap.md

详细介绍

Grafana Fleet Management + Alloy 配置

文档:https://grafana.com/docs/grafana-cloud/send-data/fleet-management/

通过 OpAMP 向 Alloy 收集器分发远程流水线——编写一次,使用匹配器指定目标,即可热应用(无需重启)。

前提条件

  • 已启用 Fleet Management 的 Grafana Cloud 堆栈
  • 具有 Fleet Management 访问权限的 API 令牌(Authorization: Bearer <STACK_ID>:<TOKEN>)
  • 已在目标上安装 Alloy ≥ 1.0(独立安装或通过 grafana/alloy Helm 图表安装)
  • 本地安装 alloy CLI,用于通过 alloy fmt 验证语法

概念

  • 收集器——具有唯一 ID 和属性的 Alloy 实例
  • 流水线——存储在 Fleet Management 中的命名 Alloy River 配置
  • 匹配器——按属性将流水线映射到收集器的选择器
  • 属性——收集器上的键值标签(env、team、region)

常见工作流

1. 编写、验证并部署流水线
# 1. Save the pipeline to a local file (lint catches typos before remote)
cat > pipeline.alloy <<'EOF'
prometheus.scrape "default" {
  targets    = []
  forward_to = [prometheus.remote_write.grafana_cloud.receiver]
  scrape_interval = "60s"
}

prometheus.remote_write "grafana_cloud" {
  endpoint {
    url = "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"
    basic_auth {
      username = "<METRICS_USERNAME>"
      password = env("GRAFANA_CLOUD_API_KEY")
    }
  }
}
EOF

# 2. Validate syntax LOCALLY before sending to Fleet Management
alloy fmt pipeline.alloy            # rewrites in place or errors with line number
alloy validate pipeline.alloy       # full semantic check (newer Alloy releases)

# 3. Create the pipeline via API (see references/api.md for the payload schema)
BASE=https://fleet-management-prod-us-east-0.grafana.net
TOKEN=<STACK_ID>:<API_TOKEN>
PAYLOAD=$(jq -n --rawfile c pipeline.alloy '{
  name:"k8s-metrics", contents:$c,
  matchers:[{name:"env",value:"production",type:"EQUAL"}]
}')
curl -s -X POST "$BASE/pipeline.v1.PipelineService/CreatePipeline" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "$PAYLOAD" | jq

# 4. Verify it rolled out — every targeted collector should report APPLIED within 1-2 polls
curl -s -X POST "$BASE/collector.v1.CollectorService/ListCollectors" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{}' \
  | jq '.collectors[] | select(.attributes[]?.value=="production")
        | {name, remoteConfigStatus}'
# Expect every row: remoteConfigStatus == "REMOTE_CONFIG_STATUS_APPLIED"
2. 排查 REMOTE_CONFIG_STATUS_FAILED 收集器的问题
# 1. Find failed collectors and surface the error message
curl -s -X POST "$BASE/collector.v1.CollectorService/ListCollectors" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{}' \
  | jq '.collectors[] | select(.remoteConfigStatus=="REMOTE_CONFIG_STATUS_FAILED")
        | {name, msg:.remoteConfigStatusMessage}'

# 2. Re-validate the offending pipeline locally
alloy fmt pipeline.alloy

# 3. Inspect Alloy directly — UI at port 12345 shows per-component health
#    http://<COLLECTOR_HOST>:12345 → Graph / Components / Clustering tabs
kubectl -n monitoring logs -l app.kubernetes.io/name=alloy --tail=100 | grep -iE 'remote|error'

# 4. After fixing + re-pushing, re-list collectors and confirm the row flips to APPLIED.

失败消息解码表:references/api.md。

3. 使用引导配置块接入新的 Alloy

引导 remotecfg 块是唯一必需的本地配置:

remotecfg {
  url = "https://<FLEET_MANAGEMENT_HOST>"
  basic_auth { username = "<STACK_ID>"; password = env("GRAFANA_CLOUD_API_KEY") }
  poll_frequency = "1m"
  attributes = { "env" = env("ENVIRONMENT"), "team" = "platform" }
}
# Verify after start
curl -s http://localhost:12345/api/v0/web/components \
  | jq '.[] | select(.id=="remotecfg") | {id, health:.health.state}'
# health.state == "healthy"

完整的引导说明(独立安装 + Helm)和助手工具列表:references/bootstrap.md。

资源

评论

支持 Markdown