Monitoring VMs with Stackdriver

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

01:00:00

Difficulty

Beginner

Keeping track of all network and application-related activity, identifying bottlenecks, and tracing errors is a major undertaking. Stackdriver, Google Cloud's cross-platform monitoring and logging service, is designed to integrate all this functionality into a single, accessible interface. In this hands-on lab, you’ll walk through the steps necessary to monitor a Compute Engine VM instance for CPU usage and network traffic, including methods for visualizing the information.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Monitoring VMs with Stackdriver

In this hands-on lab, we’ll work through the steps necessary to monitor a Compute Engine VM instance for CPU usage and network traffic, including methods for visualizing the information.

How to Log in to Google Lab Accounts

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

Monitoring VMs with Stackdriver

Now, on to the lab!

Create VM instance.

  1. Navigate to Compute Engine > VMs.
  2. Click Create.
  3. Name the instance (e.g., "la-sd-1").
  4. In the Firewall section, select the Allow HTTP traffic option.
  5. Leave all the other values at their defaults, and click Create.

Install software.

  1. From the Compute Engine VMs page, click the SSH button associated with the newly created instance.

  2. In the SSH window, update the packages:

    sudo apt-get update
  3. Install Apache2 and PHP 7:

    sudo apt-get install apache2 php7.0

    When asked if you want to continue, enter Y.

  4. Restart the service:

    sudo service apache2 restart
  5. Back on the VM instances page, click the external IP link for the instance to confirm the web server is working.

Establish a Stackdriver workspace.

  1. From the main navigation, choose Monitoring in the Stackdriver section.

  2. From the dialog, click Create workspace.

  3. On the Add Google Cloud Platform projects to monitor page, confirm your current project is listed, and click Continue.

  4. On the Monitor AWS accounts page, click Skip AWS Setup.

  5. When you get to the Install the Stackdriver Agents page, switch to the SSH terminal and enter the following commands to set up the monitoring agent:

    curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
    sudo bash install-monitoring-agent.sh
  6. Enter the following commands to set up the logging agent:

    curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
    sudo bash install-logging-agent.sh
  7. Click Continue

  8. On the Get Reports by Email page, choose the No reports option and click Continue.

  9. After the initial collection is complete, click Launch monitoring.

Define an uptime check.

  1. From the Stackdriver Monitoring navigation, head to Uptime Checks > Uptime Checks Overview.
  2. Click Create an Uptime Check.
  3. In the New Uptime Check dialog, set the following values:
    • Title: LA Uptime Check
    • Check type: HTTP
    • Resource type: Instance
  4. Leave the remaining values at their defaults, and click Test.
  5. Once you see a green check mark, click Save.
  6. When asked to create an alerting policy, click No thanks.

Set up an alerting policy.

  1. From the Stackdriver navigation, choose Alerting > Create a Policy.
  2. Under Conditions, click Add Condition.
  3. In the Target section, in the Find resource type and metric field, type GCE and choose GCE VM Instance from Resource types.
  4. Then, for a Metric, type network and choose Network traffic.
  5. Under Configuration, set the following values:
    • Condition: is above
    • Threshold: 500
    • For: 1 minute
  6. Under Notifications, select Email, enter your email address, and click Add Notification Channel.
  7. Under Documentation, click Add documentation, and then add a note.
  8. Under Name this policy, enter Ingress Traffic Alert.
  9. Click Save.

Create a custom dashboard.

  1. From Stackdriver navigation, choose Dashboards > Create Dashboard.
  2. Click Add Chart.
  3. In the Find resource type and metric field, type CPU and choose CPU load (1m).
  4. Click Save.
  5. Click Add Chart.
  6. In the Find resource type and metric field, type network, and choose Received packets.
  7. Click Save.
  8. Name the dashboard LA VM Instance.

Conclusion

Congratulations on completing this lab!