Grafana Dashboards for Cloud

Grafana dashboards

Grafana Cloud provisions and maintains a hosted Grafana instance from which you can visualize your metrics and logs data using dashboards.

To learn how to import a Grafana dashboard, please see Export and Import from the Grafana docs. Monitoring a Linux host using Prometheus and node_exporter also contains a Dashboard import example.

You can find the complete documentation for Grafana Dashboards in the Dashboards section of the Grafana docs.

You can find hosted Grafana API documentation in the HTTP API Reference section of the Grafana docs. Note that this API differs from the Grafana Cloud API and the API for hosted Prometheus metrics. To learn more about the Prometheus metrics API, please see Cortex documentation. Note that some functionality may differ slightly from documented Cortex features.

Uploading Dashboards to Hosted Grafana using the API

This quick snippet demonstrates how to upload a set of JSON dashboards to your hosted Grafana instance using the Grafana API.

To use the script you will need:

  • bash
  • curl
  • An API key for your hosted Grafana instance. To learn how to create an API key, please see Create API Token from the Grafana docs. Note that you can only create this key from your hosted Grafana instance, not the Grafana Cloud Web Portal.

Be sure to set the appropriate environment variables and directory containing your dashboard JSON files.

#!/bin/bash

set -euo pipefail

export GRAFANA_API_KEY=YOUR_HOSTED_GRAFANA_API_KEY_HERE
export GRAFANA_ENDPOINT=https://YOUR_STACK_NAME.grafana.net

if [ -z $GRAFANA_API_KEY ]; then
  echo "Set GRAFANA_API_KEY"
  exit 1
fi

if [ -z $GRAFANA_ENDPOINT ]; then
  echo "Set GRAFANA_ENDPOINT"
  exit 1
fi

cd DASHBOARD_DIRECTORY_HERE

# Upload to Grafana
for dashboard in *.json
do
  echo "Uploading $dashboard to Grafana"
  echo '{"dashboard": '$(cat $dashboard)', "overwrite": true }' | \
    curl -H "Content-Type: application/json" \
         -H "Authorization: Bearer $GRAFANA_API_KEY" \
         --data-binary @- $GRAFANA_ENDPOINT/api/dashboards/db || exit 1
done

You can also manage dashboards programmatically using the Grafana Terraform Provider.