google_monitoring_metric_descriptor

Defines a metric type and its schema. Once a metric descriptor is created, deleting or altering it stops data collection and makes the metric type's existing data unusable.

To get more information about MetricDescriptor, see:

Open in Cloud Shell

Example Usage - Monitoring Metric Descriptor Basic

resource "google_monitoring_metric_descriptor" "basic" {
  description = "Daily sales records from all branch stores."
  display_name = "metric-descriptor"
  type = "custom.googleapis.com/stores/daily_sales"
  metric_kind = "GAUGE"
  value_type = "DOUBLE"
  unit = "{USD}"
  labels {
      key = "store_id"
      value_type = "STRING"
      description = "The ID of the store."
  }
  launch_stage = "BETA"
  metadata {
    sample_period = "60s"
    ingest_delay = "30s"
  }
}
Open in Cloud Shell

Example Usage - Monitoring Metric Descriptor Alert

resource "google_monitoring_metric_descriptor" "with_alert" {
  description = "Daily sales records from all branch stores."
  display_name = "metric-descriptor"
  type = "custom.googleapis.com/stores/daily_sales"
  metric_kind = "GAUGE"
  value_type = "DOUBLE"
  unit = "{USD}"
}

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "metric-descriptor"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"${google_monitoring_metric_descriptor.with_alert.type}\" AND resource.type=\"gce_instance\""
      duration   = "60s"
      comparison = "COMPARISON_GT"
    }
  }
}

Argument Reference

The following arguments are supported:


The labels block supports:

The metadata block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

MetricDescriptor can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import MetricDescriptor using one of the formats above. For example:

import {
  id = "{{name}}"
  to = google_monitoring_metric_descriptor.default
}

When using the terraform import command, MetricDescriptor can be imported using one of the formats above. For example:

$ terraform import google_monitoring_metric_descriptor.default {{name}}

User Project Overrides

This resource supports User Project Overrides.