API usage alerts in GCP

By John Keyes

July 19, 2024 at 12:18

google google monitoring alerts

Introduction

It can be useful to be notified when usage of a Google API goes past a level you deem noteworthy. This can be helpful to manage costs, and to understand why API usage is high. Maybe due to a specific event, or a specific day of the week, etc.

This post does not intend to be the canonical source for all things alerts in GCP, it is intended to make the first step into the unknown (or partially remembered) a little bit easier.

Where are the Alerts

Alerts are in the Monitoring product (see below). If you don’t have it pinned you will find it in the “Products and solutions” section. This quick link will work for logged in users.

Be sure to check you are working on the correct project. In the screenshot below you can see Dunkettle shaded at the top of the screen.

Alerts page

On this alerts page we can see there is a single alerting policy.

Alert policy

Clicking on this policy opens the policy:

There are a few components to a policy.

Policy metrics

Select the metric you wish to monitor. In this scenario we are interested in the number of requests being received by the Google Maps API:

Policy data

After selecting the metric, it is now time to choose how to transform the data from that metric.

What is a time series?

And the various functions that can be applied are:

The example we are seeing here was set up hurriedly, and I don’t think the function dropdown was even used. So in this case are using the mean as the function, but for the simplest cases using count would appear to be a better option.

Policy aggregation

What is time series aggregation?

The default setup is to not aggregate the data across locations e.g.

But, we can aggregate the timelines to get an overall system view in a single timeline. Here we use mean as the function again, and group by API response code:

And the result is now a single timeline:

I don’t know how rolling window functions and aggregation functions interact. That’s a to-be-discovered element of this.

Summary

This post should have provided enough information to help get a Google Alert setup for one of the Google APIs. It’s not definitive by any means and any suggestions to improve are welcome.

Last updated: July 19, 2024 at 12:18