![](https://cdn.qwiklabs.com/assets/labs/start_lab-f45aca49782d4033c3ff688160387ac98c66941d.png)
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you restart it, you'll have to start from the beginning.
- On the top left of your screen, click Start lab to begin
Deploy the GKE cluster
/ 20
Create the Log-based alert
/ 20
Deploy the simple application that emits metrics
/ 10
Create the log-based metric
/ 20
Create the metrics-based alert
/ 20
Generate some errors
/ 10
Log-based metrics are Cloud Monitoring metrics that are based on the content of log entries. These metrics can help you identify trends, extract numeric values out of the logs, and set up an alert when a certain log entry occurs by creating a metric for that event. You can use both system and user-defined log-based metrics in Cloud Monitoring to create charts and alerting policies.google
The log-based metrics interface is divided into two metric-type panes: System metrics and User-defined metrics.
System-defined log-based metrics are provided by Cloud Logging for use by all Google Cloud projects.They calculated only from logs that have been ingested by Logging. If a log has been explicitly excluded from ingestion, it isn't included in these metrics.
User-defined log-based metrics are created by you to track things in your Google Cloud project. For example, you might create a log-based metric to count the number of log entries that match a given filter.
Creating an alert from a metric lets you create an alerting policy based on the log-based metric.
In this lab, you learn how to:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
In this task, you deploy a Google Kubernetes Engine (GKE) cluster to use in later tasks for log-based metrics.
If prompted, click Authorize Cloud Shell.
When the cluster has been deployed, the output displays STATUS: RUNNING for the cluster named gmp-cluster
.
Click Check my progress to verify the objective.
Log-based alerts notify you whenever a specific message appears in your logs. Try it out by setting up a log-based alert to tell you when a VM stops running.
From Cloud Console, in the Search bar, type Logs explorer, then click on the Logs Explorer result.
Enable the Show Query slide bar (if it is not already).
Copy and paste the following parameters into the query window to create Log Based Alert:
Under Actions (at the top of the Results section), click Create log alert.
Add the following parameters, and click Next after adding each value, so that you can see the next section:
5 min
and Incident autoclose duration as 1 hr
.Click Next.
For Who should be notified, complete the following:
Click Check my progress to verify the objective.
To test this log-based alert, you will now stop your VM.
Open a second Google Cloud console browser tab, and navigate to Navigation menu > Compute Engine > VM instances.
Check the box next to instance1, then click Stop at the top of the page. Click Stop again in the pop-up window.
This may take a moment. When the instance has been stopped, the green check mark will turn to a gray circle.
In the Search bar, type Monitoring, then choose the Monitoring (Infrastructure and application quality checks) option.
From the left side menu for Logging, click on Alerting under Detect.
You should see that your alert has registered.
Under Policies, click the See all policies to see the log-based alert you created named stopped vm.
Using log-based metrics you can define a metric that tracks errors in the logs to proactively respond to similar problems and symptoms before they are noticed by end users.
You should see the following message:
/metrics
endpoint:You should see the following:
Click Check my progress to verify the objective.
Re-run the command until you see the External-IP address populated.
Check that the Python Flask app is serving metrics with the following command:
You should see the following:
Return to Logs Explorer.
Under Actions, click Create metric link.
On the Create metric page, input the following:
Click Check my progress to verify the objective.
From the left side menu for Logging, click on Log-based Metrics under Configure.
In user-defined metrics, click on More actions (3 vertical dots) for hello-app-error, and select Create alert from metric.
Under Select a Metric, the metric parameters will automatically fill in.
Set notifications using the channel you created earlier in the lab.
Name the alert policy: log based metric alert
Click Create Policy.
Click Check my progress to verify the objective.
Next you'll generate some errors to match the log-based metric you created and trigger the metric-based alert.
Return to the Logs Explorer page, and go to the Severity section on the lower left side.
Click on the Error severity.
Now you can search for the 404 Error page not found
error. View more information by expanding one of the 404 Error messages.
Return to the Monitoring page, and click on Alerting.
You will see the 2 policies you created.
Under Alert policies, click on View all.
You should see both alerts in the Incidents section.
Click on an incident to see details.
Click Check my progress to verify the objective.
In this lab, you created a log-based alert, a system-defined log-based metric, a user-defined log-based metric, and a metric-based alert. You also generated some errors to trigger the alert. Lastly, you learned how to view the incidents and details of the alerts.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated November 12, 2024
Lab Last Tested November 12, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.