blob: bdc76dfbe61ef026efa5300d2eba717a63d6370f [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** 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) Monitoring"
description: |-
Defines a metric type and its schema.
---
# 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:
* [API documentation](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors)
* How-to Guides
* [Official Documentation](https://cloud.google.com/monitoring/custom-metrics/)
<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=monitoring_metric_descriptor_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 - Monitoring Metric Descriptor Basic
```hcl
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"
}
}
```
<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=monitoring_metric_descriptor_alert&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 - Monitoring Metric Descriptor Alert
```hcl
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:
* `type` -
(Required)
The metric type, including its DNS name prefix. The type is not URL-encoded. All service defined metrics must be prefixed with the service name, in the format of {service name}/{relative metric name}, such as cloudsql.googleapis.com/database/cpu/utilization. The relative metric name must have only upper and lower-case letters, digits, '/' and underscores '_' are allowed. Additionally, the maximum number of characters allowed for the relative_metric_name is 100. All user-defined metric types have the DNS name custom.googleapis.com, external.googleapis.com, or logging.googleapis.com/user/.
* `metric_kind` -
(Required)
Whether the metric records instantaneous values, changes to a value, etc. Some combinations of metricKind and valueType might not be supported.
Possible values are: `METRIC_KIND_UNSPECIFIED`, `GAUGE`, `DELTA`, `CUMULATIVE`.
* `value_type` -
(Required)
Whether the measurement is an integer, a floating-point number, etc. Some combinations of metricKind and valueType might not be supported.
Possible values are: `BOOL`, `INT64`, `DOUBLE`, `STRING`, `DISTRIBUTION`.
* `description` -
(Required)
A detailed description of the metric, which can be used in documentation.
* `display_name` -
(Required)
A concise name for the metric, which can be displayed in user interfaces. Use sentence case without an ending period, for example "Request count".
- - -
* `labels` -
(Optional)
The set of labels that can be used to describe a specific instance of this metric type. In order to delete a label, the entire resource must be deleted, then created with the desired labels.
Structure is [documented below](#nested_labels).
* `unit` -
(Optional)
The units in which the metric value is reported. It is only applicable if the
valueType is INT64, DOUBLE, or DISTRIBUTION. The unit defines the representation of
the stored metric values.
Different systems may scale the values to be more easily displayed (so a value of
0.02KBy might be displayed as 20By, and a value of 3523KBy might be displayed as
3.5MBy). However, if the unit is KBy, then the value of the metric is always in
thousands of bytes, no matter how it may be displayed.
If you want a custom metric to record the exact number of CPU-seconds used by a job,
you can create an INT64 CUMULATIVE metric whose unit is s{CPU} (or equivalently
1s{CPU} or just s). If the job uses 12,005 CPU-seconds, then the value is written as
12005.
Alternatively, if you want a custom metric to record data in a more granular way, you
can create a DOUBLE CUMULATIVE metric whose unit is ks{CPU}, and then write the value
12.005 (which is 12005/1000), or use Kis{CPU} and write 11.723 (which is 12005/1024).
The supported units are a subset of The Unified Code for Units of Measure standard.
More info can be found in the API documentation
(https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors).
* `metadata` -
(Optional)
Metadata which can be used to guide usage of the metric.
Structure is [documented below](#nested_metadata).
* `launch_stage` -
(Optional)
The launch stage of the metric definition.
Possible values are: `LAUNCH_STAGE_UNSPECIFIED`, `UNIMPLEMENTED`, `PRELAUNCH`, `EARLY_ACCESS`, `ALPHA`, `BETA`, `GA`, `DEPRECATED`.
* `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_labels"></a>The `labels` block supports:
* `key` -
(Required)
The key for this label. The key must not exceed 100 characters. The first character of the key must be an upper- or lower-case letter, the remaining characters must be letters, digits or underscores, and the key must match the regular expression [a-zA-Z][a-zA-Z0-9_]*
* `value_type` -
(Optional)
The type of data that can be assigned to the label.
Default value is `STRING`.
Possible values are: `STRING`, `BOOL`, `INT64`.
* `description` -
(Optional)
A human-readable description for the label.
<a name="nested_metadata"></a>The `metadata` block supports:
* `sample_period` -
(Optional)
The sampling period of metric data points. For metrics which are written periodically, consecutive data points are stored at this time interval, excluding data loss due to errors. Metrics with a higher granularity have a smaller sampling period. In `[duration format](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf?&_ga=2.264881487.1507873253.1593446723-935052455.1591817775#google.protobuf.Duration)`.
* `ingest_delay` -
(Optional)
The delay of data points caused by ingestion. Data points older than this age are guaranteed to be ingested and available to be read, excluding data loss due to errors. In `[duration format](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf?&_ga=2.264881487.1507873253.1593446723-935052455.1591817775#google.protobuf.Duration)`.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
* `id` - an identifier for the resource with format `{{name}}`
* `name` -
The resource name of the metric descriptor.
* `monitored_resource_types` -
If present, then a time series, which is identified partially by a metric type and a MonitoredResourceDescriptor, that is associated with this metric type can only be associated with one of the monitored resource types listed here. This field allows time series to be associated with the intersection of this metric type and the monitored resource types in this list.
## 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
MetricDescriptor can be imported using any of these accepted formats:
* `{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import MetricDescriptor using one of the formats above. For example:
```tf
import {
id = "{{name}}"
to = google_monitoring_metric_descriptor.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).