Quickstart for Google Compute Engine

This page shows you how to monitor a Google Compute Engine virtual machine (VM) instance with Stackdriver. If instead you want to monitor an Amazon EC2 VM instance, then see Quickstart for Amazon EC2.

In this Quickstart, you do the following:

  1. Create a Compute Engine VM instance.
  2. Install Apache HTTP Server.
  3. Create a Stackdriver account.
  4. Install the Stackdriver Monitoring and Logging agents.
  5. Create an uptime check with an alerting policy.
  6. Create a custom dashboard and chart.
  7. View your logs.
  8. Clean up.

Before you begin

To use Stackdriver, you need to create a project and enable billing for your project.

To create a project:

  1. In the Cloud Platform Console dashboard, go to New Project:

Create a New Project

  1. Fill in Project name with stackdriver-lamp-quickstart.

  2. Click Create.

To enable billing for your project:

  1. In the Cloud Platform Console dashboard, go to Billing:

Go to Billing

  1. Select your stackdriver-lamp-quickstart project if it is not already selected at the top of the page.

  2. You are prompted either to choose an existing payments profile or to create a new one.

Create a Compute Engine instance

In the Cloud Platform Console dashboard, go to Compute > Compute Engine:

Go to Google Compute Engine

  1. Select your stackdriver-lamp-quickstart project if it is not already selected at the top of the page.

  2. Create a VM instance by clicking Create.

  3. Fill in the fields for your instance as follows:

    • Name: lamp-1-vm
    • Firewall: Select both Allow HTTP traffic and Allow HTTPS traffic
    • Machine type: Small

    Leave the rest of the fields with their default values.

  4. Click Create. You see the VM Instances page. Wait a couple of minutes for your instance to be launched. If you try browsing to the instance's external IP address, you get an error. You are about to fix that.

  5. In the Connect column, click SSH to open a terminal to your instance.

  6. Run the following commands on your instance to set up Apache2 HTTP Server:

    sudo apt-get update
    sudo apt-get install apache2 php7.0
    
  7. If you visit http://[external IP], you see the Apache2 default page:

    Apache2 default page

Create a Stackdriver account

To use Stackdriver, your project must be in a Stackdriver account. The following steps create a new account that has a free 30-day trial of Stackdriver Premium service:

  1. In the Google Cloud Platform Console, select Stackdriver > Monitoring:

    Go to Stackdriver Monitoring

    Because your project is not in a Stackdriver account, you see the following message:

    You do not have a Stackdriver account

  2. Select Create a new Stackdriver account and then click Continue. You see the following panel:

    Create a Stackdriver Account

  3. With your project, stackdriver-lamp-quickstart shown, click Create Account.

  4. In the page, "Add Google Cloud Platform projects to monitor", click Continue to skip ahead.

  5. In the page, "Monitor AWS accounts", click Continue to skip ahead.

  6. In the page "Install the Stackdriver Agents," click Continue to skip ahead.

  7. In the page, "Get Reports by Email", select No reports and then click Continue.

  8. You see the message "Gathering information..." at the top of the page. In a few seconds, you see the following message:

    Finished initial collection

    Click Launch monitoring.

  9. You see your Stackdriver account dashboard. A pop-up message will inform you that your account is in a free trial. Click Continue with the trial.

  10. Close the "Welcome to Stackdriver" banner if you don't need it.

Install the Stackdriver agents

The Stackdriver Monitoring and Logging agents pass logs and metrics from your VM instance to Stackdriver Logging and Stackdriver Monitoring:

  1. Switch to the terminal connected to your VM instance or create a new one.

  2. Install the Stackdriver Monitoring and Logging agents by running the following commands on your instance:

    curl -O https://repo.stackdriver.com/stack-install.sh
    sudo bash stack-install.sh --write-gcm
    
    curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
    sudo bash install-logging-agent.sh
    

Create an uptime check and an alerting policy

Uptime checks verify that your web server is always accessible. The alerting policy controls who is notified if the uptime checks should fail.

