Import Grafana dashboards into Cloud Monitoring

This document describes how to import dashboard files in the Grafana JSON format into Cloud Monitoring. You can import Grafana dashboards in the following ways:

The import process converts dashboard files in the JSON format used by Grafana into the JSON format used by Cloud Monitoring. A converted dashboard might differ from the original Grafana dashboard. If, for example, a Grafana dashboard uses features that aren't available in Cloud Monitoring dashboards, then those aspects of the Grafana dashboard are not converted. These differences are listed in the results of the import.

You can only import dashboards that use PromQL expressions and Prometheus data sources. Dashboards that use other forms of querying or data sources might not import successfully.

For information about importing Prometheus alerts into Cloud Monitoring, see Migrate alerting rules and receivers from Prometheus.

For general information about managing your imported dashboards, see Create and manage custom dashboards.

Before you begin

Whether you use the Google Cloud console or the importer tool to import your dashboards, you must have sufficient authorization, and you need dashboards to import. When using the importer tool, there are additional prerequisites.

Authorization

To get the permissions that you need to create and modify custom dashboards, ask your administrator to grant you the Monitoring Editor (roles/monitoring.editor) IAM role on your 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.

For more information about roles, see Control access with Identity and Access Management.

Collect the Grafana dashboards to import

To import Grafana dashboards, you must have them stored locally as files in JSON format. You might want to create a directory specifically for these dashboard files.

Import dashboards by using the Google Cloud console

You can import Grafana dashboards into Cloud Monitoring from the Monitoring Dashboards page in the Google Cloud console.

Import Grafana dashboards

To import one or more Grafana dashboards, do the following

  1. In the Google Cloud console, go to the  Dashboards page:

    Go to Dashboards

    If you use the search bar to find this page, then select the result whose subheading is Monitoring.

  2. In the toolbar of the Google Cloud console, select your Google Cloud project. For App Hub configurations, select the App Hub host project or management project.

  3. Click Import Dashboard.

  4. Click Browse to navigate to the directory where you have stored your Grafana dashboards in JSON format, and select the dashboards you want to import.

    Each JSON file is staged after it is selected; the Staged Files pane indicates whether there are any issues in the conversion.

  5. Click  Import. The Import results pane indicates whether or not each dashboard has been successfully imported.

  6. To view a successfully imported dashboard, click  View.

View your imported dashboards

To view your imported dashboards, do the following:

  1. In the Google Cloud console, go to the  Dashboards page:

    Go to Dashboards

    If you use the search bar to find this page, then select the result whose subheading is Monitoring.

  2. In the toolbar of the Google Cloud console, select your Google Cloud project. For App Hub configurations, select the App Hub host project or management project.
  3. Locate the dashboard that you want to view in the list. To filter the list of dashboards, you can do the following:

Add or remove user-defined labels

You can add labels only to custom dashboards, which include dashboards that you import. When a dashboard displays the Add labels to dashboard button, then you can configure which labels are applied to the dashboard.

