The monitoring agent is an optional part of Google Cloud Monitoring.

Cloud Monitoring uses the Stackdriver system agent to monitor additional system resources and application services in Google Compute Engine VM instances. If you want these additional capabilities, you should install the agent and optionally some application-specific plugins on your VM instances.

By default, the agent will collect and send data about CPU utilization, CPU load, memory usage, swap usage, count of processes, disk usage, disk IO and network traffic. Agent metrics are monitored at 1-minute granularity. This information is displayed on individual instance pages and is available for selection on custom and group dashboards. In addition, there are other services which can be set up for collection using plugins.

In this codelab, you'll learn how to install the Monitoring Agent into a Compute Engine instance running Debian.

What you'll learn

What you'll need

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with Google Cloud Platform?

Novice Intermediate Proficient

Codelab-at-a-conference setup

The instructor will be sharing with you temporary accounts with existing projects that are already setup so you do not need to worry about enabling billing or any cost associated with running this codelab. Note that all these accounts will be disabled soon after the codelab is over.

Once you have received a temporary username / password to login from the instructor, log into Google Cloud Console: https://console.cloud.google.com/.

Here's what you should see once logged in :

Note the project ID you were assigned ( "codelab-test003" in the screenshot above). It will be referred to later in this codelab as PROJECT_ID.

Before we can use Google Cloud Monitoring, it must first be enabled for your project.

To use Cloud Monitoring with one of your projects, do the following:

  1. Visit the Cloud Monitoring Console, select the project you wish to monitor, and select Continue.
  2. If this is the first time you have used Cloud Monitoring with your project, select
  3. Once Monitoring has been enabled, select

You are now looking at the Cloud Monitoring Console. The information shown will vary depending on the Google services you are using and the monitoring features you have set up, but it will look something like the following:

Before we can install the Monitoring Agent on any resource, we will need to get the Cloud Monitoring API Key to authenticate the Compute Engine instance we will create in the next step of this code lab.

To get your key:

  1. Get started by visiting the Cloud Monitoring API page. Note that this page is not the Developers Console API page.
  2. You should already have a key for the agent with the role Submit Data.
  3. Copy this API Key for later

We will create a Compute Engine instance, so that we have a virtual machine in which we can install the Monitoring Agent.

  1. Navigate back to the Google Cloud Development Console
  2. Navigate to Compute > Compute Engine
  3. Click or
  4. Name the instance "monitoring-agent"
  5. Click
  6. After about a minute a green check will appear next to and you can continue to the next step.

You now have a Compute Engine instance in which we can install the Cloud Monitoring Agent.

In this section, we will SSH into the "monitoring-agent" Compute Engine Instance we created in the previous instance, and install the Monitoring Agent.

SSH Into the Instance

To SSH into the "monitoring-agent" machine, click the SSH button on the right hand side of the Compute Engine Instance listing page

This will create a new SSH session in your browser, connecting you to the "monitoring-agent" instance

Installing the Agent

Within the SSH session, run the following commands, replacing STACKDRIVER_API_KEY with the API key you obtained in Getting an API key step:

$ curl -O https://repo.stackdriver.com/stack-install.sh
$ sudo bash stack-install.sh --api-key=STACKDRIVER_API_KEY

Verifying a Successful Installation

To verify your installation, run the following command in the SSH Session:

$ /opt/stackdriver/stack-config info

The output should resemble the following:

Stackdriver Host Info Dump
Resource Id: 012345678901234567890
API Key: ABCDEFG01234567890
Error talking to Stackdriver gateway No JSON object could be decoded
[ ok ] stackdriver-agent is running.
Agent status:  Agent config snippets:
[ ok ] stackdriver-extractor is running.
Extractor status:  Extractor sample data:
{
  ...[omitted]
}

Once these command have completed, you now have the Monitoring agent installed in your Compute Engine instance!

You now have a Compute Engine instance that has the Cloud Monitoring Agent installed on it! This will give Cloud Monitoring access to extra information about the instance and will allow for extra monitoring functionality.

What we've covered

Next Steps

Learn More