Quickstart

This page gets you started using Stackdriver Monitoring by creating a Stackdriver account, installing the Stackdriver agents on a virtual machine (VM) instance, creating uptime checks with alert policies, and creating custom dashboards.

Before you begin

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

Create a VM instance

To try out Stackdriver Monitoring, you'll need something to monitor. Create a VM instance with an Apache2 web server:

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

    Go to Google Compute Engine

    It can take a minute or two to start up Compute Engine.

  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 click on 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 click on the IP address for your instance, you see the Apache2 default page:

    Apache2 default page

Create a Stackdriver account

To use Stackdriver, your project must be in a Stackdriver account:

  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.

  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:

    Create an alerting policy

  7. Fill in Policy name with "lamp-1 policy".

  8. Click Add notification and fill in your email address.

  9. In the Documentation section, enter: "Stackdriver LAMP quickstart example."

  10. 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

  • Explore the features of Stackdriver Monitoring on your own.

  • See Available Metrics for a list of the metrics available in the Stackdriver Monitoring Console. See Supported Metrics for details about the Google Cloud Platform service metrics. If you want to create your own Stackdriver Monitoring metrics, see Custom metrics.

  • To use the Stackdriver Monitoring API, see the API reference and the sample code.

  • For more information on logging and its relation to monitoring, see Stackdriver Logging.

Send feedback about...

Stackdriver Monitoring