正在加载…
未找到任何结果。

在 Google Cloud 控制台中运用您的技能

Deploy and Monitor in Google Cloud for AWS Professionals

访问 700 多个实验和课程

Monitoring a Compute Engine using Ops Agent (AWS)

实验 1 小时 universal_currency_alt 5 积分 show_chart 入门级
info 此实验可能会提供 AI 工具来支持您学习。
访问 700 多个实验和课程

As a cloud administrator, you are in charge of monitoring your infrastructure. As you start your operations in Google Cloud, you should be able to collect data from your resources—such as logs and metrics—establish alerts, and visualize the data on a dashboard.

Some of your concerns are:

  • How can you set up a monitor over your deployed resource?
  • How can you configure the metrics to read over the network traffic?
  • How can you create an alert policy for your metrics?
  • How can you visualize your metrics on a dashboard?

The CloudWatch workflow is described in the following diagram.

In Amazon Web Services (AWS), you install the Amazon CloudWatch Agent on the Amazon Elastic Compute Cloud (EC2) instances to collect metrics and logs from your applications and infrastructure. You configure logs and log groups to collect log data from your resources by using Amazon CloudWatch. You can even configure one or more custom metrics to monitor any specific aspects of your infrastructure.

Finally, you create one or more alarms to monitor and notify the administrators in response to events.

Now you will explore how you can monitor your infrastructure in Google Cloud.

Overview

In this lab you will create a compute engine to install and configure an Ops Agent. You will generate traffic and view metrics on the predefined Apache dashboard and also create an alerting policy.

Objectives

In this lab, you learn how to perform the following tasks:

  • Create a Compute Engine VM instance.
  • Install an Apache Web Server.
  • Install and configure the Ops Agent for the Apache Web Server.
  • Generate traffic and view metrics on the predefined Apache dashboard.
  • Create an alerting policy.

Task 1. Create a Compute Engine VM instance

In this task, you create a Compute Engine VM instance, and then configure its machine type, boot disk, and firewall rules to allow HTTP and HTTPS traffic.

  1. In the Google Cloud console, on the Navigation menu (), click Compute Engine > VM instances.

  2. To create a VM instance, click Create instance.

Fill in the fields for your instance as follows:

  1. Click Machine configuration, and then specify the following values:

    Field Value
    Name quickstart-vm
    Region
    Zone
    Series E2
    Machine Type e2-small
  2. Click OS and storage:

    • Boot disk image: Debian GNU/Linux 12 (bookworm)
  3. Click Networking:

    • In the Firewall field, select both Allow HTTP traffic and Allow HTTPS traffic.

Leave the rest of the fields at their default values.

  1. Click Create. When your VM is ready, it appears in the list of instances in the Instances tab.

Click Check my progress to verify the objective.

Create a Compute Engine VM instance

Task 2. Install an Apache Web Server

In this task, you deploy an Apache Web Server on your Compute Engine VM instance.

  1. To open a terminal to your instance, in the Connect column, click SSH. If prompted, click Authorize.

  2. To update the package lists on your instance, run the following command:

sudo apt-get update
  1. To install an Apache2 HTTP Server, run the following command:
sudo apt-get install apache2 php7.0 Note: If the previous command fails, then use sudo apt-get install apache2 php. If asked to continue the installation, enter Y.
  1. Open your browser and connect to your Apache2 HTTP server by using the URL http://EXTERNAL_IP, where EXTERNAL_IP is the external IP address of your VM. You can find this address in the External IP column of your VM instance.
Note: If prompted, click Continue to site.

Click Check my progress to verify the objective.

Install an Apache Web Server

Task 3. Install and configure the Ops Agent

In this task, you install the Ops Agent on your VM instance and configure it to collect logs and metrics from the Apache Web Server.

To collect logs and metrics from your Apache Web Server, install the Ops Agent by using the terminal:

  1. To open a terminal to your VM instance, in the Connect column, click SSH. If prompted, click Authorize.

  2. To install the Ops Agent, run the following command:

curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh sudo bash add-google-cloud-ops-agent-repo.sh --also-install

You see google-cloud-ops-agent installation succeeded.

  1. Copy the following command, then paste it into the terminal:
# Configures Ops Agent to collect telemetry from the app and restart Ops Agent. set -e # Create a back up of the existing file so existing configurations are not lost. sudo cp /etc/google-cloud-ops-agent/config.yaml /etc/google-cloud-ops-agent/config.yaml.bak # Configure the Ops Agent. sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF metrics: receivers: apache: type: apache service: pipelines: apache: receivers: - apache logging: receivers: apache_access: type: apache_access apache_error: type: apache_error service: pipelines: apache: receivers: - apache_access - apache_error EOF sudo service google-cloud-ops-agent restart sleep 60

The previous command creates the configuration to collect and ingest logs and metrics from the Apache Web Server. For more information about ingesting logs from the Apache Web Server, see Configure the Ops Agent for Apache Web Server.

Click Check my progress to verify the objective.

Install the Ops Agent

Task 4. Generate traffic and view metrics

In this task, you generate metrics on your Apache Web Server and view metric data on the automatically created Apache Overview dashboard.

