Installation

Install as Agent Plugin Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install fleet-management@skills-hub

Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled). Plugin fleet-management v1.0.0 follows the Agent Plugins spec.

Install with the gh extension
gh skills-hub install fleet-management

Don't have the extension? Run gh extension install samueltauil/skills-hub first.

Download and extract to your repository:

.github/skills/fleet-management/

Extract the ZIP to .github/skills/ in your repo. The folder name must match fleet-management for Copilot to auto-discover it.

Skill Files (3)

SKILL.md 5.2 KB
---
name: fleet-management
license: Apache-2.0
description: Manage a fleet of Grafana Alloy collectors with Fleet Management — author Alloy pipelines once, target them via attribute matchers (`env="production"`, regex `region=~"us-.*"`), push remotely via OpAMP without restarting collectors. Covers pipeline create / update / matcher RPCs, collector attribute API, `remotecfg` bootstrap block (standalone + Helm), pre-deploy `alloy fmt` validation, the local Alloy UI at port 12345 for component health, and post-deploy `REMOTE_CONFIG_STATUS_APPLIED` verification. Use when standing up a Cloud Alloy fleet, pushing a config change to 200 collectors, hunting why one collector shows `REMOTE_CONFIG_STATUS_FAILED`, validating River syntax before saving, or wiring `discovery.kubernetes` → `prometheus.remote_write` — even when the user says "configure Alloy", "remote config the collectors", "push pipeline", "OpAMP", "collector is unhealthy", or "manage agent config centrally" without naming Fleet Management.
---

# Grafana Fleet Management + Alloy Configuration

> **Docs**: https://grafana.com/docs/grafana-cloud/send-data/fleet-management/

Remote pipeline distribution to Alloy collectors via OpAMP — author once, target with matchers, hot-apply (no restart).

## Prerequisites

- Grafana Cloud stack with Fleet Management enabled
- API token with Fleet Management access (`Authorization: Bearer <STACK_ID>:<TOKEN>`)
- Alloy ≥ 1.0 installed on the targets (standalone or via `grafana/alloy` Helm chart)
- `alloy` CLI locally for `alloy fmt` syntax validation

## Concepts

- **Collector** — Alloy instance with unique ID + attributes
- **Pipeline** — named Alloy River config stored in Fleet Management
- **Matcher** — selector mapping a pipeline to collectors by attribute
- **Attributes** — key/value labels on a collector (`env`, `team`, `region`)

## Common Workflows

### 1. Author + validate + deploy a pipeline

```bash
# 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. Troubleshoot a `REMOTE_CONFIG_STATUS_FAILED` collector

```bash
# 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.
```

Failure-message decoder table: [`references/api.md`](references/api.md).

### 3. Onboard a new Alloy with the bootstrap block

The bootstrap `remotecfg` block is the only local config required:

```alloy
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" }
}
```

```bash
# Verify after start
curl -s http://localhost:12345/api/v0/web/components \
  | jq '.[] | select(.id=="remotecfg") | {id, health:.health.state}'
# health.state == "healthy"
```

Full bootstrap (standalone + Helm) + Assistant tool list: [`references/bootstrap.md`](references/bootstrap.md).

## Resources

- [Fleet Management docs](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/)
- [Alloy components](https://grafana.com/docs/alloy/latest/reference/components/)
- [OpAMP spec](https://github.com/open-telemetry/opamp-spec)
references/
api.md 6.2 KB
# Fleet Management API

Endpoints are gRPC-Web — `POST` JSON to `<host>/<service>.<RPC>`.

```bash
BASE=https://fleet-management-prod-us-east-0.grafana.net
TOKEN=<STACK_ID>:<API_TOKEN>
```

## Collectors

```bash
# List all collectors + health
curl -s -X POST "$BASE/collector.v1.CollectorService/ListCollectors" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{}' | jq '.collectors[] | {id, name, remoteConfigStatus}'

