Monitor usage patterns for service accounts and keys

This page explains how to use Cloud Monitoring to view usage metrics for your service accounts and service account keys. These metrics let you view and track usage patterns, which can help you identify anomalies, either automatically or manually.

Service accounts and service account keys appear in these metrics if they are used to call any Google API, including APIs that are not part of Google Cloud. The metrics include both successful and failed API calls. For example, if an API call fails because the caller is not authorized to call that API, or because the request referred to a resource that does not exist, the service account or key that was used for that API call appears in the metrics.

Service account keys also appear in these metrics if a system lists the keys while attempting to authenticate a request, even if the system doesn't use the key to authenticate the request. This behavior is most common when using signed URLs for Cloud Storage or when authenticating to third-party applications. As a result it is possible to see usage metrics for keys that have not been used for authentication.

The following don't appear in either service account or service account key metrics:

Monitoring retains service account metrics for 6 weeks. If you need to access data for a longer time period, you can periodically export the results to BigQuery. For more information, see Monitoring metric export in the Solutions documentation.

After you use a service account or service account key, usage metrics are usually available within a few minutes.

Before you begin

  • Enable the IAM and Cloud Monitoring APIs.

    Enable the APIs

Required roles

To get the permissions that you need to view recent usage for service accounts and keys, ask your administrator to grant you the Monitoring Viewer ( roles/monitoring.viewer ) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations .

You might also be able to get the required permissions through custom roles or other predefined roles .

View usage metrics for all service accounts or keys

To view the usage metrics for your service accounts or service account keys, follow these steps:

View usage metrics for a single service account

To view usage metrics for a single service account, follow these steps:

View usage metrics for a single service account key

To view usage metrics for a single service account key, follow these steps:

Export metrics

You can use Monitoring to export your metrics to BigQuery. Exporting metrics is useful for performing long-term analysis because Monitoring only retains metrics for a limited time.

For instructions, see Monitoring metric export in the Solutions documentation.

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: