Menu

Caution

Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

discovery.gce

discovery.gce allows retrieving scrape targets from Google Compute Engine (GCE) instances. The private IP address is used by default, but may be changed to the public IP address with relabeling.

Credentials are discovered by the Google Cloud SDK default client by looking in the following places, preferring the first location found:

  1. a JSON file specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
  2. a JSON file in the well-known path $HOME/.config/gcloud/application_default_credentials.json.
  3. fetched from the GCE metadata server.

If the Agent is running within GCE, the service account associated with the instance it is running on should have at least read-only permissions to the compute resources. If running outside of GCE make sure to create an appropriate service account and place the credential file in one of the expected locations.

Usage

river
discovery.gce "LABEL" {
  project = "PROJECT_NAME" 
  zone    = "ZONE_NAME"
}

Arguments

The following arguments are supported:

NameTypeDescriptionDefaultRequired
projectstringThe GCP Project.yes
zonestringThe zone of the scrape targets.yes
filterstringFilter can be used optionally to filter the instance list by other criteria.no
refresh_intervaldurationRefresh interval to re-read the instance list."60s"no
portintThe port to scrape metrics from. If using the public IP address, this must instead be specified in the relabeling rule.80no
tag_separatorstringThe tag separator is used to separate the tags on concatenation.","no

For more information on the syntax of the filter argument, refer to Google’s filter documentation for Method: instances.list.

Exported fields

The following fields are exported and can be referenced by other components:

NameTypeDescription
targetslist(map(string))The set of discovered GCE targets.

Each target includes the following labels:

  • __meta_gce_instance_id: the numeric id of the instance
  • __meta_gce_instance_name: the name of the instance
  • __meta_gce_label_LABEL_NAME: each GCE label of the instance
  • __meta_gce_machine_type: full or partial URL of the machine type of the instance
  • __meta_gce_metadata_NAME: each metadata item of the instance
  • __meta_gce_network: the network URL of the instance
  • __meta_gce_private_ip: the private IP address of the instance
  • __meta_gce_interface_ipv4_NAME: IPv4 address of each named interface
  • __meta_gce_project: the GCP project in which the instance is running
  • __meta_gce_public_ip: the public IP address of the instance, if present
  • __meta_gce_subnetwork: the subnetwork URL of the instance
  • __meta_gce_tags: comma separated list of instance tags
  • __meta_gce_zone: the GCE zone URL in which the instance is running

Component health

discovery.gce is only reported as unhealthy when given an invalid configuration. In those cases, exported fields retain their last healthy values.

Debug information

discovery.gce does not expose any component-specific debug information.

Debug metrics

discovery.gce does not expose any component-specific debug metrics.

Examples

river
discovery.gce "gce" {
  project = "agent"
  zone    = "us-east1-a"
}