What you need

To complete this lab, you need:

Internet access

Access to a supported Internet browser:

What you do

What you learn

In this codelab you will learn how to use Stackdriver Monitoring to gain insight into applications that run on Google Cloud Platform.

Step 1 Create a Project

To make cleanup easier, create a new google cloud project.

Remember the project ID, a unique name across all Google Cloud projects. It will be referred to later in this lab as PROJECT_ID.

Step 2 Launch CloudShell

Now let's open the cloud shell. The cloud shell icon is at the top right:

A cloud shell session will open inside a new frame at the bottom of your browser.

Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your PROJECT_ID. If this is not the case, replace your PROJECT_ID in the following command:

gcloud config set project PROJECT_ID

We need to create some resources within this Google Cloud Platform project before we can actually monitor them. Let's do that now.

We will create a few Nginx instances using a Bitnami Nginx Stack image, which includes a complete PHP, MySQL and Nginx development environment.

Step 0 Enable the Compute Engine API

Step 1 Create Instances

Let's create a few instances, by copying the following command in cloud shell:

for i in {1..3}; \
do \
  gcloud compute instances create "nginxstack-$i" \
  --machine-type "f1-micro" \
  --tags nginxstack-tcp-443,nginxstack-tcp-80 \
  --zone us-central1-f \
  --image   "https://www.googleapis.com/compute/v1/projects/bitnami-launchpad/global/images/bitnami-nginxstack-1-10-2-0-linux-debian-8-x86-64" \
  --boot-disk-size "10" --boot-disk-type "pd-standard" \
  --boot-disk-device-name "nginxstack-$i"; \
done

Step 2 Create a Firewall Rule

Next, let's create a firewall rule to allow external traffic to these instances

gcloud compute firewall-rules create nginx-firewall \
 --allow tcp:80,tcp:443 \
 --target-tags nginxstack-tcp-80,nginxstack-tcp-443

To use Stackdriver Monitoring with your project, do the following:

Step 1

Select "Monitoring" on the Cloud Console's left navbar. This will redirect to the Stackdriver Monitoring Console.

Step 2

You may be prompted to login again. If so, click "Log in with Google", and then choose your account to login.

Step 3

Once logged in, Stackdriver will ask you to add the project to a Stackdriver account. Choose "Create a new Stackdriver account", and click Continue.

Step 4

Click Create Account to create a Stackdriver account on this project

Step 5

If you want to monitor other Google Cloud Platform projects under the same Stackdriver account, select the projects, and click Continue.

Step 6

For extra credit, if you use AWS, you can also monitor AWS accounts with Stackdriver Monitoring. You can skip this section, click Continue.

Step 7

We will not install the Stackdriver agents on this codelab, click Continue.

Step 8

Stackdriver can send you reports on the performance of your application. For this codelab, select "No Reports", click Continue.

Step 9

Stackdriver will then perform an initial collection task on your resources. Once it's done, click Launch monitoring.

Step 10

You will see a Welcome dialog informing you that your Stackdriver account is in a free trial of the Premium Tier for 30 days. Click, Continue with the trial.

You should now be looking at the Stackdriver Monitoring Console. The information on the console will vary depending on the resources you are monitoring.

Step 1 Create Dashboard

Select Dashboards on the left navbar, and click Create Dashboard.

Click on the Untitled Dashboard text field and replace the text with an appropriate dashboard title, like Codelab Dashboard

Step 2 Add Chart

To add a chart to your dashboard, do the following:

Click the Add Chart button

Step 3 Explore the chart

  1. Select Instance (GCE) on the Resource Type drop down
  2. Click on the Metric Type field. A metric drop down list is populated. Choose a metric to chart for the Instance (GCE) resource, such as Network Outbound Traffic, or Running processes.
  3. Select a Chart Type.
  4. Explore the Advanced Options, including adding a Threshold line, or using an aggregate function.
  5. Explore filtering the results, according to the various options.
  6. Now, give the chart a meaningful name.
  7. Click Save to add the chart to your dashboard.

Step 4 Metrics Explorer

As it name implies, the Metrics Explorer allows you to examine resources and metrics without having to create a chart on a dashboard.

Let's try to recreate the chart we just created with the Metrics Explorer:

  1. Select Resources on the left navbar, and click Metrics Explorer.
  2. Click or start typing a metric or resource name on the text field.
  3. Explore the various options and try to recreate the previous chart.

You can set up alerting policies in Stackdriver Monitoring to determine when your applications are not operating normally.

To create an alerting policy, select Alerting on the left navbar, and click Create a Policy.

Step 1 Add First Condition

  1. Click Add Condition
  2. Click Select on the Metric Threshold condition
  3. Select Instance (GCE) as the Resource Type.
  4. Select Single as the Applies condition.
  5. Choose one of your instances, as the resource that will be part of the target.
  6. Select a metric you are interested in evaluating, such as "CPU (agent)".
  7. Select above as the condition
  8. Specify the threshold value and for how long the metric must cross this set value before the alert is triggered
  9. Click Save Condition

Step 2 Add Second Condition

  1. Click Add another condition
  2. Repeat the steps above to specify the second condition for this policy
  3. On the Trigger When drop down, select ALL conditions are met.

Step 3 Notifications

You can configure one or more notifications to contact specific people or services when an alerting policy is violated.

  1. Click Add Notification
  2. Select Email as the notification channel and enter an email address

Step 4 Finish Alerting Policy

  1. Skip the Documentation step
  2. Enter a name for this policy.
  3. Click Save Policy

  1. Select Groups on the left navbar, and click Create Group.
  2. Enter a name for the Group, such as "GCE Central"
  3. Select Region from the drop down
  4. Select gce us-central1
  5. Click Save Group
  6. Review the dashboard Stackdriver created for your group

  1. On the same group dashboard from previous step, select the Add button of the Uptime Check section.
  2. Enter a title for the uptime check
  3. Select HTTP as the Check Type
  4. Select Instance as the Resource Type
  5. Select 5 minutes as the Check every option
  6. Click Save
  7. Click No Thanks on the Uptime Check Created dialog

Step 1 Summary

What we've covered

Step 2 Cleanup

Take the next few minutes to disable or delete any Alerts you created. It may take some time for the service to stop sending messages.

Step 3 Delete the Project

You can delete the project.

┬ęGoogle, Inc. or its affiliates. All rights reserved. Do not distribute.