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
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.MetricBucketOptionsArgs;
import com.pulumi.gcp.logging.inputs.MetricBucketOptionsLinearBucketsArgs;
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()
.bucketOptions(MetricBucketOptionsArgs.builder()
.linearBuckets(MetricBucketOptionsLinearBucketsArgs.builder()
.numFiniteBuckets(3)
.offset(1)
.width(1)
.build())
.build())
.filter("resource.type=gae_app AND severity>=ERROR")
.labelExtractors(Map.ofEntries(
Map.entry("mass", "EXTRACT(jsonPayload.request)"),
Map.entry("sku", "EXTRACT(jsonPayload.id)")
))
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.displayName("My metric")
.labels(
MetricMetricDescriptorLabelArgs.builder()
.description("amount of matter")
.key("mass")
.valueType("STRING")
.build(),
MetricMetricDescriptorLabelArgs.builder()
.description("Identifying number for item")
.key("sku")
.valueType("INT64")
.build())
.metricKind("DELTA")
.unit("1")
.valueType("DISTRIBUTION")
.build())
.valueExtractor("EXTRACT(jsonPayload.request)")
.build());
}
}
Logging Metric Counter Basic
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()
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("INT64")
.build())
.build());
}
}
Logging Metric Counter Labels
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()
.filter("resource.type=gae_app AND severity>=ERROR")
.labelExtractors(Map.of("mass", "EXTRACT(jsonPayload.request)"))
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.labels(MetricMetricDescriptorLabelArgs.builder()
.description("amount of matter")
.key("mass")
.valueType("STRING")
.build())
.metricKind("DELTA")
.valueType("INT64")
.build())
.build());
}
}
Logging Metric Logging Bucket
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 loggingMetricProjectBucketConfig = new ProjectBucketConfig("loggingMetricProjectBucketConfig", ProjectBucketConfigArgs.builder()
.location("global")
.project("my-project-name")
.bucketId("_Default")
.build());
var loggingMetricMetric = new Metric("loggingMetricMetric", MetricArgs.builder()
.filter("resource.type=gae_app AND severity>=ERROR")
.bucketName(loggingMetricProjectBucketConfig.id())
.build());
}
}
Logging Metric Disabled
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()
.disabled(true)
.filter("resource.type=gae_app AND severity>=ERROR")
.metricDescriptor(MetricMetricDescriptorArgs.builder()
.metricKind("DELTA")
.valueType("INT64")
.build())
.build());
}
}
Import
Metric can be imported using any of these accepted formats
$ 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.