Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/observe-and-act/adaptive-telemetry/adaptive-metrics/manage-as-code/use-gcx-to-manage-adaptive-metrics-resources.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/observe-and-act/adaptive-telemetry/adaptive-metrics/manage-as-code/use-gcx-to-manage-adaptive-metrics-resources/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Use gcx to manage Adaptive Metrics resources
gcx is a command-line interface (CLI) that you and coding agents can use to manage Grafana resources. Use gcx metrics adaptive to list, inspect, create, update, and delete Adaptive Metrics segments, aggregation rules, recommendations, and exemptions from the command line.
To manage Adaptive Metrics resources using the HTTP API or Terraform instead, refer to Adaptive Metrics HTTP API or Adaptive Metrics Terraform provider.
Note
gcx metrics adaptivemanages Adaptive Metrics only. To manage Adaptive Logs, Adaptive Traces, or Adaptive Profiles fromgcx, usegcx logs adaptive,gcx traces adaptive, orgcx profiles adaptiveinstead. The declarativegcx resources pull/pushworkflow supports Adaptive Metrics rules, segments, and exemptions, but the rule and exemption resource adapters only manage the default segment. Use the commands on this page to manage rules and exemptions in non-default segments.
Before you begin
Authenticate
gcxwith the preferred method for your Grafana Cloud stack.To check which configuration
gcxuses, run:Bashgcx config view
Most gcx metrics adaptive commands take an optional --segment <ID> flag. If you omit it, the command operates on the default segment. To find a segment’s ID, use gcx metrics adaptive segments list.
Review and apply recommendations with gcx metrics adaptive recommendations
Use gcx metrics adaptive recommendations to list, preview, and apply recommendations. Coding agents can also use these commands to check which metrics have pending recommendations and estimate the series impact of applying them.
List recommendations for the default segment:
Bashgcx metrics adaptive recommendations listFilter by action, sort, and limit the results:
Bashgcx metrics adaptive recommendations list --action add --action update --sort savings --top 10Diff shows what applying one or more recommendations would change, without applying them:
Bashgcx metrics adaptive recommendations diff http_server_requests_seconds_sumApply one or more recommendations as rules:
Bashgcx metrics adaptive recommendations apply http_server_requests_seconds_sumPreview the effect first with
--dry-run, or apply every pending recommendation in the segment with--all:Bashgcx metrics adaptive recommendations apply --all --dry-run gcx metrics adaptive recommendations apply --allgcxasks for confirmation before it applies recommendations. To skip the prompt, add--force.
Manage aggregation rules with gcx metrics adaptive rules
Use gcx metrics adaptive rules to create, inspect, update, and delete aggregation and drop rules:
Create an aggregation rule that keeps only the
instanceandpodlabels:Bashgcx metrics adaptive rules create --metric http_server_requests_seconds_sum --keep-labels instance,pod --aggregations sum:counterTo create a drop rule instead, which discards the metric entirely, use
--dropon its own. It can’t be combined with--keep-labels,--drop-labels,--aggregations,--aggregation-interval, or--aggregation-delay:Bashgcx metrics adaptive rules create --metric http_server_requests_seconds_sum --dropGet a rule by its metric name:
Bashgcx metrics adaptive rules get http_server_requests_seconds_sum- Bash
gcx metrics adaptive rules listThis returns up to 50 rules by default and prints a truncation hint if there are more. Add
--limit 0to return all of them. Update a rule’s aggregation functions or label policy:
Bashgcx metrics adaptive rules update http_server_requests_seconds_sum --aggregations sum:counter,countDelete a rule by its metric name:
Bashgcx metrics adaptive rules delete http_server_requests_seconds_sumgcxasks for confirmation before it deletes the rule. To skip the prompt, add--force.
Manage exemptions with gcx metrics adaptive exemptions
Use gcx metrics adaptive exemptions to create, inspect, update, and delete recommendation exemptions:
Create an exemption that prevents recommendations from aggregating away the
instanceandpodlabels on a metric:Bashgcx metrics adaptive exemptions create --metric http_server_requests_seconds_sum --keep-labels instance,pod --reason "Preserve granularity for SLO dashboards"Use
--match-type prefixor--match-type suffixto exempt metrics by name pattern instead of an exact match.Exemptions expire after 30 days by default. Use
--active-intervalto set a different duration (for example,1hor90d).To stop new recommendations for the matched metrics entirely, instead of keeping specific labels, replace
--keep-labelswith--disable-recommendations. The two flags are mutually exclusive:Bashgcx metrics adaptive exemptions create --metric http_server_requests_seconds_sum --disable-recommendations --reason "Noisy metric, no longer needed"Get an exemption by its ID:
Bashgcx metrics adaptive exemptions get <ID>List exemptions in a segment, or across all segments:
Bashgcx metrics adaptive exemptions list --all-segmentsUpdate an exemption by its ID:
Bashgcx metrics adaptive exemptions update <ID> --reason "Updated justification"Delete an exemption by its ID:
Bashgcx metrics adaptive exemptions delete <ID>gcxasks for confirmation before it deletes the exemption. To skip the prompt, add--force.
Manage segments with gcx metrics adaptive segments
Use gcx metrics adaptive segments to create, inspect, update, and delete segments. For more information about how segments work, refer to Configure segmentation.
Create a segment for a team’s metrics:
Bashgcx metrics adaptive segments create --name billing --selector '{team="billing"}'Add
--auto-applyto automatically apply recommendations for the segment, or--fallback-to-defaultto apply the default segment’s rules to metrics in this segment that don’t match any segment-specific rule.Get a segment by its ID:
Bashgcx metrics adaptive segments get <ID>List all segments:
Bashgcx metrics adaptive segments listUpdate a segment’s name, selector, or auto-apply and fallback settings:
Bashgcx metrics adaptive segments update <ID> --auto-applyDelete a segment by its ID:
Bashgcx metrics adaptive segments delete <ID>gcxasks for confirmation before it deletes the segment. To skip the prompt, add--force.
Was this page helpful?
Related resources from Grafana Labs


