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 an Apache web server.
  3. Create a Stackdriver account.
  4. Install the Stackdriver monitoring and logging agents.
  5. Create an uptime check with an alert policy.
  6. Create a custom dashboard.

Before you begin

  1. Create a new Google Cloud Platform Console project named stackdriver-lamp-quickstart.
  2. Enable billing for your project.

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. Click Create Instance.

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

    • Name: lamp-1-vm
    • Firewall: Check both Allow HTTP traffic and Allow HTTPS traffic

    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 Connection column, click SSH to open a terminal to your instance.

  6. Run the following commands on your instance to set up an Apache2 web server:

    sudo apt-get update
    sudo apt-get install apache2 php5
  7. If you now copy the IP address for your instance to your browser, 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. Click Create new Stackdriver account and then Continue. You see the following page:

    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 Done to skip ahead.

  6. In a few seconds you see the following message:

    Finished initial collection

    Click Launch Monitoring.

  7. In the page, "Get reports by email", click No reports and Continue.

  8. You will see your Stackdriver account dashboard. Close the "Welcome to Stackdriver" banner if you don't need it.

Install the Stackdriver agents

The Stackdriver 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:

  1. Go back to the Stackdriver Monitoring Console.

  2. If you see the invitation Create an Uptime Check on the dashboard, then click it. Otherwise, go to Alerting > Uptime Checks in the top menu and then click Add Uptime Check. You see the New Uptime Check panel:

    Create an uptime check

  3. Fill in the following fields for the 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 web server. For other errors, see Uptime checks.

  5. Click Save. You see the following panel:

    Do you want an alerting policy

  6. Click Create Alerting Policy in the preceding panel. You see the following dialog:

    Create an alerting policy

  7. The Conditions section is already set up. You don't have to change it.

  8. In the Notifications section, click Add notification and fill in your email address.

  9. In the Documentation section, click Add Documentation and enter: Stackdriver LAMP quickstart example.

  10. In the Name this policy section, you can accept the default Uptime Check Policy.

  11. Click Save Policy.

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'll have to wait up to five minutes for the next uptime check to fail. The alert and notification don't happen until the next failure occurs.

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

Create a dashboard and chart

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

  1. In the top menu of Stackdriver Monitoring Console, select Dashboards > Create....

    Go to the Create Dashboard page

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

    Add chart

  3. In the Metric Type menu, select "CPU Load Average (past 5m)". You see the chart data in the Preview section.

  4. Click Save.

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

  6. In the Metric Type menu, select "Network Inbound Traffic (agent)".

  7. Click Save.

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

View your logs

Stackdriver Monitoring and Stackdriver Logging are closely integrated.

  • In the Stackdriver Monitoring Console top menu, click Logs. You see the Logs Viewer. Change the Logs Viewer focus to see the logs you want:

    1. Select Compute Engine > Instance > All resource IDs in the first drop-down menu.
    2. Select syslog in the logs menu.

    You see the syslog logs from your VM instance:

    Logs viewer

  • Return to the Stackdriver Monitoring Console. In one of your charts, open the settings menu and select View Logs. You will be shown the logs corresponding 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 charts and alerts, so that you won't get errors when you shut down your VM instance.

    1. Delete your alerting policy from Alerting > Policy Overview.
    2. Delete your uptime check from Alerting > Uptime Checks.
    3. Delete your charts from Dashboards > Stackdriver LAMP quickstart example
  2. Stop your VM instance by visiting the Compute Engine VM Instances page:

    Go to Google Compute Engine VM instances

    1. Select your instance.
    2. 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".

What's next

Send feedback about...

Stackdriver Monitoring