To generate metrics on your Apache Web Server, do the following:

  1. In the Google Cloud console, on the Navigation menu (), click Compute Engine > VM instances.

  2. In the Connect column, click SSH to open a terminal to your VM instance. If prompted, click Authorize.

  3. To generate traffic on your Apache Web Server, run the following command:

timeout 120 bash -c -- 'while true; do curl localhost; sleep $((RANDOM % 4)) ; done'

The previous command generates traffic by making a request to the Apache Web Server every four seconds.

To view the Apache Overview dashboard, do the following:

  1. In the Google Cloud console, on the Navigation menu (), click View all products > Observability > Monitoring.

  2. In the navigation pane, select Dashboards.

  3. In All Dashboards, select the Apache Overview dashboard. The dashboard opens.

In the dashboard, there are several charts that contain information about your Apache and Compute Engine integration:

Task 5. Create an alerting policy

In this task, you setup an email notification channel and then configure an alerting policy that monitors the traffic rate on your Apache Web Server, sending an email notification when the rate exceeds 4 KiB/s.

Setup email notification channel

  1. In the Google Cloud console, in the Navigation menu () click View all products > Observability > Monitoring.

  2. Click Alerting and then click Edit notification channels.

  3. In the Email section, click Add new and enter your desired email address.

  4. In Display Name, copy and paste your email address again.

  5. Click Save.

Configure Alerting policy

  1. In the Google Cloud console, in Observability, click Alerting and then click Create policy.

  2. Select the time series to be monitored:

    • Click Select a metric and enter VM instance into the filter bar.
    • In the Active metric categories list, select Apache.
    • In the Active metrics list, select workload/apache.traffic.
    • Click Apply.

The chart for Apache traffic is shown.

  1. In the Transform data section, select the following values and click Next:

    • Rolling window: 1 min
    • Rolling window function: rate
  2. In the Configure alert trigger section, select the following values and click Next:

    • Alert trigger: Any time series violates
    • Threshold position: Above threshold
    • Threshold value: 4000
  3. In the Configure notifications and finalize alert section, select the following values:

    • Notification channels: An email address you have access to
    • Incident autoclose duration: 30 min
    • Name the alert policy: Apache traffic above threshold
  4. Click Create policy. Your alerting policy is now active.

Click Check my progress to verify the objective.

Create an alerting policy

Task 6. Test the alerting policy

In this task, you test the alerting policy by generating traffic on your Apache Web Server. You the verify that an email notification is sent when the traffic rate exceeds the configured threshold.

  1. In the Google Cloud console, on the Navigation menu (), click Compute Engine > VM instances.

  2. In the Connect column, click SSH to open a terminal to your VM instance. If prompted, click Authorize.

  3. In the terminal, enter the following command:

timeout 120 bash -c -- 'while true; do curl localhost; sleep $((RANDOM % 4)) ; done'

The previous command generates traffic in your Apache Web Server.

After the traffic rate threshold value of 4 KiB/s is exceeded on your Apache Web Server, an email notification is sent. It might take several minutes for this process to complete.

The email notification you receive looks similar to the following:

Congratulations!

In this lab, you learned how to install Ops Agent on a VM and use it to set an alerting policy to notify a recipient of potential issues with the instance.

Google Ops Agent and Amazon CloudWatch Agent are both monitoring agents that allow you to collect metrics and logs from your application and infrastructure in the cloud. This information, in turn, enables users to monitor the health and performance of applications and infrastructure in the cloud. Here are some similarities and differences between the two services:

Similarities:

  • Both Ops Agent and Cloudwatch Agent allow users to collect logs and metrics from a virtual machine instance.
  • Both OpsAgent and Cloudwatch Agent can be installed through a remote connection to the virtual machine (VM) or through the corresponding command-line interface (CLI).
  • After you have installed the agent on your VM, the host metrics, process metrics, and logs will automatically be routed to the monitoring service (Cloud Logging and Cloud Monitoring in Google Cloud and Amazon CloudWatch in AWS) without user intervention.
  • Once the data is collected in Cloud Logging and Cloud Monitoring or CloudWatch, you can visualize it in a centralized dashboard by using the corresponding console (Cloud Console for Google Cloud and Amazon Management Console for AWS).

Differences:

  • Just like in AWS, you also create a configuration file for Ops Agent to log metrics. In AWS, this configuration file is in JSON format, whereas in Google Cloud, a default YAML-based unified configuration is used.
  • In Google Cloud, you create an alerting policy to get notified in response to an event, while in AWS, you use alarms. In AWS, the alarms require the integration of a notification service—such as Simple Notification Service, Simple Queue Service, or Simple Email Service—into CloudWatch to get notified in response to an event. Whereas, in Google Cloud, the notification service is integrated within the alerting policy.
  • After the OpsAgent or CloudWatch Agent is installed, logs and metrics are automatically routed to the monitoring service. Google Cloud has two dedicated monitoring services: Cloud Logging for logs and Cloud Monitoring for metrics. Whereas in AWS, the functionality of both services is combined in Amazon CloudWatch.

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

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.

上一步 下一步

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

请使用无痕模式或无痕式浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。
预览