Table of Contents (🔎 Click to expand/collapse)
- Overview
- Challenge Scenario
- Your Challenge
- Task 1: Configure Cloud Monitoring
- Task 2: Configure a Compute Instance to generate Custom Cloud Monitoring metrics
- Task 3: Create a custom metric using Cloud Operations logging events
- Task 4: Add custom metrics to the Media Dashboard in Cloud Operations Monitoring
- Task 5: Create a Cloud Operations alert based on the rate of high resolution video file uploads
Quest Outline (🔎 Click to expand/collapse)
Level | Code | Name | Note |
---|---|---|---|
Introductory | GSP089 |
Cloud Monitoring: Qwik Start | EN |
Fundamental | GSP090 |
Monitoring Multiple Projects with Cloud Monitoring | EN |
Fundamental | GSP092 |
Monitoring and Logging for Cloud Functions | EN |
Fundamental | GSP111 |
Reporting Application Metrics into Cloud Monitoring | EN |
Advanced | GSP091 |
Creating and Alerting on Logs-based Metrics | EN |
Advanced | GSP087 |
Autoscaling an Instance Group with Custom Cloud Monitoring Metrics | EN |
Expert | GSP338 |
Monitor and Log with Google Cloud Operations Suite: Challenge Lab |
This lab is recommended for students enrolled in the Monitor and Log with Google Cloud Operations Suite Quest.
Topics tested:
- Initialize Cloud Monitoring.
- Configure a Compute Engine application for Cloud Operations Monitoring custom metrics.
- Create a custom metric using Cloud Operations logging events.
- Add custom metrics to a Cloud Monitoring Dashboard.
- Create a Cloud Operations alert.
In your new role as Junior Cloud Engineer for Jooli Inc., you're expected to help manage the Cloud infrastructure components and support the video operations team. Common tasks include monitoring resource utilization, analyzing logs, configuring alerts, and reporting on any issues related to Jooli Inc.'s online services.
As you're expected to have the skills and knowledge for these tasks, step-by-step guides are not provided.
Some Jooli Inc. standards you should follow:
- Create all resources in the
us-east1
region andus-east1-b
zone, unless otherwise directed. - Naming is
team-resource
, e.g. an instance could be namedvideo-webserver1
. - Allocate cost effective resource sizes. Projects are monitored and excessive resource use will result in the containing project's termination (and possibly yours), so beware. Unless directed, use
n1-standard-1
.
On the first day of your new job, your manager gives you a series of tasks that you must complete. Good luck!
Your primary concern is a media upload function that Jooli Inc. provides. This function allows subscribers to upload video content to edit and transform using Jooli Inc.'s innovative range of cloud based media production tools.
The media upload function is a critical part of the service, and it is vital that Jooli Inc. is aware of any changes in the behavior of the users that might impact performance or cost of the services.
Your tasks today will use Cloud Operations tools to improve the company's ability to identify such changes and respond to them rapidly. Your manager has told you that the company is concerned that recent changes in end user behavior, combined with a new generation of phones and tablets, is fuelling a demand for much higher media such as 4K, and even 8K, video. Storage for the data is a relatively minor concern but the company wants to make sure that resource consumption by the Cloud Functions used for media upload and transcoding do not run into any limits or result in unexpected spikes in billing costs.
Your first task is to enable Cloud Monitoring for your project.
A basic Cloud Monitoring dashboard, called Media_Dashboard, will be made available to you automatically, but you have to enable Cloud Monitoring in your project before you will be able to access this dashboard.
Once you initialize Cloud Monitoring, you can access the initial dashboard, called Media_Dashboard. In subsequent tasks you will add custom metrics to this basic dashboard. The initial dashboard configuration incldues some charts that display stats about the latency of the video upload Cloud Function.
- Navigate to Navigation menu > Monitoring.
- Wait for the workspace to be provisioned.
Your next task is to confirm that the monitoring service that checks the length of the video processing queue is working correctly.
The monitoring service creates a custom metric, opencensus/my.videoservice.org/measure/input_queue_size
, that allows you to monitor the state of the Jooli Inc.'s video processing queue. This custom metric is created and written to by a Go application that runs on a Compute Instance called video-queue-monitor
.
The video-queue-monitor
Compute Instance has been deployed for you and uses a startup script to install and launch the input queue monitoring Go application. This application was tested fully in a development environment but the configuration in your Compute Instance has not been finalized. The Go application will not write custom metric data until the application is correctly configured by the startup script.
You must modify the startup script for the video-queue-monitor
Compute Instance so that the queue monitoring application (the Go application) can create and write to custom metrics. Once you have updated the startup script you will need to restart the instance.
The Go application is installed in the /work/go
directory in the Compute Instance by the startup script.
You can confirm that the application is working by searching for the metric input_queue_size
in the Metrics Explorer in Cloud Monitoring.
- In the Cloud Console, click Navigation Menu > Compute Engine > VM Instances.
- Click the instance named
video-queue-monitor
. - Click EDIT
- Modify the value of of
startup-script
in Custom metadata.
...
# Configure env vars for the Video Queue processing application
export MY_PROJECT_ID=<PROJECT_ID>
export MY_GCE_INSTANCE_ID=<INSTANCE-ID>
export MY_GCE_INSTANCE_ZONE="us-east1-b"
...
- Click Save
- Go back to Stop and then Start the instance
video-queue-monitor
.
The startup script for the Compute Instance is in the Compute Instance metadata key called startup_script
. We can use gcloud compute instances add-metadata
command for updating metadata on a running instance.
# setup the environment variables
$ PROJECT_ID=$DEVSHELL_PROJECT_ID
$ INSTANCE_ID=$(gcloud compute instances describe "video-queue-monitor" --zone="us-east1-b" --format="value[](id)")
$ INSTANCE_ZONE="us-east1-b"
# retrieve the original start-script.sh and replace content with environment variables
$ gcloud compute instances describe "video-queue-monitor" \
--zone="us-east1-b" \
--format="value[](metadata.items.startup-script)" \
> "start-script.sh"
$ sed "s/\[REPLACE-WITH-PROJECT_ID\]/$PROJECT_ID/g" -i start-script.sh
$ sed "s/\[REPLACE-WITH-INSTANCE-ID\]/$INSTANCE_ID/g" -i start-script.sh
$ sed "s/\[REPLACE-WITH-INSTANCE-ZONE\]/$INSTANCE_ZONE/g" -i start-script.sh
# update the metadata
$ gcloud compute instances add-metadata "video-queue-monitor" \
--zone="us-east1-b" \
--metadata-from-file="startup_script"="start-script.sh"
Don't forget to restart the instance once we have updated the startup script.
# restart the instance
$ gcloud compute instances stop "video-queue-monitor" --zone="us-east1-b"
$ gcloud compute instances start "video-queue-monitor" --zone="us-east1-b"
gcloud compute instances add-metadata
| Cloud SDK Documentation- Stopping and starting a VM | Compute Engine Documentation
Examine the Cloud Operations logs and create a custom metric that tracks the total volume of uploaded media files to your Cloud Function. The video upload Cloud Function creates a Cloud Operations Logging event that includes metadata about the type of video file the video processing system handles. You have been asked to configure a custom log based metric called large_video_upload_rate
that will monitor the rate at which high resolution video files, those recorded at either 4K or 8K resolution, are uploaded. The Cloud Function is already processing this data, and if you search the Cloud Operations logs using the advanced filter mode you will find log entries that contain the string "file_format: 4K"
or "file_format: 8K"
in the textPayload
field whenever the video_processing
Cloud Function receives a request to process a high resolution video. You can use that filter to create your custom metric.
- In the Cloud Console, click Navigation menu > Logging > Logs Explorer.
- Use the query criteria
textPayload=~"file_format\: ([4,8]K).*"
and then click Run Query. - On top right of the Query Results section, click Actions drop down and select Create Metric.
- Create the custom metric with the name
large_video_upload_rate
.
- Creating and Alerting on Logs-based Metrics | Qwiklabs
- Creating custom metrics | Cloud Monitoring Document
You must now add two charts to the Media Dashboard:
- Add a chart for the video input queue length custom metric that is generated by the Go application running on the
video-queue-monitor
Compute Instance. - Add a chart for the high resolution video upload rate custom log based metric to the
Media_Dashboard
custom dashboard.
- In the Cloud Console, click Navigation menu > Monitoring > Dashboards.
- Click the custom dashboard named
Media_Dashboard
. - Click VIEWING on top right and then click Switch to Editing mode in the dropdown list.
- Click ADD CHART and then click Line.
- Add charts with the given resources and metrics.
- The metric
input_queue_size
associated with thegce_instance
resource type. - The metric
large_video_upload_rate
.
- The metric
- In the Cloud Console, click Navigation menu > Monitoring > Metrics Explorer.
- Find the given resource type and metric.
- The metric
input_queue_size
associated with thegce_instance
resource type. - The metric
large_video_upload_rate
.
- The metric
- Click Save Chart.
- Keep the Chart Title field with default value and set the Dashboard as
Media_Dashboard
. - Click SAVE
- Cloud Monitoring: Qwik Start | Qwiklabs
- Creating and managing dashboard widgets | Cloud Monitoring Documentation
Create a custom alert using the high resolution video upload metric that triggers when the upload rate for large videos exceeds a count of 3 per minute.
- In the Cloud Console, click Navigation menu > Monitoring > Alerting.
- Click CREATE POLICY.
- Click ADD CONDITION
- Find resource type
gae_instance
and metriclarge_video_upload_rate
. - Setup the configuration with Condition
is above
for3
minute.
- Find resource type
- Click ADD > NEXT > NEXT
- Fill up the Alert Name (e.g.
High resolution video uploads
). - CLick Save
$ gcloud alpha monitoring policies create \
--display-name="High resolution video uploads" \
--condition-display-name="/logging/user/large_video_upload_rate [RATE]"\
--condition-filter='metric.type="appengine.googleapis.com/flex/instance/cpu/utilization" resource.type="gae_instance"' \
--duration="3m" \
--if="> 5.0" \
--combiner="AND"