gcloud logging metrics create Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud logging metrics create - create a logs-based metric
- SYNOPSIS
gcloud logging metrics createMETRIC_NAME(--config-from-file=PATH_TO_FILE| [--description=DESCRIPTION--log-filter=LOG_FILTER:--bucket-name=BUCKET_NAME])[GCLOUD_WIDE_FLAG …]
- DESCRIPTION
- Create a logs-based metric to count the number of log entries that match afilter expression. Logs-based metrics can also be used to extract values fromlogs and create a distribution of the values.
- EXAMPLES
- To create a metric that counts the number of log entries with a severity levelhigher than WARNING, run:
gcloudloggingmetricscreatehigh_severity_count--description="Number of high severity log entries"--log-filter="severity > WARNING"Detailed information about filters can be found at:https://cloud.google.com/logging/docs/view/logging-query-language
To create a metric that uses advanced features like distribution or user-definedlabels, run:
gcloudloggingmetricscreatemy_metric--config-from-file=$PATH_TO_FILEThe config file can be in YAML or JSON format. Detailed information about how toconfigure metrics can be found at:https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics#LogMetric.
To create a bucket log-based metric, run:
gcloudloggingmetricscreatemy_bucket_metric--description="DESCRIPTION"--log-filter="LOG_FILTER"--bucket-name="BUCKET_NAME" - POSITIONAL ARGUMENTS
METRIC_NAME- The name of the new metric.
- REQUIRED FLAGS
- Data about the new metric.
Exactly one of these must be specified:
--config-from-file=PATH_TO_FILE- A path to a YAML or JSON file specifying the logs-based metric to create. Use afull or relative path to a local file containing the value of config.
- A group of arguments to specify simple counter logs-based metrics.
--description=DESCRIPTION- The metric's description.
This flag argument must be specified if any of the other arguments in this groupare specified.
--log-filter=LOG_FILTER- The metric's filter expression.
This flag argument must be specified if any of the other arguments in this groupare specified.
--bucket-name=BUCKET_NAME- The Log Bucket name which owns the log-based metric.
- Data about the new metric.
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- These variants are also available:
gcloudalphaloggingmetricscreategcloudbetaloggingmetricscreate
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-07 UTC.