google_logging_metric

Logs-based metric can also be used to extract values from logs and create a a distribution of the values. The distribution records the statistics of the extracted values along with an optional histogram of the values as specified by the bucket options.

To get more information about Metric, see:

Open in Cloud Shell

Example Usage - Logging Metric Basic

resource "google_logging_metric" "logging_metric" {
  name   = "my-(custom)/metric"
  filter = "resource.type=gae_app AND severity>=ERROR"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "DISTRIBUTION"
    unit        = "1"
    labels {
      key         = "mass"
      value_type  = "STRING"
      description = "amount of matter"
    }
    labels {
      key         = "sku"
      value_type  = "INT64"
      description = "Identifying number for item"
    }
    display_name = "My metric"
  }
  value_extractor = "EXTRACT(jsonPayload.request)"
  label_extractors = {
    "mass" = "EXTRACT(jsonPayload.request)"
    "sku"  = "EXTRACT(jsonPayload.id)"
  }
  bucket_options {
    linear_buckets {
      num_finite_buckets = 3
      width              = 1
      offset             = 1
    }
  }
}
Open in Cloud Shell

Example Usage - Logging Metric Counter Basic

resource "google_logging_metric" "logging_metric" {
  name   = "my-(custom)/metric"
  filter = "resource.type=gae_app AND severity>=ERROR"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "INT64"
  }
}
Open in Cloud Shell

Example Usage - Logging Metric Counter Labels

resource "google_logging_metric" "logging_metric" {
  name   = "my-(custom)/metric"
  filter = "resource.type=gae_app AND severity>=ERROR"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "INT64"
    labels {
      key         = "mass"
      value_type  = "STRING"
      description = "amount of matter"
    }
  }
  label_extractors = {
    "mass" = "EXTRACT(jsonPayload.request)"
  }
}
## Example Usage - Logging Metric Logging Bucket
resource "google_logging_project_bucket_config" "logging_metric" {
    location  = "global"
    project   = "my-project-name"
    bucket_id = "_Default"
}

resource "google_logging_metric" "logging_metric" {
  name        = "my-(custom)/metric"
  filter      = "resource.type=gae_app AND severity>=ERROR"
  bucket_name = google_logging_project_bucket_config.logging_metric.id
}
Open in Cloud Shell

Example Usage - Logging Metric Disabled

resource "google_logging_metric" "logging_metric" {
  name   = "my-(custom)/metric"
  filter = "resource.type=gae_app AND severity>=ERROR"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "INT64"
  }
  disabled = true
}

Argument Reference

The following arguments are supported:


The metric_descriptor block supports:

The labels block supports:

The bucket_options block supports:

The linear_buckets block supports:

The exponential_buckets block supports:

The explicit_buckets 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

Metric can be imported using any of these accepted formats:

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

import {
  id = "{{project}} {{name}}"
  to = google_logging_metric.default
}

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

$ terraform import google_logging_metric.default {{project}} {{name}}
$ terraform import google_logging_metric.default {{name}}

User Project Overrides

This resource supports User Project Overrides.