Grafana Cloud

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 adaptive manages Adaptive Metrics only. To manage Adaptive Logs, Adaptive Traces, or Adaptive Profiles from gcx, use gcx logs adaptive, gcx traces adaptive, or gcx profiles adaptive instead. The declarative gcx resources pull/push workflow 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

  1. Install gcx.

  2. Authenticate gcx with the preferred method for your Grafana Cloud stack.

  3. To check which configuration gcx uses, run:

    Bash
    gcx 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:

    Bash
    gcx metrics adaptive recommendations list

    Filter by action, sort, and limit the results:

    Bash
    gcx metrics adaptive recommendations list --action add --action update --sort savings --top 10
  • Diff shows what applying one or more recommendations would change, without applying them:

    Bash
    gcx metrics adaptive recommendations diff http_server_requests_seconds_sum
  • Apply one or more recommendations as rules:

    Bash
    gcx metrics adaptive recommendations apply http_server_requests_seconds_sum

    Preview the effect first with --dry-run, or apply every pending recommendation in the segment with --all:

    Bash
    gcx metrics adaptive recommendations apply --all --dry-run
    gcx metrics adaptive recommendations apply --all

    gcx asks 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 instance and pod labels:

    Bash
    gcx metrics adaptive rules create --metric http_server_requests_seconds_sum --keep-labels instance,pod --aggregations sum:counter

    To create a drop rule instead, which discards the metric entirely, use --drop on its own. It can’t be combined with --keep-labels, --drop-labels, --aggregations, --aggregation-interval, or --aggregation-delay:

    Bash
    gcx metrics adaptive rules create --metric http_server_requests_seconds_sum --drop
  • Get a rule by its metric name:

    Bash
    gcx metrics adaptive rules get http_server_requests_seconds_sum
  • List rules in a segment:

    Bash
    gcx metrics adaptive rules list

    This returns up to 50 rules by default and prints a truncation hint if there are more. Add --limit 0 to return all of them.

  • Update a rule’s aggregation functions or label policy:

    Bash
    gcx metrics adaptive rules update http_server_requests_seconds_sum --aggregations sum:counter,count
  • Delete a rule by its metric name:

    Bash
    gcx metrics adaptive rules delete http_server_requests_seconds_sum

    gcx asks 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 instance and pod labels on a metric:

    Bash
    gcx metrics adaptive exemptions create --metric http_server_requests_seconds_sum --keep-labels instance,pod --reason "Preserve granularity for SLO dashboards"

    Use --match-type prefix or --match-type suffix to exempt metrics by name pattern instead of an exact match.

    Exemptions expire after 30 days by default. Use --active-interval to set a different duration (for example, 1h or 90d).

    To stop new recommendations for the matched metrics entirely, instead of keeping specific labels, replace --keep-labels with --disable-recommendations. The two flags are mutually exclusive:

    Bash
    gcx metrics adaptive exemptions create --metric http_server_requests_seconds_sum --disable-recommendations --reason "Noisy metric, no longer needed"
  • Get an exemption by its ID:

    Bash
    gcx metrics adaptive exemptions get <ID>
  • List exemptions in a segment, or across all segments:

    Bash
    gcx metrics adaptive exemptions list --all-segments
  • Update an exemption by its ID:

    Bash
    gcx metrics adaptive exemptions update <ID> --reason "Updated justification"
  • Delete an exemption by its ID:

    Bash
    gcx metrics adaptive exemptions delete <ID>

    gcx asks 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:

    Bash
    gcx metrics adaptive segments create --name billing --selector '{team="billing"}'

    Add --auto-apply to automatically apply recommendations for the segment, or --fallback-to-default to 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:

    Bash
    gcx metrics adaptive segments get <ID>
  • List all segments:

    Bash
    gcx metrics adaptive segments list
  • Update a segment’s name, selector, or auto-apply and fallback settings:

    Bash
    gcx metrics adaptive segments update <ID> --auto-apply
  • Delete a segment by its ID:

    Bash
    gcx metrics adaptive segments delete <ID>

    gcx asks for confirmation before it deletes the segment. To skip the prompt, add --force.