Vitaliy
Vitaliy

Reputation: 429

Monitor Google API usage programmatically?

https://console.cloud.google.com/apis/dashboard If we open google console we see how many requests per every service has been done. Is there any way to export these counters? I was not able to find any API which is responsible for these counters.

Get google maps api usage info Detect Google Maps Javascript API limit for map loads

Many years passed, still no way to setup alerting for API usage? If there is no programmatic access may be there is some way to setup alerts when API usage is above threshold?

Upvotes: 1

Views: 460

Answers (1)

Shawn Domingo
Shawn Domingo

Reputation: 1411

As mentioned by the first answer, there's no such API to monitor these usages but there are couple of ways to monitor your usage which are:

  1. Setup Budget Alerts, this will trigger notification if you've reached a certain amount of your specified budget for a month, but please note that this will only notify you and will not actually stop the usage after the specified amount.

  2. If you would like to monitor or get an overview of your daily usage, you may implement what we call channels with the help of BigQuery Export. This will give you a breakdown report of daily usage. The standard SQL code you can use to retrieve such report using the BigQuery export is:

SELECT   Date(usage_start_time, "America/Los_Angeles") AS billing_day,
         invoice.month                                 AS invoice_month,
         service.description                           AS service,
         sku.description                               AS sku,
         (
                SELECT l.value
                FROM   Unnest(labels) AS l
                WHERE  l.KEY = 'goog-maps-channel' ) AS goog_maps_channel,
         Round(Sum(usage.amount), 2)                 AS usage_amount,
         usage.unit                                  AS usage_unit,
         Round(Sum(cost), 2)                         AS cost,
         cost_type,
         currency
FROM     `PROJECT_ID.DATASET_NAME.gcp_billing_export_v1_BILLING_ACCOUNT_ID`
WHERE    invoice.month = '201906' -- Change the invoice month with the same format as the example.
GROUP BY billing_day,
         invoice_month,
         service,
         sku,
         goog_maps_channel,
         usage_unit,
         cost_type,
         currency
ORDER BY billing_day,
         service,
         sku

You may learn more on how to setup the BigQuery export here.

  1. If you want to restrict your usage up to a certain amount per day, you may also implement the Capping of API usage wherein it will only allow an API to call a specific amount of requests per day.

If you would ever need help in the correct calculation of requests per day for each API to be on a certain budget, you may reach to the support team of the Google Maps Platform APIs here.

Upvotes: 2

Related Questions