adaptive-metrics — скилл для Claude Code: снижение счёта Grafana Cloud
Скилл для работы с правилами агрегации Adaptive Metrics: помогает уменьшить число активных серий в Grafana Cloud Metrics и разобраться с высоким счётом за Mimir.
npx skills add grafana/skills --skill adaptive-metrics -a claude-codeЧто делает adaptive-metrics
Скилл описывает рабочий процесс вокруг Adaptive Metrics в Grafana Cloud: как вытянуть авторекомендации из истории запросов, применить их и потом проверить результат по метрике grafanacloud_instance_active_series. Есть отдельные сценарии для ручных правил с точным или regex-совпадением, для удаления неиспользуемых метрик и для отбрасывания меток вроде pod_uid, service_instance_id и version.
Внутри — команды curl к API adaptive-metrics.grafana.net и к эндпоинту запросов метрик, примеры payload для правил, проверка через grep по дашбордам и алертам, а также запасной вариант с write_relabel_config в Alloy. Для работы нужен платный план Grafana Cloud Metrics, ключ API с правом metrics:write для Adaptive Metrics API и отдельный токен с metrics:read для проверочных запросов — там HTTP basic auth, а не Bearer. Если перепутать эти два способа авторизации, проверка молча вернёт пустой результат, и покажется, что правило не сработало.
Правила вступают в силу примерно за 5 минут, полный эффект на биллинг виден в течение часа. Откатить изменение можно удалением правила через API или переключателем Disable в интерфейсе. Исходные сэмплы с высокой кардинальностью продолжают поступать, просто отброшенные метки больше не считаются в счёте.
Какие задачи решает
- сократить число активных серий в Grafana Cloud Metrics
- найти метки с высокой кардинальностью вроде
pod_uidиversion - применить авторекомендации из истории запросов
- удалить метрики, которые никто не запрашивает
- сравнить
grafanacloud_instance_active_seriesдо и после правил
Примеры запросов агенту
- Покажи рекомендации Adaptive Metrics и отсортируй их по сокращению серий
- Создай правило, которое дропает метки
versionиgo_versionуprocess_cpu_seconds_total - Проверь, какие метрики не использовались, и подготовь их удаление через Alloy
Как установить adaptive-metrics
1Через Skills CLI (Vercel)
npx skills add grafana/skills --skill adaptive-metrics -a claude-code2Вручную: положить файлы
~/.claude/skills/adaptive-metrics/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/adaptive-metrics/
1Через Skills CLI (Vercel)
npx skills add grafana/skills --skill adaptive-metrics -a codex2Вручную: положить файлы
.agents/skills/adaptive-metrics/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add grafana/skills --skill adaptive-metrics -a cursor2Вручную: положить файлы
.cursor/skills/adaptive-metrics/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install grafana/skills adaptive-metrics2Вручную: положить файлы
.github/skills/adaptive-metrics/SKILL.md1Через Skills CLI (Vercel)
npx skills add grafana/skills --skill adaptive-metrics -a gemini-cli2Командой платформы
gemini skills install https://github.com/grafana/skills --path skills/grafana-cloud/adaptive-metricsВручную: положить файлы
.devin/skills/adaptive-metrics/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add grafana/skills --skill adaptive-metrics -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Из того же набора44
Похожие
Рядом в теме «DevOps и инфраструктура»
Всё по теме «DevOps и инфраструктура» →Вопросы о adaptive-metrics
Как установить adaptive-metrics в Claude?
Выполните npx skills add grafana/skills --skill adaptive-metrics -a claude-code. Скилл окажется в ~/.claude/skills/adaptive-metrics/SKILL.md.
Что делает adaptive-metrics?
Проводит через правила агрегации Adaptive Metrics: авторекомендации, ручные правила с точным или regex-совпадением, отбрасывание меток и поиск неиспользуемых метрик. Цель — уменьшить счёт за активные серии в Grafana Cloud.
Какие права нужны для ключа API?
Для Adaptive Metrics API — ключ с metrics:write и Bearer-авторизацией. Для проверочных запросов нужен другой доступ: HTTP basic auth с числовым <metrics_user> и токеном с metrics:read.
Исходный текст
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