This repository contains samples that may be used with the Cloud Monitoring Dashboards API.
-
Check it out from GitHub. For example, you can do it in Cloud Shell by clicking the button below:
-
Use these commands to import the dashboard.
First, set your environment variables, replacing the following values with your values:
- PROJECT_ID you wish to import the dashboard to
- FILE_NAME with the input filename for the dashboard JSON config
export PROJECT_ID=<PROJECT_ID> export FILE_NAME=<DASH_FILE_NAME>
-
Use the provided script to create a dashboard.
scripts/dashboard/dashboard.sh import $PROJECT_ID $FILE_NAME
Alternatively, you can run the following command via curl. Use the projects.dashboards.create to call the Dashboards API with the sample JSON and create a new dashboard. Make sure you replace the [project-id] and [file-name.json] in the command:
curl -X POST -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://monitoring.googleapis.com/v1/projects/[project-id]/dashboards -d @[file-name.json]
If you want to export a dashboard to a JSON file and share it, you can use the following steps.
-
Create the dashboard in the Monitoring UI (or even better, share one that you’ve already developed and used).
-
Open the dashboard and copy the dashboard ID from the URL (the string is in the URL after the /monitoring/dashboards/custom/ ˆprefix). For example, 10768789961894600977 is the dashboard ID in the URL below:
-
Use these commands to export the JSON configuration for your dashboard.
First, set your environment variables, replacing the following values with your values:
- DASH_ID with the dashboard ID copied from step #2
- PROJECT_ID with your project id that contains the dashboard
- FILE_NAME with the output filename for the dashboard JSON config
export DASH_ID=<YOUR_DASH_ID> export PROJECT_ID=<PROJECT_ID> export FILE_NAME=<DASH_FILE_NAME>
-
Use the gcloud command line to export the dashboard to a JSON file.
scripts/dashboard/dashboard.sh export $DASH_ID $PROJECT_ID $FILE_NAME
Please add a screenshot with your dashboard. All screenshots should live in the same directory as the sample dashboard specification.
If there is only a single screenshot, the name should match the dashboard specification but with a PNG extension. For example:
cloudrun-monitoring.json
cloudrun-monitoring.png
If there are multiple screenshots, a two digit number should be added between the name and file extension. For example:
gke-cluster-monitoring.json
gke-cluster-monitoring.01.png
gke-cluster-monitoring.02.png
Please also update the README.md file in the same directory of your dashboard file.