Skip to main content
skill CX Codex

adaptive-metrics — Claude Code skill: cut Grafana Cloud Metrics cost

A skill for working with Adaptive Metrics aggregation rules: it helps shrink active-series count in Grafana Cloud Metrics and dig into a high Mimir bill.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add grafana/skills --skill adaptive-metrics -a claude-code
Open on GitHub

What adaptive-metrics does

The skill walks through Adaptive Metrics in Grafana Cloud: pull auto-recommendations from query history, apply them, then check the result against grafanacloud_instance_active_series. Separate workflows cover hand-written rules with exact or regex matching, dropping unused metrics, and stripping labels like pod_uid, service_instance_id and version.

Inside are curl calls to the adaptive-metrics.grafana.net API and to the metrics query endpoint, example rule payloads, a grep check across dashboards and alerts, and an Alloy write_relabel_config fallback. You need a paid Grafana Cloud Metrics plan, an API key with metrics:write for the Adaptive Metrics API, and a separate token with metrics:read for the verification queries — those use HTTP basic auth, not the Bearer key. Mix the two up and the check quietly returns nothing, which looks like the rule failed.

Rules take effect within about 5 minutes; the full billing impact shows up within an hour. Rollback means deleting the rule through the API or flipping Disable in the UI. High-cardinality samples keep flowing — the dropped labels just stop counting toward the bill.

What it helps with

  • shrink active-series count in Grafana Cloud Metrics
  • hunt high-cardinality labels such as pod_uid and version
  • apply auto-recommendations built from query history
  • drop metrics nobody queries
  • compare grafanacloud_instance_active_series before and after rules

Example prompts for the agent

  • List the Adaptive Metrics recommendations sorted by series reduction
  • Create a rule that drops the version and go_version labels from process_cpu_seconds_total
  • Find unused metrics and prepare to drop them through Alloy

How to install adaptive-metrics

1Skills CLI (Vercel)

npx skills add grafana/skills --skill adaptive-metrics -a claude-code

2Manually: put the files in place

~/.claude/skills/adaptive-metrics/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/adaptive-metrics/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about adaptive-metrics

How do I install adaptive-metrics in Claude?

Run npx skills add grafana/skills --skill adaptive-metrics -a claude-code. The skill lands in ~/.claude/skills/adaptive-metrics/SKILL.md.

What does adaptive-metrics do?

It guides you through Adaptive Metrics aggregation rules: auto-recommendations, custom exact or regex rules, label drops, and unused-metric detection. The point is a smaller active-series bill in Grafana Cloud.

Which API permissions does it need?

The Adaptive Metrics API needs a key with metrics:write and Bearer auth. Verification queries need different access: HTTP basic auth with a numeric <metrics_user> plus a token carrying metrics:read.

Source text

SKILL.md · Apache-2.0
---
name: adaptive-metrics
license: Apache-2.0
description: Cut Grafana Cloud Metrics cost by shrinking active-series count with Adaptive Metrics aggregation rules — auto-recommendations from query history, custom exact/regex rules, label-drop config, unused-metric detection, and Alloy remote_write fallback. Use when investigating a high Mimir/Grafana Cloud bill, hunting high-cardinality labels (`pod_uid`, `service_instance_id`, `version`), pre-aggregating counters/gauges, dropping unused metrics, or measuring `grafanacloud_instance_active_series` before/after — even when the user says "reduce cardinality", "too many series", "metrics spend", "active series count is exploding", or "drop the version label" without naming Adaptive Metrics.
---

# Grafana Cloud Adaptive Metrics

> **Docs**: https://grafana.com/docs/grafana-cloud/cost-management-and-billing/reduce-costs/metrics-costs/adaptive-metrics.md

Aggregation rules that pre-shrink high-cardinality metrics before storage — directly reduces active-series billing.

## Prerequisites

- Grafana Cloud Metrics plan (any paid tier)
- API key with `metrics:write` (for the Adaptive Metrics API — `adaptive-metrics.grafana.net`, Bearer auth)
- For the verification queries: the metrics query endpoint (`prometheus-prod-XX.grafana.net`) uses HTTP basic auth — `<metrics_user>` (numeric stack/instance ID) plus a token with `metrics:read` — not the Bearer key
- Access to **Home → Adaptive Metrics** in the Cloud portal

## Common Workflows

### 1. Review + apply auto-recommendations

```bash
# 1. Pull the recommendation list (sorted by series-reduction impact)
curl -s -H "Authorization: Bearer <KEY>" \
  "https://adaptive-metrics.grafana.net/api/v1/recommendations" \
  | jq '.recommendations[] | {metric_name, current_series, projected_series, estimated_reduction_percent}'

# 2. Capture the baseline series count for the target metric
#    (metrics query endpoint = basic auth, not the Bearer key)
curl -s -u "<metrics_user>:<metrics_token>" \
  "https://prometheus-prod-XX.grafana.net/api/prom/api/v1/query?query=count({__name__=\"process_cpu_seconds_total\"})" \
  | jq '.data.result[0].value[1]'   # → e.g. "12480"

# 3. Apply the recommendation (or click Apply in the UI)
curl -s -X POST -H "Authorization: Bearer <KEY>" \
  "https://adaptive-metrics.grafana.net/api/v1/recommendations/<ID>/apply"

# 4. Wait ~5 min. Verify — re-run the count query; expect a large drop.
#    Also check the saving metric:
#      grafanacloud_instance_active_series_dropped_by_aggregation_rules
```

