Log-based metric

A counter or chart created by counting log entries that match a rule, useful when the app does not emit the metric directly.

log based meticturn this error message into a counteralert when this log line happens too oftencount matching logs over timegraph how often a message appearsmake a dashboard from logscount 500 logs without changing codecount how many times that error appeared yesterday

See it

Live demo coming soon

What it is

A log-based metric turns matching log records into a time series. Each match can increment a counter, and selected fields can become labels for grouping. Google Cloud Logging calls these logs-based metrics and can feed them directly into Cloud Monitoring charts and alerts.

Reach for one when the application already emits a reliable event but does not expose a metric for it, especially when changing and deploying the application would slow down an urgent alert. It is useful for counting known error classes, rejected jobs, or rare business events.

Gotcha: the metric is only as stable as the log contract. A rewritten message or renamed field can silently stop the count, and extracting user IDs or request IDs as labels creates a cardinality explosion. Match structured fields, test the filter, and treat creation as the start of the series unless the backend explicitly supports backfill.

Ask AI for it

Create a Google Cloud Logging counter metric with Terraform's google_logging_metric resource. Count production records where jsonPayload.event equals checkout_failed, extract service and error_type as labels, and never extract user_id, request_id, or raw message text. Add a Cloud Monitoring rate chart and an alert policy that fires when the five-minute rate exceeds 0.5 events per second for ten minutes. Add fixture log entries that prove the filter accepts the intended event and rejects nearby messages.

You might have meant

metricstructured logginglog aggregationalert thresholdhigh cardinality