Setting an Uptime Alert

This tutorial shows how to set up an uptime alert for the Python Hello World Application using Google Stackdriver. Uptime alerts allow you to receive notifications whenever your application is not serving traffic. This tutorial demonstrates setting an uptime alert for the Hello World application on App Engine Flexible. You can also set uptime alerts for applications deployed on Google Compute Engine or Google Kubernetes Engine.


  • Deploy a basic "Hello World" app.
  • Create an uptime check that monitors that the application returns a 200 HTTP response.
  • Create an alert policy that emails you when the uptime check fails.
  • Redeploy the app so it returns a 404 response and triggers the alert so that you receive an email.


This tutorial uses billable components of Cloud Platform, including:

  • Google App Engine
  • Google Stackdriver Monitoring

Stackdriver Monitoring is currently offered to Beta users free of charge.

Use the Pricing Calculator to generate a cost estimate based on your projected usage. New Cloud Platform users might be eligible for a free trial.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Google Cloud Platform project.

    Go to the Manage resources page

  3. Make sure that billing is enabled for your Google Cloud Platform project.

    Learn how to enable billing

Cloning the sample application

The sample application is available on GitHub at GoogleCloudPlatform/getting-started-python.

  1. Clone the repository:

    git clone
  2. Navigate to the sample directory:

    cd getting-started-python/1-hello-world

Because the application simply returns "Hello World", no configuration is required and you can deploy right away.

gcloud app deploy

You should now be able to see the Hello World message:


Creating an uptime check

With your app deployed, you can use Google Stackdriver Monitoring to create an uptime check that will continually ping your deployed application and ensures it's returning a healthy response. To use Stackdriver, your project must be in a Stackdriver Account.

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

  1. In the Google Cloud Platform Console, select Stackdriver > Monitoring:

    Go to Monitoring

    Because your project is not in a Workspace, 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 name shown, click Create account.

  4. In the "Add Google Cloud Platform projects to monitor" page, click Continue to skip ahead.

  5. In the "Monitor AWS accounts" page, click Done to skip ahead.

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

    Finished initial collection

    Click Launch Monitoring.

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

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

You should now see the Stackdriver console and be able to create an Uptime Check. Under Alerting, click Uptime Checks, then click Create an Uptime Check.

  1. A window might pop up to automatically create an uptime check. In order to manually configure it, click No thanks.
  2. Give your check a title, such as "Check Hello World".
  3. Because you deployed to App Engine, change Resource Type to App Engine instead of URL, which you would use to target a custom URL on a Compute Engine instance.
  4. Leave Path blank, which defaults the main index page.
  5. Change Check every to 1 minute, so that the demonstration of the alert will work faster.

Creating an alerting policy

After you create the check, you are automatically prompted to create an associated alerting policy. Alerting policies allow you to manage how Stackdriver informs you of any incidents, such as a failed uptime check.

  1. Click Create Alerting Policy. Give your policy a name like "Hello World Uptime Check Policy".

  2. If you followed the prompt, the Conditions of the alert should be preopopulated with your uptime check. Otherwise, you can click Add Another Condition > Uptime Check Health and re-create it.

  3. In order to receive an email for this alerting policy, under Notifications, keep the Email method, and click Add Notification in order to enter your email address.

  4. Click Save to save this policy.

Simulating an outage

Now that the check is created, you can simulate an outage by changing your app to respond with an HTTP 404 Not Found error rather then a 200 OK response. Looking at the view function in our Hello World application, it currently returns only a 'Hello World' message, and the status code of the response defaults to 200 OK.

from flask import Flask

app = Flask(__name__)

def hello():
    """Return a friendly HTTP greeting."""
    return 'Hello World!'

if __name__ == '__main__':'', port=8080)

In order to have it return a 404 HTTP error code, you can change the return line to add a 404 value to the second part of the return value.

return 'Hello World', 404

Deploy the new intentionally broken app:

gcloud app deploy

Within half an hour, you should see an email stating that your uptime check is failing.

Cleaning up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this tutorial:

The easiest way to eliminate billing is to delete the project you created for the tutorial.

To delete the project:

  1. In the GCP Console, go to the Projects page.

    Go to the Projects page

  2. In the project list, select the project you want to delete and click Delete delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Was this page helpful? Let us know how we did:

Send feedback about...