# Update collector attributes (matchers target these)
curl -s -X POST "$BASE/collector.v1.CollectorService/UpdateCollector" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{
    "id": "<COLLECTOR_ID>",
    "attributes": [
      {"name":"env",   "value":"production"},
      {"name":"team",  "value":"platform"},
      {"name":"region","value":"us-east-1"}
    ]
  }'
```

Auto-set attributes on registration: `platform`, `arch`, `alloy_version`.

## Pipelines

```bash
# List
curl -s -X POST "$BASE/pipeline.v1.PipelineService/ListPipelines" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{}'

# Create (plain-text Alloy config, not base64)
curl -s -X POST "$BASE/pipeline.v1.PipelineService/CreatePipeline" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{
    "name": "k8s-metrics",
    "contents": "prometheus.scrape \"default\" {\n  targets = []\n  forward_to = []\n}",
    "matchers": [{"name":"env","value":"production","type":"EQUAL"}]
  }'

# Update — set matchers
curl -s -X POST "$BASE/pipeline.v1.PipelineService/UpdatePipeline" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{
    "id":"<PIPELINE_ID>",
    "matchers": [
      {"name":"env","value":"production","type":"EQUAL"},
      {"name":"team","value":"platform","type":"EQUAL"}
    ]
  }'
```

Matcher `type` values: `EQUAL`, `NOT_EQUAL`, `REGEX`, `NOT_REGEX`.
A pipeline with no matchers is saved but deployed to zero collectors.

## Matcher selector syntax (UI form)

| Op | Example | Meaning |
|----|---------|---------|
| `=`  | `env="production"` | Exact match |
| `!=` | `env!="dev"` | Not equal |
| `=~` | `region=~"us-.*"` | Regex match |
| `!~` | `region!~"eu-.*"` | Regex not match |

## Alloy component categories

| Category | Example components |
|----------|--------------------|
| Discovery | `discovery.kubernetes`, `discovery.docker`, `discovery.relabel` |
| Metrics   | `prometheus.scrape`, `prometheus.remote_write`, `prometheus.operator.*` |
| Logs      | `loki.source.file`, `loki.source.kubernetes`, `loki.write` |
| Traces    | `otelcol.receiver.otlp`, `otelcol.exporter.otlp` |
| Profiles  | `pyroscope.scrape`, `pyroscope.write` |
| Transform | `otelcol.processor.batch`, `otelcol.processor.filter` |

## Common failure messages

| Status message | Root cause | Fix |
|---|---|---|
| `syntax error at line N` | Invalid River syntax | Run `alloy fmt` before saving |
| `component not found: X` | Alloy version too old | Upgrade Alloy |
| `failed to unmarshal config` | Encoding error in API call | Send plain text, not base64 |
| `authentication failed` | Wrong token | Rotate and re-apply |
| `connection refused` | Network/firewall | Open egress to Fleet Management host |
## Pipeline Revision History

Every `UpdatePipeline` call creates a new revision:

```bash
# List revisions
curl -X POST $BASE/pipeline.v1.PipelineService/ListPipelineRevisions \
  -H "Authorization: Bearer $TOKEN" -d '{"pipelineId": "pipeline-id"}'

# Roll back to a previous revision
curl -X POST $BASE/pipeline.v1.PipelineService/RollbackPipeline \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"pipelineId": "pipeline-id", "revisionId": "revision-id"}'
```

## Tenant API

Returns rate limits and quotas for your Fleet Management tenant:

```bash
curl -X POST $BASE/tenant.v1.TenantService/GetLimits \
  -H "Authorization: Bearer $TOKEN" -d '{}'