To add or remove user-defined labels to a dashboard, do the following:

  • In the Google Cloud console, go to the  Dashboards page:

    Go to Dashboards

    If you use the search bar to find this page, then select the result whose subheading is Monitoring.

  • In the list of dashboards, locate the dashboard and then click Add labels to dashboard.
  • Do one of the following:

    To create a label and add it to your dashboard, in the Create a new label section, enter the name of the label in the textbox and then click Create and apply.

  • To configure which labels are added to your dashboard, click Select labels to apply, select the labels, and then click Ok.
  • To save your changes, click Confirm.
  • Import dashboards by using the importer tool

    You can use the importer tool to convert Grafana dashboards and upload them to Cloud Monitoring as a single operation, or you can perform the conversion and upload steps separately. You might choose this approach if you want to edit the converted dashboards before uploading them.

    Additional prerequisites

    Before you can install and run the dashboard importer, you must do the following:

    1. Use an environment that supports Bash shell scripts.
    2. Have or install Git.
    3. Have or install Node.js, version 20.4.1 or newer.
    4. Have or install the Google Cloud CLI. If you already have the gcloud CLI installed, ensure that you have the latest version by running the gcloud components update command.

    Obtain the dashboard importer

    The dashboard importer is stored in the monitoring-dashboard-samples GitHub repository. To obtain and set up the importer, do the following:

    1. Clone the repository:

      git clone https://github.com/GoogleCloudPlatform/monitoring-dashboard-samples
      
    2. Change to the directory for the dashboard importer:

      cd monitoring-dashboard-samples/scripts/dashboard-importer
      
    3. Install the node modules and build the files

      npm install && npm run build
      

    The dashboard importer includes the following scripts:

    When you use the import.sh script, you must specify the location of the Grafana dashboards to convert. The importer creates a directory that contains the converted dashboards and other information. The following sections describe these directories.

    Grafana dashboards to convert

    You can use the dashboard importer to convert one or more dashboards at a time by specifying a path to the dashboards files.

    Converted dashboards and other information

    When the importer runs the first time, it creates a reports subdirectory. Every time you run the importer, you get a new output directory under the reports directory, named by the date and time. The name of the output directory has the following structure:
    reports/YYYY-M-D/HH:MM:SS

    For each invocation of the importer, the output directory contains the following:

    If you have uploaded the dashboards, the report directory also includes an upload_HH:MM:SS.txt file, which includes the URL to which the dashboard was uploaded.

    Import Grafana dashboards

    To convert Grafana dashboards and upload them to Cloud Monitoring, use the import.sh script:

    ./import.sh PATH_TO_DIRECTORY_OR_FILE PROJECT_ID
    

    This script does the following:

    1. Converts dashboards in PATH_TO_DIRECTORY_OR_FILE from the JSON format used by Grafana into the JSON format used by Cloud Monitoring.
    2. Uploads the converted dashboards into your Google Cloud project PROJECT_ID by using the Google Cloud CLI.

      If you have not authenticated to the gcloud CLI, then run the gcloud auth login command before running the import.sh script.

    You can import all the Grafana dashboards in a directory, or you can specify a single dashboard in the directory to import.

    The dashboard importer includes a sample Grafana dashboard as examples/k8s_cluster_example.json. The following command imports that dashboard into the specified project:

    ./import.sh examples/k8s_cluster_example.json PROJECT_ID
    

    When invoked with the PROJECT_ID my-project-test-1, the output resembles the following:

    Converting: Kubernetes Cluster Overview
    ✓ Kubernetes Cluster Overview converted successfully
    
    Conversion of examples/k8s_cluster_example.json complete. Conversion Report located at: reports/2023-9-28/22:14:57/report.json
    
    To upload these dashboard(s) manually, you can run:
    ./upload.sh reports/2023-9-28/22:14:57/ <PROJECT_ID>
    
    Conversion Complete. Proceeding to uploading...
    
    Now running: ./upload.sh reports/2023-9-28/22:14:57/ my-project-test-1
    
    Uploading 1 dashboard(s) from a directory with the following args:
    Directory: reports/2023-9-28/22:14:57/
    Project: my-project-test-1
    
    The following are your dashboards:
    - k8s_cluster_example.json
    

    After the import.sh script has created the output directory and converted the dashboards, but before it uploads the converted dashboards to your project, it prompts you for confirmation. Enter y, and the script uploads the dashboard and prints the URL for the new dashboard:

    Would you like to continue? (y/n) y
    
    ✓ k8s_cluster_example.json successfully uploaded:
    https://console.cloud.google.com/monitoring/dashboards/builder/9c341ef8-cfef-4bdd-98d5-821571c520ef?project=my-project-test-1
    
    Upload log created in reports/2023-9-28/22:14:57/upload_22:14:57.txt
    
    Need to troubleshoot? Please visit:
    https://github.com/GoogleCloudPlatform/monitoring-dashboard-samples/tree/master/scripts/dashboard-importer/README.md#troubleshooting
    

    Convert Grafana dashboards without uploading

    If you want to inspect or edit the converted dashboards before uploading them, then omit the PROJECT_ID value when invoking the import.sh script:

    ./import.sh PATH_TO_DIRECTORY_OR_FILE
    

    The importer converts the dashboards as described in Import Grafana dashboards but does not upload the converted dashboards to Cloud Monitoring.

    You can run the upload step later, by using the upload.sh script manually.

    Upload dashboards manually

    To manually upload dashboards in Cloud Monitoring JSON format, use the upload.sh script.

        ./upload.sh PATH_TO_DIRECTORY_OR_FILE PROJECT_ID
    

    The upload.sh script uses the Google Cloud CLI to upload the JSON files. If you have not authenticated to the gcloud CLI, then run the gcloud auth login command before running the upload.sh script.

    For example, the following command uploads a dashboard stored in a reports subdirectory to the Google Cloud project my-project-test-1:

    ./upload.sh reports/2023-9-26/22:48:31/k8s_cluster_example.json my-project-test-1
    Uploading json file: k8s_cluster_example.json to project: my-project-test-1...
    
    ✓ k8s_cluster_example.json successfully uploaded:
    https://console.cloud.google.com/monitoring/dashboards/builder/25956d9a-93e2-410c-ada1-ec6872cb6665?project=my-project-test-1
    

    View your uploaded dashboards

    To view your uploaded dashboards, do the following:

    1. In the Google Cloud console, go to the  Dashboards page:

      Go to Dashboards

      If you use the search bar to find this page, then select the result whose subheading is Monitoring.

    2. Locate the dashboard that you want to view in the list. To filter the list of dashboards, you can do the following:

    Troubleshooting

    We occasionally publish small updates and bug fixes to the tool. Before attempting further troubleshooting, first try fixing the issue by using git pull to pull down the latest version of the repository and then importing again.

    For information about problems with the converted dashboards, such as charts not showing data, see the importer's README file.

    What's next