Skip to content

googleLoggingMetric

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:

Example Usage - Logging Metric Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.loggingMetric.LoggingMetric(this, "logging_metric", {
  bucket_options: [
    {
      linear_buckets: [
        {
          num_finite_buckets: 3,
          offset: 1,
          width: 1,
        },
      ],
    },
  ],
  filter: "resource.type=gae_app AND severity>=ERROR",
  label_extractors: [
    {
      mass: "EXTRACT(jsonPayload.request)",
      sku: "EXTRACT(jsonPayload.id)",
    },
  ],
  metric_descriptor: [
    {
      display_name: "My metric",
      labels: [
        {
          description: "amount of matter",
          key: "mass",
          value_type: "STRING",
        },
        {
          description: "Identifying number for item",
          key: "sku",
          value_type: "INT64",
        },
      ],
      metric_kind: "DELTA",
      unit: "1",
      value_type: "DISTRIBUTION",
    },
  ],
  name: "my-(custom)/metric",
  value_extractor: "EXTRACT(jsonPayload.request)",
});

Example Usage - Logging Metric Counter Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.loggingMetric.LoggingMetric(this, "logging_metric", {
  filter: "resource.type=gae_app AND severity>=ERROR",
  metric_descriptor: [
    {
      metric_kind: "DELTA",
      value_type: "INT64",
    },
  ],
  name: "my-(custom)/metric",
});

Example Usage - Logging Metric Counter Labels

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.loggingMetric.LoggingMetric(this, "logging_metric", {
  filter: "resource.type=gae_app AND severity>=ERROR",
  label_extractors: [
    {
      mass: "EXTRACT(jsonPayload.request)",
    },
  ],
  metric_descriptor: [
    {
      labels: [
        {
          description: "amount of matter",
          key: "mass",
          value_type: "STRING",
        },
      ],
      metric_kind: "DELTA",
      value_type: "INT64",
    },
  ],
  name: "my-(custom)/metric",
});

Example Usage - Logging Metric Logging Bucket

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleLoggingProjectBucketConfigLoggingMetric =
  new google.loggingProjectBucketConfig.LoggingProjectBucketConfig(
    this,
    "logging_metric",
    {
      bucket_id: "_Default",
      location: "global",
      project: "my-project-name",
    }
  );
const googleLoggingMetricLoggingMetric = new google.loggingMetric.LoggingMetric(
  this,
  "logging_metric_1",
  {
    bucket_name: googleLoggingProjectBucketConfigLoggingMetric.id,
    filter: "resource.type=gae_app AND severity>=ERROR",
    name: "my-(custom)/metric",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleLoggingMetricLoggingMetric.overrideLogicalId("logging_metric");

Argument Reference

The following arguments are supported:

  • name - (Required) 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.

  • filter - (Required) An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which is used to match log entries.


  • description - (Optional) A description of this metric, which is used in documentation. The maximum length of the description is 8000 characters.

  • bucketName - (Optional) 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.

  • metricDescriptor - (Optional) 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.

  • labelExtractors - (Optional) 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.

  • valueExtractor - (Optional) 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.

  • bucketOptions - (Optional) 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.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The metricDescriptor block supports:

  • unit - (Optional) The unit in which the metric value is reported. It is only applicable if the valueType is int64, double, or distribution. The supported units are a subset of The Unified Code for Units of Measure standard

  • valueType - (Required) Whether the measurement is an integer, a floating-point number, etc. Some combinations of metricKind and valueType might not be supported. For counter metrics, set this to INT64. Possible values are bool, int64, double, string, distribution, and money.

  • metricKind - (Required) Whether the metric records instantaneous values, changes to a value, etc. Some combinations of metricKind and valueType might not be supported. For counter metrics, set this to DELTA. Possible values are delta, gauge, and cumulative.

  • labels - (Optional) The set of labels that can be used to describe a specific instance of this metric type. For example, the appengine.googleapis.com/http/server/response_latencies metric type has a label for the HTTP response code, response_code, so you can look at latencies for successful responses or just for responses that failed. Structure is documented below.

  • displayName - (Optional) A concise name for the metric, which can be displayed in user interfaces. Use sentence case without an ending period, for example "Request count". This field is optional but it is recommended to be set for any metrics associated with user-visible concepts, such as Quota.

The labels block supports:

  • key - (Required) The label key.

  • description - (Optional) A human-readable description for the label.

  • valueType - (Optional) The type of data that can be assigned to the label. Default value is string. Possible values are bool, int64, and string.

The bucketOptions block supports:

  • linearBuckets - (Optional) Specifies a linear sequence of buckets that all have the same width (except overflow and underflow). Each bucket represents a constant absolute uncertainty on the specific value in the bucket. Structure is documented below.

  • exponentialBuckets - (Optional) Specifies an exponential sequence of buckets that have a width that is proportional to the value of the lower bound. Each bucket represents a constant relative uncertainty on a specific value in the bucket. Structure is documented below.

  • explicitBuckets - (Optional) Specifies a set of buckets with arbitrary widths. Structure is documented below.

The linearBuckets block supports:

  • numFiniteBuckets - (Optional) Must be greater than 0.

  • width - (Optional) Must be greater than 0.

  • offset - (Optional) Lower bound of the first bucket.

The exponentialBuckets block supports:

  • numFiniteBuckets - (Optional) Must be greater than 0.

  • growthFactor - (Optional) Must be greater than 1.

  • scale - (Optional) Must be greater than 0.

The explicitBuckets block supports:

  • bounds - (Required) The values must be monotonically increasing.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format {{name}}

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Metric can be imported using any of these accepted formats:

$ terraform import google_logging_metric.default {{project}} {{name}}
$ terraform import google_logging_metric.default {{name}}

User Project Overrides

This resource supports User Project Overrides.