To create an uptime check and an alerting policy:

  1. Go back to the Stackdriver Monitoring Console.

  2. Click Create an Uptime Check on the dashboard. Otherwise, go to Uptime Checks in the left-hand menu, then select Uptime Checks Overview and then click Create an Uptime Check in the new page.

    You see the New Uptime Check panel:

    Create an uptime check

  3. Fill in the following fields for the new uptime check:

    • Title: Lamp Uptime Check
    • Check type: HTTP
    • Resource Type: Instance
    • Applies To: Single, lamp-1-vm
    • Leave the other fields with their default values.
  4. Click Test to verify your uptime check is working. If you see a Connection error - refused message, you might have not installed the Apache HTTP Server. For other errors, see Uptime checks.

  5. Click Save.

  6. You see the following panel--click Create Alerting Policy:

    Uptime Check Created

  7. You see the following dialog:

    Create new Alerting Policy

  8. Fill in the sections as follows:

    • The Conditions section is already set up. You don't have to change it.
    • In the Notifications section, click Add Notification and fill in your email address.
    • In the Documentation section, click Add Documentation and enter: Stackdriver LAMP quickstart example.
    • In the Name this policy section, you can accept the default Uptime Check Policy.
  9. Click Save Policy.

Create a dashboard and chart

Display the metrics collected by Stackdriver Monitoring in your own charts and dashboards:

  1. In the left-hand menu of Stackdriver Monitoring Console, select Dashboards > Create Dashboard.

    Go to the Create Dashboard page

  2. Click Add Chart. You see the Add Chart panel:

    Add chart

  3. In the Metric Type menu, select "Agent- CPU Load Average (past 5m)". Leave the other fields with their default values. You see the chart data in the Preview section of the panel.

  4. Click Save.

  5. Create a second chart. Select Add Chart in the upper-right menu of the new dashboard.

  6. In the Metric Type menu, select "Network Inbound Traffic (GCE Instance)". Leave the other fields with their default values. You see the chart data in the Preview section.

  7. Click Save.

  8. In the new dashboard, change Untitled Dashboard to Stackdriver LAMP quickstart dashboard.

Test the check and alert

This procedure can take up to fifteen minutes.

To test the check and alert, go to the VM Instances page, select your instance, and click Stop from the top menu. You might wait up to five minutes for the next uptime check to fail. The alert and notification will happen when the next failure occurs.

To correct the "problem," return to the VM Instances page, select your instance, and click Start from the top menu.

View your logs

Stackdriver Monitoring and Stackdriver Logging are closely integrated. To view your logs:

  1. In the Stackdriver Monitoring Console left-hand menu, click Logging:

    Go to Stackdriver Logging

  2. You see the Logs Viewer.

  3. Change the Logs Viewer focus to see the logs you want:
    • Select GCE VM Instance > lamp-1-vm in the first drop-down menu.
    • Select syslog in the second drop-down menu, and click OK.
    • Leave the other fields with their default values.
  4. You see the logs from your VM instance:

    View logs from console

  5. Return to the Stackdriver Monitoring Console. In one of your charts, open the settings menu and select View Logs:

    View logs from chart

  6. You are shown the logs that correspond to the time span and data in the chart.

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. Remove your Stackdriver alerting policies, uptime checks, and chart so that you won't get errors when you shut down your VM instance.

    • To delete your alerting policy:
      • In the Stackdriver Monitoring Console left-hand menu, select Alerting > Policies Overview.
      • In your Alerting Policies Overview page, click Delete next to the policy that you wish to remove.
    • To delete your uptime check:
      • In the Stackdriver Monitoring Console left-hand menu, select Uptime Checks > Lamp Uptime Check.
      • In the upper right-hand menu, select Delete Uptime Check.
    • To delete your charts:
      • In the Stackdriver Monitoring Console left-hand menu, select Dashboards > Stackdriver LAMP quickstart dashboard.
      • In the upper right-hand menu of each chart, select Delete.
      • When the dashboard is empty, select Delete in the settings menu on the dashboard.
      • In the "Confirm Chart Deletion" panel, click Delete.
  2. Stop your VM instance by visiting the Compute Engine VM Instances page:

    Go to Google Compute Engine VM instances

    • Select your instance.
    • Click Stop or Delete at the top of the page. You will not be charged for a stopped instance.
  3. To completely remove this Quickstart exercise, delete the project you created, stackdriver-lamp-quickstart:

    • In the console's home page, click Go to project settings in the "Project Info" card.
    • Click Shut Down.
    • In the "Shut down project..." panel, confirm that you want to delete your project by typing your project ID in the text box.
    • Click Shut Down.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Stackdriver Monitoring