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:
How-to Guides
Example Usage
Monitoring Metric Descriptor Basic
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.monitoring.MetricDescriptor;
import com.pulumi.gcp.monitoring.MetricDescriptorArgs;
import com.pulumi.gcp.monitoring.inputs.MetricDescriptorLabelArgs;
import com.pulumi.gcp.monitoring.inputs.MetricDescriptorMetadataArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var basic = new MetricDescriptor("basic", MetricDescriptorArgs.builder()
.description("Daily sales records from all branch stores.")
.displayName("metric-descriptor")
.labels(MetricDescriptorLabelArgs.builder()
.description("The ID of the store.")
.key("store_id")
.valueType("STRING")
.build())
.launchStage("BETA")
.metadata(MetricDescriptorMetadataArgs.builder()
.ingestDelay("30s")
.samplePeriod("60s")
.build())
.metricKind("GAUGE")
.type("custom.googleapis.com/stores/daily_sales")
.unit("{USD}")
.valueType("DOUBLE")
.build());
}
}
Monitoring Metric Descriptor Alert
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.monitoring.MetricDescriptor;
import com.pulumi.gcp.monitoring.MetricDescriptorArgs;
import com.pulumi.gcp.monitoring.AlertPolicy;
import com.pulumi.gcp.monitoring.AlertPolicyArgs;
import com.pulumi.gcp.monitoring.inputs.AlertPolicyConditionArgs;
import com.pulumi.gcp.monitoring.inputs.AlertPolicyConditionConditionThresholdArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var withAlert = new MetricDescriptor("withAlert", MetricDescriptorArgs.builder()
.description("Daily sales records from all branch stores.")
.displayName("metric-descriptor")
.metricKind("GAUGE")
.type("custom.googleapis.com/stores/daily_sales")
.unit("{USD}")
.valueType("DOUBLE")
.build());
var alertPolicy = new AlertPolicy("alertPolicy", AlertPolicyArgs.builder()
.combiner("OR")
.conditions(AlertPolicyConditionArgs.builder()
.conditionThreshold(AlertPolicyConditionConditionThresholdArgs.builder()
.comparison("COMPARISON_GT")
.duration("60s")
.filter(withAlert.type().applyValue(type -> String.format("metric.type=\"%s\" AND resource.type=\"gce_instance\"", type)))
.build())
.displayName("test condition")
.build())
.displayName("metric-descriptor")
.build());
}
}
Import
MetricDescriptor can be imported using any of these accepted formats:
$ pulumi import gcp:monitoring/metricDescriptor:MetricDescriptor default {{name}}
Properties
A detailed description of the metric, which can be used in documentation.
A concise name for the metric, which can be displayed in user interfaces. Use sentence case without an ending period, for example "Request count".
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.
The launch stage of the metric definition. Possible values are: LAUNCH_STAGE_UNSPECIFIED
, UNIMPLEMENTED
, PRELAUNCH
, EARLY_ACCESS
, ALPHA
, BETA
, GA
, DEPRECATED
.
Metadata which can be used to guide usage of the metric. Structure is documented below.
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
.
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.
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/.
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