# Response:
# {
#   "maxCollectors": 1000,
#   "maxPipelines": 100,
#   "maxPipelineSizeBytes": 1048576,
#   "maxMatchersPerPipeline": 10
# }
```

## Matcher Types (API form)

When constructing the JSON payload (vs the UI selector syntax above), the API expects the enum form:

| Type | Description | Example value |
|------|-------------|---------------|
| `EQUAL` | Exact match | `"production"` |
| `NOT_EQUAL` | Not equal | `"dev"` |
| `REGEX` | RE2 regex match | `"us-.*"` |
| `NOT_REGEX` | Does not match regex | `"eu-.*"` |

## remotecfg Block (Alloy)

```alloy
remotecfg {
  url = "https://fleet-management-prod-us-east-0.grafana.net"

  basic_auth {
    username = sys.env("FM_INSTANCE_ID")   // Stack ID / instance ID
    password = sys.env("FM_API_KEY")
  }

  // Attributes used to match pipeline matchers
  attributes = {
    "env"    = "production",
    "region" = "us-east-1",
    "team"   = "platform",
  }

  poll_interval = "1m"   // How often to check for config updates
  id            = ""     // Auto-generated; persist across restarts for stable ID
}
```

## Advanced Patterns

### Staged Rollout

```bash
# 1. Create canary pipeline targeting one collector by attribute
POST .../CreatePipeline
{ "name": "canary-v2",
  "matchers": [{"name": "canary", "value": "true", "type": "EQUAL"}],
  "contents": "# New config v2..." }

# 2. Add canary=true attribute to test collector
POST .../UpdateCollector
{ "id": "collector-id", "attributes": [{"name": "canary", "value": "true"}] }

# 3. Validate metrics; expand to more collectors
# 4. Update main pipeline, remove canary pipeline
```

### On-Demand Debug Pipeline

```bash
# Temporarily boost log verbosity for one collector
POST .../CreatePipeline
{ "name": "debug-001",
  "matchers": [{"name": "id", "value": "collector-001", "type": "EQUAL"}],
  "contents": "logging { level = \"debug\" }" }
# Delete when done
```

### Kubernetes DaemonSet with Auto-Attributes

```yaml
# Pass K8s metadata as env vars to Alloy
env:
  - name: K8S_NODE_NAME
    valueFrom: { fieldRef: { fieldPath: spec.nodeName } }
  - name: K8S_NAMESPACE
    valueFrom: { fieldRef: { fieldPath: metadata.namespace } }
```

```alloy
remotecfg {
  url = sys.env("FM_URL")
  basic_auth {
    username = sys.env("FM_INSTANCE_ID")
    password = sys.env("FM_API_KEY")
  }
  attributes = {
    "k8s.node.name" = sys.env("K8S_NODE_NAME"),
    "k8s.namespace" = sys.env("K8S_NAMESPACE"),
    "env"           = "production",
  }
}
bootstrap.md 1.2 KB
# Alloy bootstrap configuration

For Alloy to receive remote config from Fleet Management it needs the `remotecfg` block locally.

## Standalone Alloy

```alloy
// /etc/alloy/bootstrap.alloy
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",
    "region" = env("AWS_REGION"),
  }
}
```

## Kubernetes (grafana/alloy Helm chart)

```yaml
alloy:
  configMap:
    content: |
      remotecfg {
        url = "https://<FLEET_MANAGEMENT_HOST>"
        basic_auth {
          username = "<STACK_ID>"
          password = env("GRAFANA_CLOUD_API_KEY")
        }
        poll_frequency = "1m"
        attributes = {
          "env"     = "production",
          "cluster" = env("CLUSTER_NAME"),
        }
      }
  extraEnv:
    - name: GRAFANA_CLOUD_API_KEY
      valueFrom:
        secretKeyRef:
          name: grafana-cloud-credentials
          key:  api-key
```

## Grafana Assistant Fleet Management tools

- `fleetManagementRead` — list collectors and pipelines
- `fleetManagementWrite` — update pipeline configurations
- `alloyConfigValidation` — validate Alloy River syntax

License (Apache-2.0)

View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/grafana/skills/blob/main/LICENSE