Google Cloud Monitoring Dashboards

2.21.0 · active · verified Fri Apr 17

The `google-cloud-monitoring-dashboards` client library provides Python access to the Google Cloud Monitoring Dashboards API. It allows programmatic creation, management, and listing of custom dashboards for visualizing metrics in Google Cloud Monitoring. Part of the larger `google-cloud-python` monorepo, it receives frequent updates alongside other Google Cloud client libraries.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Monitoring Dashboards client and lists the first 5 dashboards in a specified Google Cloud project. Requires `GOOGLE_CLOUD_PROJECT_ID` environment variable or direct replacement of 'your-gcp-project-id'.

import os
from google.cloud import monitoring_dashboards_v1

# Set your Google Cloud Project ID
project_id = os.environ.get("GOOGLE_CLOUD_PROJECT_ID", "your-gcp-project-id") 

try:
    # Initialize the client
    client = monitoring_dashboards_v1.DashboardsServiceClient()
    
    # The parent resource name for listing dashboards
    parent = f"projects/{project_id}"

    print(f"Listing up to 5 dashboards for project: {project_id}")
    
    # Iterate over and print dashboard display names
    for dashboard in client.list_dashboards(request={"parent": parent}, page_size=5):
        print(f"  - {dashboard.display_name} (ID: {dashboard.name.split('/')[-1]})")

except Exception as e:
    print(f"An error occurred: {e}")
    print("\nEnsure you have authenticated (e.g., `gcloud auth application-default login` or set `GOOGLE_APPLICATION_CREDENTIALS`) and provided a valid project ID.")

view raw JSON →