0
0
GCPcloud~30 mins

Log-based metrics in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Log-based Metric in Google Cloud
📖 Scenario: You are managing a Google Cloud project that runs several applications. You want to monitor how many error logs are generated to quickly detect issues.
🎯 Goal: Create a log-based metric in Google Cloud that counts the number of error logs with severity ERROR.
📋 What You'll Learn
Create a log-based metric resource with the exact name error_count_metric.
Use the filter to select logs with severity=ERROR.
Set the metric type to counter to count occurrences.
Use the Google Cloud Logging API resource format.
💡 Why This Matters
🌍 Real World
Log-based metrics help monitor application health by counting specific log entries like errors or warnings.
💼 Career
Cloud engineers and DevOps professionals use log-based metrics to set up alerts and dashboards for system reliability.
Progress0 / 4 steps
1
Define the log-based metric resource
Create a dictionary called log_metric with keys name set to "error_count_metric" and filter set to "severity=\"ERROR\"".
GCP
Need a hint?

Use a Python dictionary with keys name and filter.

2
Add the metric descriptor type
Add a key metricDescriptor to log_metric with a nested dictionary containing metricKind set to "DELTA" and valueType set to "INT64".
GCP
Need a hint?

The metric kind DELTA counts changes, and value type INT64 means integer values.

3
Add a description for the metric
Add a key description to log_metric with the value "Counts the number of error logs".
GCP
Need a hint?

The description helps explain what the metric measures.

4
Complete the log-based metric configuration
Add a key labelExtractors to log_metric with an empty dictionary {} to complete the configuration.
GCP
Need a hint?

Label extractors are optional but required as an empty dictionary to complete the metric resource.