Skip to main content

Create an SMS Alerting Policy with Stackdriver

Hands-On Lab

 

Photo of Broadus Palmer

Broadus Palmer

Google Cloud Training Architect

Length

00:45:00

Difficulty

Beginner

An alerting policy describes a set of conditions that you want to monitor within your infrastructure. Alerting policies provide granular information about your architecture that can help you troubleshoot issues if needed. In this hands-on lab, we will set up an SMS alerting policy on a Compute Engine instance and simulate instance failure to test it.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create an SMS Alerting Policy with Stackdriver

Introduction

An alerting policy describes a set of conditions that you want to monitor within your infrastructure. Alerting policies provide granular information about your architecture that can help you troubleshoot issues if needed. In this hands-on lab, we will set up an SMS alerting policy on a Compute Engine instance and simulate instance failure to test it.

Connect to the Lab

  1. On the lab instructions page, right-click the Open GPC Console button.
  2. From the dropdown, select the option to open the link in a private browser window. (Note: Different browsers have different names for a private browser window. In Chrome, you'll choose Open Link in Incognito Window. If you're using Firefox, click Open Link in New Private Window. Etc.)
  3. On the Google sign-in page, enter the unique username you were provided on the lab instructions page. Click Next.
  4. Enter the unique password you were provided on the lab instructions page. Click Next.
  5. On the Welcome to your new account page, click Accept.
  6. In the Welcome L.A.! menu, check the box under Terms of service.
  7. Choose your country of residence, then click AGREE AND CONTINUE.

Enable the Stackdriver Monitoring and Stackdriver Logging APIs

  1. From the Google Cloud Platform dashboard, click the main navigation menu at the top left of the page.
  2. In the dropdown, choose APIs & Services > Dashboard.
  3. Click the + Enable APIs and Services tab.
  4. In the search bar, type "stackdriver".
  5. Select the Stackdriver Monitoring API.
  6. Click Enable API.
  7. Click the back arrow at the top left of the screen to go back to the API Library.
  8. Select the Stackdriver Logging API.
  9. Click Enable API.

Create a VM

  1. Click the main navigation menu at the top left of the page.
  2. Select Compute Engine > VM instances.
  3. Click Create.
  4. On the Create an instance page, configure the following settings:
    • Name: instance-1
    • Region: us-central1 (Iowa)
    • Zone: us-central1-a
    • Machine type: n1-standard-1 (1 vCPU, 3.75 GB memory)
    • Firewall: Allow HTTP traffic
  5. Click Create.

Install Apache and PHP

  1. Under the Connect header of the instance, click SSH.
  2. In the Cloud Shell, run the following command to update the packages:
    sudo apt-get update
  3. Install Apache and PHP.
    sudo apt-get install apache2 php -y

Install the Stackdriver Monitoring and Stackdriver Logging Agents

  1. Download the Stackdriver Monitoring agent installation package.
    curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
  2. Install the Stackdriver Monitoring agent.
    sudo bash install-monitoring-agent.sh
  3. Download the Stackdriver Logging agent installation package.
    curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
  4. Install the Stackdriver Logging agent.
    sudo bash install-logging-agent.sh
  5. Go back to your GCP console browser tab.
  6. Under the External IP header of the instance, click the arrow on the right of the IP address.

Add an Uptime Check and Create an Alerting Policy

  1. Click the main navigation menu at the top left of the page.
  2. Under the Stackdriver header, select Monitoring.
  3. In the Stackdriver Monitoring dashboard, click your profile name at the top right of the page.
  4. In the dropdown, select Profile.
  5. Under the Phone Numbers header, click Workspace Settings.
  6. Click Add Phone Number.
  7. In the Add Contact Number menu, enter your phone number (make sure to set the correct country code).
  8. Click Send Verification Code.
  9. In the Verify Your Contact Number menu, enter the 6-digit verification code you received, and click Verify.
  10. In the left navigation panel, click Monitoring Overview.
  11. Under Create uptime checks, click CREATE CHECK.
  12. In the New Uptime Check menu, configure the following settings:
    • Title: my-uptime-check
    • Check Type: HTTP
    • Resource Type: Instance
    • Applies To: Single | instance-1
    • Check every: 1 minute
  13. Click Test.
  14. Click Save.
  15. Click Create Alert Policy.
  16. Name the policy "myuptimecheck-alert".
  17. Click the Metric tab.
  18. Leave the settings as their defaults, and click Save.
  19. Click Notification Channel Type, and select SMS from the dropdown.
  20. Click Notification Channel, and select your phone number from the dropdown.
  21. Click Add Notification Channel.
  22. Under Name this policy, enter "uptimecheck-policy".
  23. Click Save.

Test the Alerting Policy

  1. In the left navigation panel, click Uptime Checks > my-uptime-check.
  2. Go back to the GCP console.
  3. Click the checkbox to select the VM instance.
  4. Click the "More options" menu (â‹®), and select Stop from the dropdown.
  5. In the Stop VM instance menu, click STOP.
  6. You should receive an SMS message alerting you that the instance is down.
  7. Go back to your Stackdriver Monitoring browser tab.
  8. In the left navigation panel, select Uptime Checks.
  9. Refresh the page to see the "All locations failed" alert.

Conclusion

Congratulations, you've successfully completed this hands-on lab!