MetricDescriptor class
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
- How-to Guides
- Official Documentation
Example Usage
Monitoring Metric Descriptor Basic
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const basic = new gcp.monitoring.MetricDescriptor("basic", {
description: "Daily sales records from all branch stores.",
displayName: "metric-descriptor",
type: "custom.googleapis.com/stores/daily_sales",
metricKind: "GAUGE",
valueType: "DOUBLE",
unit: "{USD}",
labels: [{
key: "store_id",
valueType: "STRING",
description: "The ID of the store.",
}],
launchStage: "BETA",
metadata: {
samplePeriod: "60s",
ingestDelay: "30s",
},
});
import pulumi
import pulumi_gcp as gcp
basic = gcp.monitoring.MetricDescriptor("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",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var basic = new Gcp.Monitoring.MetricDescriptor("basic", new()
{
Description = "Daily sales records from all branch stores.",
DisplayName = "metric-descriptor",
Type = "custom.googleapis.com/stores/daily_sales",
MetricKind = "GAUGE",
ValueType = "DOUBLE",
Unit = "{USD}",
Labels = new[]
{
new Gcp.Monitoring.Inputs.MetricDescriptorLabelArgs
{
Key = "store_id",
ValueType = "STRING",
Description = "The ID of the store.",
},
},
LaunchStage = "BETA",
Metadata = new Gcp.Monitoring.Inputs.MetricDescriptorMetadataArgs
{
SamplePeriod = "60s",
IngestDelay = "30s",
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/monitoring"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := monitoring.NewMetricDescriptor(ctx, "basic", &monitoring.MetricDescriptorArgs{
Description: pulumi.String("Daily sales records from all branch stores."),
DisplayName: pulumi.String("metric-descriptor"),
Type: pulumi.String("custom.googleapis.com/stores/daily_sales"),
MetricKind: pulumi.String("GAUGE"),
ValueType: pulumi.String("DOUBLE"),
Unit: pulumi.String("{USD}"),
Labels: monitoring.MetricDescriptorLabelArray{
&monitoring.MetricDescriptorLabelArgs{
Key: pulumi.String("store_id"),
ValueType: pulumi.String("STRING"),
Description: pulumi.String("The ID of the store."),
},
},
LaunchStage: pulumi.String("BETA"),
Metadata: &monitoring.MetricDescriptorMetadataArgs{
SamplePeriod: pulumi.String("60s"),
IngestDelay: pulumi.String("30s"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_monitoring_metricdescriptor" "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"
}
}
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.ArrayList;
import java.util.Arrays;
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")
.type("custom.googleapis.com/stores/daily_sales")
.metricKind("GAUGE")
.valueType("DOUBLE")
.unit("{USD}")
.labels(MetricDescriptorLabelArgs.builder()
.key("store_id")
.valueType("STRING")
.description("The ID of the store.")
.build())
.launchStage("BETA")
.metadata(MetricDescriptorMetadataArgs.builder()
.samplePeriod("60s")
.ingestDelay("30s")
.build())
.build());
}
}
resources:
basic:
type: gcp:monitoring:MetricDescriptor
properties:
description: Daily sales records from all branch stores.
displayName: metric-descriptor
type: custom.googleapis.com/stores/daily_sales
metricKind: GAUGE
valueType: DOUBLE
unit: '{USD}'
labels:
- key: store_id
valueType: STRING
description: The ID of the store.
launchStage: BETA
metadata:
samplePeriod: 60s
ingestDelay: 30s
Monitoring Metric Descriptor Alert
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const withAlert = new gcp.monitoring.MetricDescriptor("with_alert", {
description: "Daily sales records from all branch stores.",
displayName: "metric-descriptor",
type: "custom.googleapis.com/stores/daily_sales",
metricKind: "GAUGE",
valueType: "DOUBLE",
unit: "{USD}",
});
const alertPolicy = new gcp.monitoring.AlertPolicy("alert_policy", {
displayName: "metric-descriptor",
combiner: "OR",
conditions: [{
displayName: "test condition",
conditionThreshold: {
filter: pulumi.interpolate`metric.type="${withAlert.type}" AND resource.type="gce_instance"`,
duration: "60s",
comparison: "COMPARISON_GT",
},
}],
});
import pulumi
import pulumi_gcp as gcp
with_alert = gcp.monitoring.MetricDescriptor("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}")
alert_policy = gcp.monitoring.AlertPolicy("alert_policy",
display_name="metric-descriptor",
combiner="OR",
conditions=[{
"display_name": "test condition",
"condition_threshold": {
"filter": with_alert.type.apply(lambda type: f"metric.type=\"{type}\" AND resource.type=\"gce_instance\""),
"duration": "60s",
"comparison": "COMPARISON_GT",
},
}])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var withAlert = new Gcp.Monitoring.MetricDescriptor("with_alert", new()
{
Description = "Daily sales records from all branch stores.",
DisplayName = "metric-descriptor",
Type = "custom.googleapis.com/stores/daily_sales",
MetricKind = "GAUGE",
ValueType = "DOUBLE",
Unit = "{USD}",
});
var alertPolicy = new Gcp.Monitoring.AlertPolicy("alert_policy", new()
{
DisplayName = "metric-descriptor",
Combiner = "OR",
Conditions = new[]
{
new Gcp.Monitoring.Inputs.AlertPolicyConditionArgs
{
DisplayName = "test condition",
ConditionThreshold = new Gcp.Monitoring.Inputs.AlertPolicyConditionConditionThresholdArgs
{
Filter = withAlert.Type.Apply(type => $"metric.type=\"{type}\" AND resource.type=\"gce_instance\""),
Duration = "60s",
Comparison = "COMPARISON_GT",
},
},
},
});
});
package main
import (
"fmt"
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/monitoring"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
withAlert, err := monitoring.NewMetricDescriptor(ctx, "with_alert", &monitoring.MetricDescriptorArgs{
Description: pulumi.String("Daily sales records from all branch stores."),
DisplayName: pulumi.String("metric-descriptor"),
Type: pulumi.String("custom.googleapis.com/stores/daily_sales"),
MetricKind: pulumi.String("GAUGE"),
ValueType: pulumi.String("DOUBLE"),
Unit: pulumi.String("{USD}"),
})
if err != nil {
return err
}
_, err = monitoring.NewAlertPolicy(ctx, "alert_policy", &monitoring.AlertPolicyArgs{
DisplayName: pulumi.String("metric-descriptor"),
Combiner: pulumi.String("OR"),
Conditions: monitoring.AlertPolicyConditionArray{
&monitoring.AlertPolicyConditionArgs{
DisplayName: pulumi.String("test condition"),
ConditionThreshold: &monitoring.AlertPolicyConditionConditionThresholdArgs{
Filter: withAlert.Type.ApplyT(func(_type string) (string, error) {
return fmt.Sprintf("metric.type=\"%v\" AND resource.type=\"gce_instance\"", _type), nil
}).(pulumi.StringOutput),
Duration: pulumi.String("60s"),
Comparison: pulumi.String("COMPARISON_GT"),
},
},
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_monitoring_metricdescriptor" "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 "gcp_monitoring_alertpolicy" "alert_policy" {
display_name = "metric-descriptor"
combiner = "OR"
conditions {
display_name = "test condition"
condition_threshold = {
filter ="metric.type="${gcp_monitoring_metricdescriptor.with_alert.type}" AND resource.type="gce_instance""
duration = "60s"
comparison = "COMPARISON_GT"
}
}
}
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.ArrayList;
import java.util.Arrays;
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")
.type("custom.googleapis.com/stores/daily_sales")
.metricKind("GAUGE")
.valueType("DOUBLE")
.unit("{USD}")
.build());
var alertPolicy = new AlertPolicy("alertPolicy", AlertPolicyArgs.builder()
.displayName("metric-descriptor")
.combiner("OR")
.conditions(AlertPolicyConditionArgs.builder()
.displayName("test condition")
.conditionThreshold(AlertPolicyConditionConditionThresholdArgs.builder()
.filter(withAlert.type().applyValue(_type -> String.format("metric.type=\"%s\" AND resource.type=\"gce_instance\"", _type)))
.duration("60s")
.comparison("COMPARISON_GT")
.build())
.build())
.build());
}
}
resources:
withAlert:
type: gcp:monitoring:MetricDescriptor
name: with_alert
properties:
description: Daily sales records from all branch stores.
displayName: metric-descriptor
type: custom.googleapis.com/stores/daily_sales
metricKind: GAUGE
valueType: DOUBLE
unit: '{USD}'
alertPolicy:
type: gcp:monitoring:AlertPolicy
name: alert_policy
properties:
displayName: metric-descriptor
combiner: OR
conditions:
- displayName: test condition
conditionThreshold:
filter: metric.type="${withAlert.type}" AND resource.type="gce_instance"
duration: 60s
comparison: COMPARISON_GT
Import
MetricDescriptor can be imported using any of these accepted formats:
{{project}}/{{name}}{{project}} {{name}}{{name}}
When using the pulumi import command, MetricDescriptor can be imported using one of the formats above. For example:
$ pulumi import gcp:monitoring/metricDescriptor:MetricDescriptor default {{project}}/{{name}}
$ terraform import google_monitoring_metric_descriptor.default "{{project}} {{name}}"
$ pulumi import gcp:monitoring/metricDescriptor:MetricDescriptor default {{name}}
Constructors
- MetricDescriptor(String name, {MetricDescriptorArgs? args, CustomResourceOptions? options})
-
Creates a new MetricDescriptor.
nameThe Pulumi resource name.argsArguments used to configure this MetricDescriptor. The set of arguments for MetricDescriptor.optionsResource options controlling this resource's behavior. - MetricDescriptor.reference(String urn)
- Creates a typed reference to an existing MetricDescriptor resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
deletionPolicy
↔ Output<
String> -
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE.
When a 'terraform destroy' or 'pulumi up' would delete the resource,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
latefinal
-
description
↔ Output<
String?> -
A detailed description of the metric, which can be used in documentation.
latefinal
-
displayName
↔ Output<
String?> -
A concise name for the metric, which can be displayed in user interfaces. Use sentence case without an ending period, for example "Request count".
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
labels
↔ Output<
List< MetricDescriptorLabel> ?> -
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.
latefinal
-
launchStage
↔ Output<
String?> -
The launch stage of the metric definition.
Possible values are:
LAUNCH_STAGE_UNSPECIFIED,UNIMPLEMENTED,PRELAUNCH,EARLY_ACCESS,ALPHA,BETA,GA,DEPRECATED.latefinal -
metadata
↔ Output<
MetricDescriptorMetadata?> -
Metadata which can be used to guide usage of the metric.
Structure is documented below.
latefinal
-
metricKind
↔ Output<
String> -
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.latefinal -
monitoredResourceTypes
↔ Output<
List< String> > -
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.
latefinal
-
name
↔ Output<
String> -
The resource name of the metric descriptor.
latefinal
-
project
↔ Output<
String> -
The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
type
↔ Output<
String> -
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 relativeMetricName is 100. All user-defined metric types have the DNS name custom.googleapis.com, external.googleapis.com, or logging.googleapis.com/user/.
latefinal
-
unit
↔ Output<
String?> -
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).
latefinal
-
urn
↔ Output<
String> -
latefinalinherited
-
valueType
↔ Output<
String> -
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.latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {MetricDescriptorState? state, CustomResourceOptions? options}) → MetricDescriptor -
Gets an existing MetricDescriptor resource's state with the given
nameandid.