Setting an uptime alert Stay organized with collections Save and categorize content based on your preferences.
This tutorial shows how to set up an uptime alert for thePython Hello World app running on App Engine flexible environment usingCloud Monitoring.Uptime alerts let you know when your app is not serving traffic. You can also setuptime alerts for apps running onCompute Engine orGoogle Kubernetes Engine (GKE).
Objectives
- 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 uptimecheck fails.
- Restart the app to trigger thealert.
Costs
Important: In this document, you use the following billable components of Google Cloud: To generate a cost estimate based on your projected usage, use thepricing calculator.
Monitoring is currently offered to beta users at no charge.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Cloning the sample app
The sample app is available on GitHub atGoogleCloudPlatform/getting-started-python.
Clone the repository.
gitclonehttps://github.com/GoogleCloudPlatform/getting-started-python.gitGo to the sample directory.
cdgetting-started-python/gceBecause the app only returns "Hello World!", it requires no configuration, andyou can run it right away.
gcloudappdeployTo see the returned message, enter the following URL in your browser:
https://PROJECT_ID.REGION_ID.r.appspot.comReplace the following:
PROJECT_ID: Your Google Cloud project IDREGION_ID: Acode that App Engine assignsto your app
Creating an uptime check
After you deploy your app,you can use Monitoring to create an uptime check. The checkcontinually pings your deployed app to ensure that it's returning a healthyresponse.
In the Google Cloud console, go to the
Uptime checks page:If you use the search bar to find this page, then select the result whose subheading isMonitoring.
- ClickCreate Uptime Check.
Give your check a title, such as
Check Hello World,and then clickNext.In theTarget section, you specify what the uptime check is to monitor:
- Because you deployed to App Engine, changeResource Type toApp Engine instead ofURL. (URL is for generating a customURL on a Compute Engine instance.)
- Select theService to be monitored by the uptime check.
- LeavePath blank to default to the main index page.
- LeaveCheck frequency at the default of1 minute.
- ClickNext.
Leave theResponse Validation fields at their default values andclickNext.
In theAlert & Notification section, you specify how you are notifiedif an alert occurs:
- Ensure that the toggle's label isAlerting is enabled.
- Leave the name and duration fields at their default values.
To add a notification channel to the alerting policy, in thetext box labeledNotification channels, clickMenu.Select the channels to add and clickOK.The notifications are grouped alphabetically for each channel type.
To add an entry to the checkbox list, clickManage notification channels and follow the instructions. When youreturn to this dialog, clickRefreshrefresh.
ClickCreate. When the create action is successful, the messageCheck and alert created is displayed and then theUptime checksdashboard page is displayed.
In the uptime checks dashboard, your new uptime check is listed. If youclick the check name, then you open the detail view for that uptime check.This view displays several charts, shows the uptime percentage and theconfiguration information, and lists the configured alert policies.To view a policy, click its name.
You can also view the alert policy by starting at theAlerting page.From the alerting page, thePolicies pane lists a subset of policies.To view a list of all policies, clickSee all policies.
Simulating an outage
Now that the uptime check is created, you can simulate an outage by changingyour app to respond with an HTTP404 Sorry, we can't find that page errorrather than an HTTP200 OK response.
The following code shows where the Hello World app returns only a 'HelloWorld!' 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.# Copyright 2019 Google LLC All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.fromflaskimportFlaskapp=Flask(__name__)@app.route('/',methods=['GET'])defsay_hello():return"Hello, world!"if__name__=='__main__':app.run(host='127.0.0.1',port=8080,debug=True)To cause the Hello World app to return an HTTP
404error code, change thereturn line by adding a404value to the second part of the return value.return'Hello World',404
Deploy the new, intentionally broken app.
gcloudappdeploy
Within half an hour, you'll receive an email message that states that youruptime check is failing.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.