terraform-provider-google/website/docs/r/logging_metric.html.markdown
The Magician 4d9f0a456d Add new line before project doc bullet (#3645)
Signed-off-by: Modular Magician <magic-modules@google.com>
2019-05-17 09:58:48 -07:00

7.5 KiB

layout page_title sidebar_current description
google Google: google_logging_metric docs-google-logging-metric Logs-based metric can also be used to extract values from logs and create a a distribution of the values.

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:

## 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"
    labels {
        key = "mass"
        value_type = "STRING"
        description = "amount of matter"
    }
  }
  value_extractor = "EXTRACT(jsonPayload.request)"
  label_extractors = { "mass": "EXTRACT(jsonPayload.request)" }
  bucket_options {
    linear_buckets {
      num_finite_buckets = 3
      width = 1
      offset = 1
    }
  }
}

Argument Reference

The following arguments are supported:

  • name - (Required) The client-assigned metric identifier. Examples - "error_count", "nginx/requests". Metric identifiers are limited to 100 characters and can include only the following characters A-Z, a-z, 0-9, and the special characters _-.,+!*',()%/. The forward-slash character (/) denotes a hierarchy of name pieces, and it cannot be the first character of the name.

  • filter - (Required) An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which is used to match log entries.

  • metric_descriptor - (Required) The metric descriptor associated with the logs-based metric. Structure is documented below.

The metric_descriptor block supports:

  • value_type - (Required) Whether the measurement is an integer, a floating-point number, etc. Some combinations of metricKind and valueType might not be supported.

  • metric_kind - (Required) Whether the metric records instantaneous values, changes to a value, etc. Some combinations of metricKind and valueType might not be supported.

  • labels - (Optional) The set of labels that can be used to describe a specific instance of this metric type. For example, the appengine.googleapis.com/http/server/response_latencies metric type has a label for the HTTP response code, response_code, so you can look at latencies for successful responses or just for responses that failed. Structure is documented below.

The labels block supports:

  • key - (Required) The label key.

  • description - (Optional) A human-readable description for the label.

  • value_type - (Optional) The type of data that can be assigned to the label.


  • description - (Optional) A description of this metric, which is used in documentation. The maximum length of the description is 8000 characters.

  • label_extractors - (Optional) A map from a label key string to an extractor expression which is used to extract data from a log entry field and assign as the label value. Each label key specified in the LabelDescriptor must have an associated extractor expression in this map. The syntax of the extractor expression is the same as for the valueExtractor field.

  • value_extractor - (Optional) A valueExtractor is required when using a distribution logs-based metric to extract the values to record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax (https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified log entry field. The value of the field is converted to a string before applying the regex. It is an error to specify a regex that does not include exactly one capture group.

  • bucket_options - (Optional) The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it describes the bucket boundaries used to create a histogram of the extracted values. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The bucket_options block supports:

  • linear_buckets - (Optional) Specifies a linear sequence of buckets that all have the same width (except overflow and underflow). Each bucket represents a constant absolute uncertainty on the specific value in the bucket. Structure is documented below.

  • exponential_buckets - (Optional) Specifies an exponential sequence of buckets that have a width that is proportional to the value of the lower bound. Each bucket represents a constant relative uncertainty on a specific value in the bucket. Structure is documented below.

  • explicit - (Optional) Specifies a set of buckets with arbitrary widths. Structure is documented below.

The linear_buckets block supports:

  • num_finite_buckets - (Optional) Must be greater than 0.

  • width - (Optional) Must be greater than 0.

  • offset - (Optional) Lower bound of the first bucket.

The exponential_buckets block supports:

  • num_finite_buckets - (Optional) Must be greater than 0.

  • growth_factor - (Optional) Must be greater than 1.

  • scale - (Optional) Must be greater than 0.

The explicit block supports:

  • bounds - (Optional) The values must be monotonically increasing.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • update - Default is 4 minutes.
  • delete - Default is 4 minutes.

Import

Metric can be imported using any of these accepted formats:

$ terraform import google_logging_metric.default {{name}}

-> If you're importing a resource with beta features, make sure to include -provider=google-beta as an argument so that Terraform uses the correct provider to import your resource.