**Rollback** — delete the rule:

```bash
curl -s -H "Authorization: Bearer <KEY>" \
  "https://adaptive-metrics.grafana.net/api/v1/rules" | jq '.rules[] | {id, metric_name}'
curl -s -X DELETE -H "Authorization: Bearer <KEY>" \
  "https://adaptive-metrics.grafana.net/api/v1/rules/<RULE_ID>"
# Or in the UI: Rules → row → Disable
```

### 2. Hand-write a custom rule

```bash
# 1. Sanity-check the metric is not used WITH that label in dashboards/alerts
grep -r 'process_cpu_seconds_total' dashboards/ alerts/ | grep -E 'version|go_version'
# Expect no hits → safe to drop.

# 2. Create the rule
curl -s -X POST -H "Authorization: Bearer <KEY>" -H "Content-Type: application/json" \
  "https://adaptive-metrics.grafana.net/api/v1/rules" \
  -d '{"rules":[{"metric_name":"process_cpu_seconds_total","match_type":"MATCH_TYPE_EXACT",
                 "drop_labels":["version","go_version"],
                 "aggregations":[{"type":"AGGREGATION_TYPE_SUM"}]}]}'

# 3. Verify — same count() query as above; series count should drop within 5 min.
```

Full payloads (regex match, aggregation types, all caveats): [`references/api.md`](references/api.md).

### 3. Drop unused metrics entirely

```bash
# 1. List unused metrics
curl -s -H "Authorization: Bearer <KEY>" \
  "https://adaptive-metrics.grafana.net/api/v1/usage-analysis?filter=unused" | \
  jq '.metrics[] | {metric_name, series_count, last_queried}'

# 2. Confirm not referenced in dashboards / alerts / recording rules
grep -r '<METRIC_NAME>' dashboards/ alerts/ recording-rules/

# 3. Add a write_relabel_config drop in Alloy (full block in references/api.md)
#    Reload Alloy: curl -X POST http://localhost:12345/-/reload

# 4. Verify — the metric should no longer appear in series counts after ~10 min
curl -s -u "<metrics_user>:<metrics_token>" \
  'https://prometheus-prod-XX.grafana.net/api/prom/api/v1/label/__name__/values' | jq '.data | index("<METRIC_NAME>")'  # → null
```

## Measure the impact

```promql
# Total active series (billed unit)
grafanacloud_instance_active_series

# Series specifically dropped by Adaptive Metrics rules
grafanacloud_instance_active_series_dropped_by_aggregation_rules
```

Rules take effect within ~5 minutes; full billing impact appears within an hour. The original high-cardinality samples keep flowing but the dropped labels no longer count toward billing.

## Resources

- [Adaptive Metrics docs](https://grafana.com/docs/grafana-cloud/cost-management-and-billing/reduce-costs/metrics-costs/adaptive-metrics/)
- [Adaptive Logs docs](https://grafana.com/docs/grafana-cloud/cost-management-and-billing/reduce-costs/logs-costs/adaptive-logs/)
- [Cardinality in Prometheus](https://grafana.com/docs/grafana-cloud/send-data/metrics/cardinality/)

© grafana · Apache-2.0 · grafana/skills

Similar skills

All skills for DevOps and infrastructure →

From the same set51

testing Sets up uptime probes, k6 load tests, and frontend observability through Grafana Cloud. Use it before a release or when investigating failures. CX Codex +1 4,200installs cue-kind-definition Walks an agent through CUE kind definitions in grafana-app-sdk apps: spec and status schemas, versions, field constraints and codegen. CX Codex +1 4,200installs reconciler-logic Helps implement reconcilers and watchers for grafana-app-sdk applications. Guides reconcile loops, atomic status updates, and resource filters. CX Codex +1 4,200installs app-sdk-concepts This skill guides Grafana App Platform work: choose a deployment mode, scaffold an app, and connect CUE schemas with generated Go logic. CX Codex +1 4,200installs private-connectivity Sets up private network connectivity to Grafana Cloud over AWS PrivateLink, Azure Private Link, GCP Private Service Connect and PDC. Useful when telemetry must stay off the public internet. CX Codex +1 4,100installs ml-ai Enables machine learning and AI features in Grafana Cloud. It helps set up Prophet forecasts, DBSCAN outlier alerts, and Sift root-cause investigations. CX Codex +1 4,100installs react-19-plugin-migration This skill guides changes that prepare a Grafana plugin for React 19 compatibility without upgrading React itself. Use it to scan a plugin and work through the migration steps. CX Codex +1 4,100installs admin A skill for Grafana Cloud account work: creates stacks, mints service-account tokens, configures SSO and RBAC roles. CX Codex +1 4,200installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor