Stackdriver Monitoring Automation Part 6: Uptime Checks with Terraform

Charles
Google Cloud - Community
3 min readMar 5, 2019

This post is part 6 in the Stackdriver Automation series. In this post, I will walk through the steps that you can use to automate the management of Stackdriver Monitoring Uptime Checks with Terraform.

Uptime Checks

Uptime Checks lets you verify the availability of your service via HTTP, HTTPS or TCP health checks. Stackdriver provides this service by accessing your application’s frontend from locations around the world and reporting on the results such as latency and response codes. You can use this service as a way to understand whether your users can access the service from various global locations.

Uptime Checks Configuration

As an example, I created an Uptime Check based on the apache infrastructure that I described in parts 1 and 2 of this series. The application itself is a simple website being hosted by apache servers behind a load-balancer. I created a simple HTTP Uptime Check to understand whether my users could access the service.

provider "google" {
project = "abab-cdcd-023991"
region = "us-central1"
zone = "us-central1-c"
}
resource "google_monitoring_uptime_check_config" "http" {
display_name = "1 - Website uptime check [global]"
timeout = "10s"
period = "60s"
http_check {
path = "/"
port = "80"
}
monitored_resource {
type = "uptime_url"
labels = {
host = "35.241.47.194"
}
}
}

You can find the full configuration files on the github repo.

After the standard initialization, the terraform apply does all the work and creates the Uptime Check.

$ terraform applyAn execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:+ google_monitoring_uptime_check_config.http
id: <computed>
display_name: "01 - Website uptime check [global]"
http_check.#: "1"
http_check.0.path: "/"
http_check.0.port: "80"
monitored_resource.#: "1"
monitored_resource.0.labels.%: "1"
monitored_resource.0.labels.host: "35.241.47.194"
monitored_resource.0.type: "uptime_url"
name: <computed>
period: "60s"
project: <computed>
timeout: "10s"
Plan: 1 to add, 0 to change, 0 to destroy.Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yesgoogle_monitoring_uptime_check_config.http: Creating...
display_name: "" => "01 - Website uptime check [global]"
http_check.#: "" => "1"
http_check.0.path: "" => "/"
http_check.0.port: "" => "80"
monitored_resource.#: "" => "1"
monitored_resource.0.labels.%: "" => "1"
monitored_resource.0.labels.host: "" => "35.241.47.194"
monitored_resource.0.type: "" => "uptime_url"
name: "" => "<computed>"
period: "" => "60s"
project: "" => "<computed>"
timeout: "" => "10s"
google_monitoring_uptime_check_config.http: Creation complete after 1s (ID: projects/abab-cdcd-023991/uptimeCheckConfigs/01-website-uptime-check-global)
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Once the uptime checks were created, I used the Stackdriver Monitoring console to verify that the uptime checks had been successfully created. Keep in mind that when you first create uptime checks, it can take up to 5 mins to start reporting status according to the docs.

Now, the uptime checks are active and can be used in conjunction with alerting policies to notify you when the uptime checks fail or when the latency is outside of tolerance.

Conclusion: The Stackdriver Monitoring Automation Series

This concludes the Stackdriver Monitoring Automation series. In this series, I have included the steps that I took and the methods that I used to create Stackdriver Monitoring components via Google Cloud Deployment Manager and Terraform. In the posts 1 and 4, I created a Stackdriver Group used to group resources to monitor as a single entity. In posts 2 and 5, I created Stackdriver Alerting Policies to define when to send an alert and what alert to send. In posts 3 and 6, I created Stackdriver Uptime Checks to provide a basic picture of end-user experience. You can use these steps and config files as templates to automate the deployment of Stackdriver Monitoring resources in your environment.

Read more about Stackdriver Monitoring Automation in the other posts in the series and references below.

References:

--

--