Class Metric
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:
- API documentation
- How-to Guides
- Official Documentation
Example Usage - Logging Metric Basic
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var loggingMetric = new Gcp.Logging.Metric("loggingMetric", new Gcp.Logging.MetricArgs
{
BucketOptions = new Gcp.Logging.Inputs.MetricBucketOptionsArgs
{
LinearBuckets = new Gcp.Logging.Inputs.MetricBucketOptionsLinearBucketsArgs
{
NumFiniteBuckets = 3,
Offset = 1,
Width = 1,
},
},
Filter = "resource.type=gae_app AND severity>=ERROR",
LabelExtractors =
{
{ "mass", "EXTRACT(jsonPayload.request)" },
{ "sku", "EXTRACT(jsonPayload.id)" },
},
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
DisplayName = "My metric",
Labels =
{
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Description = "amount of matter",
Key = "mass",
ValueType = "STRING",
},
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Description = "Identifying number for item",
Key = "sku",
ValueType = "INT64",
},
},
MetricKind = "DELTA",
Unit = "1",
ValueType = "DISTRIBUTION",
},
ValueExtractor = "EXTRACT(jsonPayload.request)",
});
}
}
Example Usage - Logging Metric Counter Basic
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var loggingMetric = new Gcp.Logging.Metric("loggingMetric", new Gcp.Logging.MetricArgs
{
Filter = "resource.type=gae_app AND severity>=ERROR",
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
MetricKind = "DELTA",
ValueType = "INT64",
},
});
}
}
Example Usage - Logging Metric Counter Labels
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var loggingMetric = new Gcp.Logging.Metric("loggingMetric", new Gcp.Logging.MetricArgs
{
Filter = "resource.type=gae_app AND severity>=ERROR",
LabelExtractors =
{
{ "mass", "EXTRACT(jsonPayload.request)" },
},
MetricDescriptor = new Gcp.Logging.Inputs.MetricMetricDescriptorArgs
{
Labels =
{
new Gcp.Logging.Inputs.MetricMetricDescriptorLabelArgs
{
Description = "amount of matter",
Key = "mass",
ValueType = "STRING",
},
},
MetricKind = "DELTA",
ValueType = "INT64",
},
});
}
}
Inherited Members
Namespace: Pulumi.Gcp.Logging
Assembly: Pulumi.Gcp.dll
Syntax
public class Metric : CustomResource
Constructors
View SourceMetric(String, MetricArgs, CustomResourceOptions)
Create a Metric resource with the given unique name, arguments, and options.
Declaration
public Metric(string name, MetricArgs args, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resource |
| MetricArgs | args | The arguments used to populate this resource's properties |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Properties
View SourceBucketOptions
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.
Declaration
public Output<MetricBucketOptions> BucketOptions { get; }
Property Value
| Type | Description |
|---|---|
| Output<MetricBucketOptions> |
Description
A description of this metric, which is used in documentation. The maximum length of the description is 8000 characters.
Declaration
public Output<string> Description { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Filter
An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which is used to match log entries.
Declaration
public Output<string> Filter { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
LabelExtractors
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.
Declaration
public Output<ImmutableDictionary<string, string>> LabelExtractors { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableDictionary<System.String, System.String>> |
MetricDescriptor
The metric descriptor associated with the logs-based metric. Structure is documented below.
Declaration
public Output<MetricMetricDescriptor> MetricDescriptor { get; }
Property Value
| Type | Description |
|---|---|
| Output<MetricMetricDescriptor> |
Name
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.
Declaration
public Output<string> Name { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Project
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Declaration
public Output<string> Project { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
ValueExtractor
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.
Declaration
public Output<string> ValueExtractor { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Methods
View SourceGet(String, Input<String>, MetricState, CustomResourceOptions)
Get an existing Metric resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
Declaration
public static Metric Get(string name, Input<string> id, MetricState state = null, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resulting resource. |
| Input<System.String> | id | The unique provider ID of the resource to lookup. |
| MetricState | state | Any extra arguments used during the lookup. |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Returns
| Type | Description |
|---|---|
| Metric |