| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # This file is automatically generated by Magic Modules and manual |
| # changes will be clobbered when the file is regenerated. |
| # |
| # Please read more about how to change this file in |
| # .github/CONTRIBUTING.md. |
| # |
| # ---------------------------------------------------------------------------- |
| subcategory: "Cloud (Stackdriver) Logging" |
| description: |- |
| 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: |
| |
| * [API documentation](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/create) |
| * How-to Guides |
| * [Official Documentation](https://cloud.google.com/logging/docs/apis) |
| |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=logging_metric_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Logging Metric Basic |
| |
| |
| ```hcl |
| 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 |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=logging_metric_counter_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Logging Metric Counter Basic |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=logging_metric_counter_labels&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Logging Metric Counter Labels |
| |
| |
| ```hcl |
| 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 |
| |
| |
| ```hcl |
| 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 |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=logging_metric_disabled&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Logging Metric Disabled |
| |
| |
| ```hcl |
| 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: |
| |
| |
| * `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. |
| |
| |
| - - - |
| |
| |
| * `description` - |
| (Optional) |
| A description of this metric, which is used in documentation. The maximum length of the |
| description is 8000 characters. |
| |
| * `bucket_name` - |
| (Optional) |
| The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects |
| are supported. The bucket has to be in the same project as the metric. |
| |
| * `disabled` - |
| (Optional) |
| If set to True, then this metric is disabled and it does not generate any points. |
| |
| * `metric_descriptor` - |
| (Optional) |
| The optional metric descriptor associated with the logs-based metric. |
| If unspecified, it uses a default metric descriptor with a DELTA metric kind, |
| INT64 value type, with no labels and a unit of "1". Such a metric counts the |
| number of log entries matching the filter expression. |
| Structure is [documented below](#nested_metric_descriptor). |
| |
| * `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](#nested_bucket_options). |
| |
| * `project` - (Optional) The ID of the project in which the resource belongs. |
| If it is not provided, the provider project is used. |
| |
| |
| <a name="nested_metric_descriptor"></a>The `metric_descriptor` block supports: |
| |
| * `unit` - |
| (Optional) |
| The unit in which the metric value is reported. It is only applicable if the valueType is |
| `INT64`, `DOUBLE`, or `DISTRIBUTION`. The supported units are a subset of |
| [The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard |
| |
| * `value_type` - |
| (Required) |
| Whether the measurement is an integer, a floating-point number, etc. |
| Some combinations of metricKind and valueType might not be supported. |
| For counter metrics, set this to INT64. |
| Possible values are: `BOOL`, `INT64`, `DOUBLE`, `STRING`, `DISTRIBUTION`, `MONEY`. |
| |
| * `metric_kind` - |
| (Required) |
| Whether the metric records instantaneous values, changes to a value, etc. |
| Some combinations of metricKind and valueType might not be supported. |
| For counter metrics, set this to DELTA. |
| Possible values are: `DELTA`, `GAUGE`, `CUMULATIVE`. |
| |
| * `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](#nested_labels). |
| |
| * `display_name` - |
| (Optional) |
| A concise name for the metric, which can be displayed in user interfaces. Use sentence case |
| without an ending period, for example "Request count". This field is optional but it is |
| recommended to be set for any metrics associated with user-visible concepts, such as Quota. |
| |
| |
| <a name="nested_labels"></a>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. |
| Default value is `STRING`. |
| Possible values are: `BOOL`, `INT64`, `STRING`. |
| |
| <a name="nested_bucket_options"></a>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](#nested_linear_buckets). |
| |
| * `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](#nested_exponential_buckets). |
| |
| * `explicit_buckets` - |
| (Optional) |
| Specifies a set of buckets with arbitrary widths. |
| Structure is [documented below](#nested_explicit_buckets). |
| |
| |
| <a name="nested_linear_buckets"></a>The `linear_buckets` block supports: |
| |
| * `num_finite_buckets` - |
| (Required) |
| Must be greater than 0. |
| |
| * `width` - |
| (Required) |
| Must be greater than 0. |
| |
| * `offset` - |
| (Required) |
| Lower bound of the first bucket. |
| |
| <a name="nested_exponential_buckets"></a>The `exponential_buckets` block supports: |
| |
| * `num_finite_buckets` - |
| (Required) |
| Must be greater than 0. |
| |
| * `growth_factor` - |
| (Required) |
| Must be greater than 1. |
| |
| * `scale` - |
| (Required) |
| Must be greater than 0. |
| |
| <a name="nested_explicit_buckets"></a>The `explicit_buckets` block supports: |
| |
| * `bounds` - |
| (Required) |
| The values must be monotonically increasing. |
| |
| ## Attributes Reference |
| |
| In addition to the arguments listed above, the following computed attributes are exported: |
| |
| * `id` - an identifier for the resource with format `{{name}}` |
| |
| |
| ## Timeouts |
| |
| This resource provides the following |
| [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: |
| |
| - `create` - Default is 20 minutes. |
| - `update` - Default is 20 minutes. |
| - `delete` - Default is 20 minutes. |
| |
| ## Import |
| |
| |
| Metric can be imported using any of these accepted formats: |
| |
| * `{{project}} {{name}}` |
| * `{{name}}` |
| |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Metric using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "{{project}} {{name}}" |
| to = google_logging_metric.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |