Metric Args
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:
How-to Guides
Example Usage
Logging Metric Basic
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const loggingMetric = new gcp.logging.Metric("logging_metric", {
name: "my-(custom)/metric",
filter: "resource.type=gae_app AND severity>=ERROR",
metricDescriptor: {
metricKind: "DELTA",
valueType: "DISTRIBUTION",
unit: "1",
labels: [
{
key: "mass",
valueType: "STRING",
description: "amount of matter",
},
{
key: "sku",
valueType: "INT64",
description: "Identifying number for item",
},
],
displayName: "My metric",
},
valueExtractor: "EXTRACT(jsonPayload.request)",
labelExtractors: {
mass: "EXTRACT(jsonPayload.request)",
sku: "EXTRACT(jsonPayload.id)",
},
bucketOptions: {
linearBuckets: {
numFiniteBuckets: 3,
width: 1,
offset: 1,
},
},
});
import pulumi
import pulumi_gcp as gcp
logging_metric = gcp.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",
},
{
"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,
},
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var loggingMetric = new Gcp.Logging.Metric("logging_metric", new()
{
Name = "my-(custom)/metric",
Filter = "resource.type=gae_app AND severity>=ERROR",
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
MetricKind = "DELTA",
ValueType = "DISTRIBUTION",
Unit = "1",
Labels = new[]
{
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Key = "mass",
ValueType = "STRING",
Description = "amount of matter",
},
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Key = "sku",
ValueType = "INT64",
Description = "Identifying number for item",
},
},
DisplayName = "My metric",
},
ValueExtractor = "EXTRACT(jsonPayload.request)",
LabelExtractors =
{
{ "mass", "EXTRACT(jsonPayload.request)" },
{ "sku", "EXTRACT(jsonPayload.id)" },
},
BucketOptions = new Gcp.Logging.Inputs.MetricBucketOptionsArgs
{
LinearBuckets = new Gcp.Logging.Inputs.MetricBucketOptionsLinearBucketsArgs
{
NumFiniteBuckets = 3,
Width = 1,
Offset = 1,
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/logging"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := logging.NewMetric(ctx, "logging_metric", &logging.MetricArgs{
Name: pulumi.String("my-(custom)/metric"),
Filter: pulumi.String("resource.type=gae_app AND severity>=ERROR"),
MetricDescriptor: &logging.MetricMetricDescriptorArgs{
MetricKind: pulumi.String("DELTA"),
ValueType: pulumi.String("DISTRIBUTION"),
Unit: pulumi.String("1"),
Labels: logging.MetricMetricDescriptorLabelArray{
&logging.MetricMetricDescriptorLabelArgs{
Key: pulumi.String("mass"),
ValueType: pulumi.String("STRING"),
Description: pulumi.String("amount of matter"),
},
&logging.MetricMetricDescriptorLabelArgs{
Key: pulumi.String("sku"),
ValueType: pulumi.String("INT64"),
Description: pulumi.String("Identifying number for item"),
},
},
DisplayName: pulumi.String("My metric"),
},
ValueExtractor: pulumi.String("EXTRACT(jsonPayload.request)"),
LabelExtractors: pulumi.StringMap{
"mass": pulumi.String("EXTRACT(jsonPayload.request)"),
"sku": pulumi.String("EXTRACT(jsonPayload.id)"),
},
BucketOptions: &logging.MetricBucketOptionsArgs{
LinearBuckets: &logging.MetricBucketOptionsLinearBucketsArgs{
NumFiniteBuckets: pulumi.Int(3),
Width: pulumi.Float64(1),
Offset: pulumi.Float64(1),
},
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.logging.Metric;
import com.pulumi.gcp.logging.MetricArgs;
import com.pulumi.gcp.logging.inputs.MetricMetricDescriptorArgs;
import com.pulumi.gcp.logging.inputs.MetricBucketOptionsArgs;
import com.pulumi.gcp.logging.inputs.MetricBucketOptionsLinearBucketsArgs;
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 loggingMetric = new Metric("loggingMetric", MetricArgs.builder()
.name("my-(custom)/metric")
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("DISTRIBUTION")
.unit("1")
.labels(
MetricMetricDescriptorLabelArgs.builder()
.key("mass")
.valueType("STRING")
.description("amount of matter")
.build(),
MetricMetricDescriptorLabelArgs.builder()
.key("sku")
.valueType("INT64")
.description("Identifying number for item")
.build())
.displayName("My metric")
.build())
.valueExtractor("EXTRACT(jsonPayload.request)")
.labelExtractors(Map.ofEntries(
Map.entry("mass", "EXTRACT(jsonPayload.request)"),
Map.entry("sku", "EXTRACT(jsonPayload.id)")
))
.bucketOptions(MetricBucketOptionsArgs.builder()
.linearBuckets(MetricBucketOptionsLinearBucketsArgs.builder()
.numFiniteBuckets(3)
.width(1)
.offset(1)
.build())
.build())
.build());
}
}
resources:
loggingMetric:
type: gcp:logging:Metric
name: logging_metric
properties:
name: my-(custom)/metric
filter: resource.type=gae_app AND severity>=ERROR
metricDescriptor:
metricKind: DELTA
valueType: DISTRIBUTION
unit: '1'
labels:
- key: mass
valueType: STRING
description: amount of matter
- key: sku
valueType: INT64
description: Identifying number for item
displayName: My metric
valueExtractor: EXTRACT(jsonPayload.request)
labelExtractors:
mass: EXTRACT(jsonPayload.request)
sku: EXTRACT(jsonPayload.id)
bucketOptions:
linearBuckets:
numFiniteBuckets: 3
width: 1
offset: 1
Logging Metric Counter Basic
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const loggingMetric = new gcp.logging.Metric("logging_metric", {
name: "my-(custom)/metric",
filter: "resource.type=gae_app AND severity>=ERROR",
metricDescriptor: {
metricKind: "DELTA",
valueType: "INT64",
},
});
import pulumi
import pulumi_gcp as gcp
logging_metric = gcp.logging.Metric("logging_metric",
name="my-(custom)/metric",
filter="resource.type=gae_app AND severity>=ERROR",
metric_descriptor={
"metric_kind": "DELTA",
"value_type": "INT64",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var loggingMetric = new Gcp.Logging.Metric("logging_metric", new()
{
Name = "my-(custom)/metric",
Filter = "resource.type=gae_app AND severity>=ERROR",
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
MetricKind = "DELTA",
ValueType = "INT64",
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/logging"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := logging.NewMetric(ctx, "logging_metric", &logging.MetricArgs{
Name: pulumi.String("my-(custom)/metric"),
Filter: pulumi.String("resource.type=gae_app AND severity>=ERROR"),
MetricDescriptor: &logging.MetricMetricDescriptorArgs{
MetricKind: pulumi.String("DELTA"),
ValueType: pulumi.String("INT64"),
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.logging.Metric;
import com.pulumi.gcp.logging.MetricArgs;
import com.pulumi.gcp.logging.inputs.MetricMetricDescriptorArgs;
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 loggingMetric = new Metric("loggingMetric", MetricArgs.builder()
.name("my-(custom)/metric")
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("INT64")
.build())
.build());
}
}
resources:
loggingMetric:
type: gcp:logging:Metric
name: logging_metric
properties:
name: my-(custom)/metric
filter: resource.type=gae_app AND severity>=ERROR
metricDescriptor:
metricKind: DELTA
valueType: INT64
Logging Metric Counter Labels
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const loggingMetric = new gcp.logging.Metric("logging_metric", {
name: "my-(custom)/metric",
filter: "resource.type=gae_app AND severity>=ERROR",
metricDescriptor: {
metricKind: "DELTA",
valueType: "INT64",
labels: [{
key: "mass",
valueType: "STRING",
description: "amount of matter",
}],
},
labelExtractors: {
mass: "EXTRACT(jsonPayload.request)",
},
});
import pulumi
import pulumi_gcp as gcp
logging_metric = gcp.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)",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var loggingMetric = new Gcp.Logging.Metric("logging_metric", new()
{
Name = "my-(custom)/metric",
Filter = "resource.type=gae_app AND severity>=ERROR",
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
MetricKind = "DELTA",
ValueType = "INT64",
Labels = new[]
{
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Key = "mass",
ValueType = "STRING",
Description = "amount of matter",
},
},
},
LabelExtractors =
{
{ "mass", "EXTRACT(jsonPayload.request)" },
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/logging"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := logging.NewMetric(ctx, "logging_metric", &logging.MetricArgs{
Name: pulumi.String("my-(custom)/metric"),
Filter: pulumi.String("resource.type=gae_app AND severity>=ERROR"),
MetricDescriptor: &logging.MetricMetricDescriptorArgs{
MetricKind: pulumi.String("DELTA"),
ValueType: pulumi.String("INT64"),
Labels: logging.MetricMetricDescriptorLabelArray{
&logging.MetricMetricDescriptorLabelArgs{
Key: pulumi.String("mass"),
ValueType: pulumi.String("STRING"),
Description: pulumi.String("amount of matter"),
},
},
},
LabelExtractors: pulumi.StringMap{
"mass": pulumi.String("EXTRACT(jsonPayload.request)"),
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.logging.Metric;
import com.pulumi.gcp.logging.MetricArgs;
import com.pulumi.gcp.logging.inputs.MetricMetricDescriptorArgs;
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 loggingMetric = new Metric("loggingMetric", MetricArgs.builder()
.name("my-(custom)/metric")
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("INT64")
.labels(MetricMetricDescriptorLabelArgs.builder()
.key("mass")
.valueType("STRING")
.description("amount of matter")
.build())
.build())
.labelExtractors(Map.of("mass", "EXTRACT(jsonPayload.request)"))
.build());
}
}
resources:
loggingMetric:
type: gcp:logging:Metric
name: logging_metric
properties:
name: my-(custom)/metric
filter: resource.type=gae_app AND severity>=ERROR
metricDescriptor:
metricKind: DELTA
valueType: INT64
labels:
- key: mass
valueType: STRING
description: amount of matter
labelExtractors:
mass: EXTRACT(jsonPayload.request)
Logging Metric Logging Bucket
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const loggingMetric = new gcp.logging.ProjectBucketConfig("logging_metric", {
location: "global",
project: "my-project-name",
bucketId: "_Default",
});
const loggingMetricMetric = new gcp.logging.Metric("logging_metric", {
name: "my-(custom)/metric",
filter: "resource.type=gae_app AND severity>=ERROR",
bucketName: loggingMetric.id,
});
import pulumi
import pulumi_gcp as gcp
logging_metric = gcp.logging.ProjectBucketConfig("logging_metric",
location="global",
project="my-project-name",
bucket_id="_Default")
logging_metric_metric = gcp.logging.Metric("logging_metric",
name="my-(custom)/metric",
filter="resource.type=gae_app AND severity>=ERROR",
bucket_name=logging_metric.id)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var loggingMetric = new Gcp.Logging.ProjectBucketConfig("logging_metric", new()
{
Location = "global",
Project = "my-project-name",
BucketId = "_Default",
});
var loggingMetricMetric = new Gcp.Logging.Metric("logging_metric", new()
{
Name = "my-(custom)/metric",
Filter = "resource.type=gae_app AND severity>=ERROR",
BucketName = loggingMetric.Id,
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/logging"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
loggingMetric, err := logging.NewProjectBucketConfig(ctx, "logging_metric", &logging.ProjectBucketConfigArgs{
Location: pulumi.String("global"),
Project: pulumi.String("my-project-name"),
BucketId: pulumi.String("_Default"),
})
if err != nil {
return err
}
_, err = logging.NewMetric(ctx, "logging_metric", &logging.MetricArgs{
Name: pulumi.String("my-(custom)/metric"),
Filter: pulumi.String("resource.type=gae_app AND severity>=ERROR"),
BucketName: loggingMetric.ID(),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.logging.ProjectBucketConfig;
import com.pulumi.gcp.logging.ProjectBucketConfigArgs;
import com.pulumi.gcp.logging.Metric;
import com.pulumi.gcp.logging.MetricArgs;
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 loggingMetric = new ProjectBucketConfig("loggingMetric", ProjectBucketConfigArgs.builder()
.location("global")
.project("my-project-name")
.bucketId("_Default")
.build());
var loggingMetricMetric = new Metric("loggingMetricMetric", MetricArgs.builder()
.name("my-(custom)/metric")
.filter("resource.type=gae_app AND severity>=ERROR")
.bucketName(loggingMetric.id())
.build());
}
}
resources:
loggingMetric:
type: gcp:logging:ProjectBucketConfig
name: logging_metric
properties:
location: global
project: my-project-name
bucketId: _Default
loggingMetricMetric:
type: gcp:logging:Metric
name: logging_metric
properties:
name: my-(custom)/metric
filter: resource.type=gae_app AND severity>=ERROR
bucketName: ${loggingMetric.id}
Logging Metric Disabled
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const loggingMetric = new gcp.logging.Metric("logging_metric", {
name: "my-(custom)/metric",
filter: "resource.type=gae_app AND severity>=ERROR",
metricDescriptor: {
metricKind: "DELTA",
valueType: "INT64",
},
disabled: true,
});
import pulumi
import pulumi_gcp as gcp
logging_metric = gcp.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)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var loggingMetric = new Gcp.Logging.Metric("logging_metric", new()
{
Name = "my-(custom)/metric",
Filter = "resource.type=gae_app AND severity>=ERROR",
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
MetricKind = "DELTA",
ValueType = "INT64",
},
Disabled = true,
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/logging"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := logging.NewMetric(ctx, "logging_metric", &logging.MetricArgs{
Name: pulumi.String("my-(custom)/metric"),
Filter: pulumi.String("resource.type=gae_app AND severity>=ERROR"),
MetricDescriptor: &logging.MetricMetricDescriptorArgs{
MetricKind: pulumi.String("DELTA"),
ValueType: pulumi.String("INT64"),
},
Disabled: pulumi.Bool(true),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.logging.Metric;
import com.pulumi.gcp.logging.MetricArgs;
import com.pulumi.gcp.logging.inputs.MetricMetricDescriptorArgs;
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 loggingMetric = new Metric("loggingMetric", MetricArgs.builder()
.name("my-(custom)/metric")
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("INT64")
.build())
.disabled(true)
.build());
}
}
resources:
loggingMetric:
type: gcp:logging:Metric
name: logging_metric
properties:
name: my-(custom)/metric
filter: resource.type=gae_app AND severity>=ERROR
metricDescriptor:
metricKind: DELTA
valueType: INT64
disabled: true
Import
Metric can be imported using any of these accepted formats:
{{project}} {{name}}
{{name}}
When using thepulumi import
command, Metric can be imported using one of the formats above. For example:
$ pulumi import gcp:logging/metric:Metric default {{project}} {{name}}
$ pulumi import gcp:logging/metric:Metric default {{name}}
Constructors
Properties
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.
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.
A description of this metric, which is used in documentation. The maximum length of the description is 8000 characters.
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.
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.
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.
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.