Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install cost-management@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin cost-management v1.0.0 follows the Agent Plugins spec.
gh skills-hub install cost-management Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/cost-management/ Extract the ZIP to .github/skills/ in your repo. The folder name must match cost-management for Copilot to auto-discover it.
Skill Files (3)
SKILL.md 4.4 KB
---
name: cost-management
license: Apache-2.0
description: Cut your Grafana Cloud bill by attributing spend to teams and reducing telemetry volume. Covers FOCUS-compliant billing dashboards, cost-attribution labels in Alloy, Adaptive Metrics (cardinality reduction), Adaptive Logs (drop/sample), Adaptive Traces (tail sampling), usage alerts, and an optimization checklist. Use when investigating a high Grafana Cloud bill, attributing observability cost to a team or service, reducing active series / log bytes / trace spans, or setting up usage / quota alerts — even when the user says "our Grafana bill is too high", "who's burning the most metrics", "drop debug logs", "sample our traces", or "alert me before we hit quota" without naming Cost Management.
---
# Grafana Cloud Cost Management
> **Docs**: https://grafana.com/docs/grafana-cloud/cost-management-and-billing/
Reduce metric / log / trace spend with Adaptive signals + cost-attribution labels.
## Prerequisites
- A Grafana Cloud stack with Adaptive Metrics / Logs / Traces enabled (visible under **Cost Management**)
- Alloy (or Grafana Agent) ingesting telemetry, with API key in scope `metrics:write` + `logs:write` (+ `traces:write`)
- Admin access to the stack to apply Adaptive recommendations
## Common Workflows
### 1. Attribute cost to a team / service
```alloy
# 1. Add external labels in Alloy (metrics + logs configs)
prometheus.remote_write "cloud" {
endpoint { url = sys.env("PROMETHEUS_URL") /* ... */ }
external_labels = { team = "platform", project = "checkout-service" }
}
```
```bash
# 2. Reload Alloy
curl -X POST http://localhost:12345/-/reload
# 3. Verify labels arrived in Grafana Cloud
# In Explore, run: count by (team, project) ({__name__=~".+"})
# Then visit Cost Management → group by `team` / `project`
```
See [`references/adaptive-signals.md`](references/adaptive-signals.md) for the full Alloy snippet.
### 2. Cut metric cardinality with Adaptive Metrics
```bash
# 1. Pull recommendations
curl https://<stack>.grafana.net/api/plugins/grafana-adaptive-metrics-app/resources/v1/recommendations \
-H "Authorization: Bearer <token>" | jq '.recommendations | length'
# 2. In the UI: Grafana Cloud → Adaptive Metrics → review rules sorted by series-reduction impact
# 3. Test in "Preview" mode before applying
# 4. Apply (takes effect within 5 min)
# 5. Verify — series count should drop on the affected metrics
# Before applying, capture baseline:
# count({__name__="http_request_duration_seconds_bucket"})
# Wait 10 min after apply, run again — expect 10x+ reduction for high-card metrics.
# Rollback if needed: open the rule in the UI → Disable, or DELETE /v1/rules/<id>.
```
### 3. Drop noisy logs in Alloy
```alloy
# 1. Add a filter stage (see references/adaptive-signals.md for the full block)
loki.process "filter_logs" {
forward_to = [loki.write.cloud.receiver]
stage.drop { expression = ".*GET /health.*" }
}
```
```bash
# 2. Reload Alloy
curl -X POST http://localhost:12345/-/reload
# 3. Verify the filter — health logs should NOT appear in Logs Drilldown
# LogQL check (should return 0):
# sum(rate({app="my-app"} |= "GET /health" [5m]))
# Bytes-ingested should also drop. Compare 24h before/after:
# sum(increase(loki_ingester_chunk_size_bytes_sum[24h])) by (namespace)
```
### 4. Set a usage alert before you hit quota
See [`references/alerts-and-queries.md`](references/alerts-and-queries.md) for ready-to-paste rules (`MetricsUsageHigh`, `LogsIngestionHigh`).
## Optimization checklist
- [ ] Apply Adaptive Metrics recommendations — typically reduces series 40-60%
- [ ] Drop health/readiness probe logs in Alloy
- [ ] Tail-sample traces to 5-10% + keep errors / slow spans
- [ ] Add `team` + `project` external labels to every Alloy config
- [ ] Set usage alerts at 80% of quota
- [ ] Replace expensive ad-hoc queries with recording rules
## References
- [`references/adaptive-signals.md`](references/adaptive-signals.md) — Adaptive Metrics / Logs / Traces config; cost-attribution labels
- [`references/alerts-and-queries.md`](references/alerts-and-queries.md) — usage alert rules, cost-finding PromQL, billing-unit table
## Resources
- [Cost Management docs](https://grafana.com/docs/grafana-cloud/cost-management-and-billing/)
- [Adaptive Metrics](https://grafana.com/docs/grafana-cloud/cost-management-and-billing/reduce-costs/metrics-costs/adaptive-metrics/)
- [Adaptive Logs](https://grafana.com/docs/grafana-cloud/cost-management-and-billing/reduce-costs/logs-costs/)
adaptive-signals.md 2.1 KB
# Adaptive Signals — config snippets
## Adaptive Metrics aggregation rule (YAML)
```yaml
# Keep only meaningful labels for HTTP histogram; drops pod/container/instance/node
- match: "^http_request_duration_seconds.*"
action: keep
match_labels:
- method
- status_code
- service
```
After Apply takes effect within 5 minutes. Recommendations are also exposed via the API:
```bash
curl https://<stack>.grafana.net/api/plugins/grafana-adaptive-metrics-app/resources/v1/recommendations \
-H "Authorization: Bearer <token>"
```
## Adaptive Logs — drop & sample in Alloy
```alloy
loki.process "filter_logs" {
forward_to = [loki.write.cloud.receiver]
// Drop health-check logs
stage.drop {
expression = ".*GET /health.*"
}
// Drop debug logs
stage.drop {
source = "level"
expression = "debug"
}
// Sample verbose info logs (keep 10%)
stage.sampling {
rate = 0.1
source = "level"
value = "info"
}
}
```
## Adaptive Traces — tail-sampling in Alloy
```alloy
otelcol.processor.tail_sampling "cost_control" {
decision_wait = "10s"
policy {
name = "keep-errors"
type = "status_code"
status_code { status_codes = ["ERROR"] }
}
policy {
name = "keep-slow"
type = "latency"
latency { threshold_ms = 1000 }
}
policy {
name = "sample-rest"
type = "probabilistic"
probabilistic { sampling_percentage = 5 }
}
output {
traces = [otelcol.exporter.otlp.cloud.input]
}
}
```
## Cost attribution labels in Alloy
```alloy
prometheus.remote_write "cloud" {
endpoint {
url = sys.env("PROMETHEUS_URL")
basic_auth {
username = sys.env("PROM_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
external_labels = {
team = "platform",
project = "checkout-service",
env = "production",
}
}
loki.write "cloud" {
endpoint {
url = sys.env("LOKI_URL")
basic_auth {
username = sys.env("LOKI_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
external_labels = {
team = "platform",
project = "checkout-service",
}
}
```
alerts-and-queries.md 1.3 KB
# Usage alerts and cost queries
## Usage alerts (Prometheus rules)
```yaml
groups:
- name: grafana-cloud-usage
rules:
- alert: MetricsUsageHigh
expr: grafana_cloud_metrics_active_series / grafana_cloud_metrics_limit > 0.8
for: 1h
labels:
severity: warning
annotations:
summary: "Grafana Cloud metrics usage >80% of quota"
- alert: LogsIngestionHigh
expr: increase(grafana_cloud_logs_bytes_ingested_total[24h]) > 50e9 # 50GB/day
labels:
severity: warning
annotations:
summary: "Grafana Cloud log ingestion >50GB today"
```
## Cost-finding PromQL
```promql
# Active series (billing unit for metrics)
grafana_cloud_metrics_active_series
# Top 20 highest-cardinality metric names
topk(20, count by (__name__) ({__name__=~".+"}))
# Log bytes ingested per stream
sum(increase(loki_ingester_chunk_size_bytes_sum[24h])) by (namespace, app)
# Trace spans ingested
rate(tempo_distributor_spans_received_total[5m])
```
## Billing units
| Signal | Billing Unit |
|--------|--------------|
| Metrics | Active series (unique label combinations) |
| Logs | Bytes ingested |
| Traces | Spans ingested |
| Profiles | Bytes ingested |
| Synthetic Monitoring | Check executions |
| k6 | VUh (Virtual User hours) |
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