Setting an uptime alert

This tutorial shows how to set up an uptime alert for the Python Hello World app running on App Engine flexible environment using Cloud Monitoring. Uptime alerts let you know when your app is not serving traffic. You can also set uptime alerts for apps running on Compute Engine or Google Kubernetes Engine (GKE).


  • Run a basic Hello World app.
  • Create an uptime check that monitors whether the app returns an HTTP '200' status code.
  • Create an alert that sends an email message to you when the uptime check fails.
  • Restart the app to trigger the alert.


Monitoring is currently offered to beta users at no charge.

Before you begin

  1. Sign in to your Google Account.

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

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

Cloning the sample app

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

  1. Clone the repository.

    git clone
  2. Go to the sample directory.

    cd getting-started-python/1-hello-world
  3. Because the app only returns "Hello World!", it requires no configuration, and you can run it right away.

    gcloud app deploy
  4. To see the returned message, enter the following URL in your browser:

    Replace the following:

Adding your project to a Workspace

After your app is deployed, you can use Monitoring to create an uptime check. The check continually pings your deployed app to ensure that it's returning a healthy response. To use Google Cloud's operations suite, your project must be in a Workspace.

  1. From to the Cloud Console, go to Monitoring.

    Go to Monitoring

  2. If the Add your project to a Workspace dialog is displayed, create a new Workspace by selecting your Google Cloud project under New Workspace and then clicking Add. In the following image, the Google Cloud project name is Quickstart:

    Select workspace

    The Add your project to a Workspace dialog is displayed only when you have at least one existing Workspace available to you. The Workspaces listed under Existing Workspace are Workspaces you've created or Workspaces for Google Cloud projects where you have editorial permission. Using this dialog, you can choose between creating a new Workspace and adding your project to an existing Workspace.

Creating an uptime check

  1. In the Cloud Console, go to Monitoring.

    Go to Monitoring

  2. In the navigation pane, click Uptime Checks, then click Create an Uptime Check.

  3. If a dialog opens asking to automatically create an uptime check, click No thanks.

  4. Give your check a title, such as Check Hello World.

  5. Because you deployed to App Engine, change Resource Type to App Engine instead of URL. (URL is for generating a custom URL on a Compute Engine instance.)

  6. Leave Path blank to default to the main index page.

  7. Change Check every to 1 minute.

Creating an alerting policy

After you create the check, you are automatically prompted to create an associated alerting policy. An alerting policy lets you manage how Google Cloud's operations suite informs you of any incidents, such as a failed uptime check.

  1. To follow the prompt, click Create Alerting Policy. Give your policy a name, such as Hello World Uptime Check Policy.

  2. The Conditions of the alert are prepopulated with your uptime check. To manually populate the Conditions instead, you can click Add Another Condition > Uptime Check Health.

  3. To receive an email message from this alerting policy, under Notifications, make sure that Email is selected, and then click Add Notification to enter your email address.

  4. Click Save.

Simulating an outage

Now that the uptime check is created, you can simulate an outage by changing your app to respond with an HTTP 404 Sorry, we can't find that page error rather than an HTTP 200 OK response.

  1. The following code shows where the Hello World app returns only a 'Hello World!' message, and that the status code of the response defaults to 200 OK. To view this code in the Hello World app, use the view function.

    from flask import Flask
    app = Flask(__name__)
    def hello():
        """Return a friendly HTTP greeting."""
        return 'Hello World!'
    if __name__ == '__main__':'', port=8080)
  2. To cause the Hello World app to return an HTTP 404 error code, change the return line by adding a 404 value to the second part of the return value.

    return 'Hello World', 404
  3. Deploy the new, intentionally broken app.

    gcloud app deploy

    Within half an hour, you'll receive an email message that states 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 that you created for the tutorial.

To delete the project:

  1. In the Cloud Console, go to the Manage resources page.

    Go to the Manage resources page

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