Home MonitoringGrafana How To Create a Grafana Dashboard? (UI + API methods)

How To Create a Grafana Dashboard? (UI + API methods)

by schkn

Grafana dashboards are awesome. Whether you are looking to monitor your entire infrastructure, or just your home, everybody benefits from having a complete Grafana dashboard.

In today’s article, we are going to see how we can easily create a Grafana dashboard, what the different panels are and how they can be used efficiently.

Here are the steps to create a Grafana dashboard using the UI:

  • Hover the ‘Plus’ icon located on the left menu with your cursor (it should be the first icon)
  • From there, a dropdown will open. Click on the ‘dashboard’ option.
Create dashboard option in Grafana
Create dashboard option in Grafana
  • A new dashboard will automatically be created with a first panel.
Grafana new panel
Grafana new panel – query & visualization

In Grafana v6.0+, the query and the visualization panels are separated. It means that you can easily write your query, and decide later which visualization you want to use for your dashboard.

This is particularly handy because you don’t have to reset your panel everytime you want to change the visualization types.

  • First, click on ‘Add Query’ and make sure that your datasource is correctly binded to Grafana.
  • Write your query and refactor it until you’re happy with the final result. By default, Grafana sets new panels to “Graph” types.
Grafana query panel
  • Choose the visualization that fits your query the best. You have to choose between ten different visualizations (or more if you have plugins installed!)
Grafana visualization types
  • Tweak your dashboard with display options until you’re satisfied with the visual of your panel.
Grafana display options
Grafana display options
Final dashboard in Grafana

Here are the steps to create a Grafana dashboard using the API:

Most of the API requests are authenticated within Grafana. In order to call the Grafana API to create a dashboard, you will have to get a token. If you don’t own the Grafana instance, you have to ask your administrator a token.

  • Hover the ‘Configuration’ icon in the left menu and click on the “API Keys” option.
Configuration menu in Grafana
  • Click on “Add API Key”. Enter a key name and at least an “Editor” role to the key.
  • Click on “Add”
Add API Key
  • A popup page will open and show you the token you will be using in the future. It is very important that you copy it immediately. You won’t be able to see it after closing the window.
API key created in Grafana
  • Now that you have your API key, you need to make a call to the /api/dashboards/db endpoint using the token in the authorization header of your HTTP request.

For this example, I will be using Postman.

  • Create a new POST request in Postman, and type http://localhost:3000/api/dashboards/db as the target URL.
  • In the authorization panel, select the ‘Bearer token’ type and paste the token you got from the UI.
  • In the body of your request, select “Raw” then “JSON (application/json)”. Paste the following JSON to create your dashboard.
{
  "dashboard": {
    "id": null,
    "uid": null,
    "title": "Production Overview",
    "tags": [ "templated" ],
    "timezone": "browser",
    "schemaVersion": 16,
    "version": 0
  },
  "folderId": 0,
  "overwrite": false
}

Here’s the description of every field in the request:

  • dashboard.id : the dashboard ID, should be set to null on dashboard creation.
  • dashboard.uid : the dashboard unique identifier, should be set to null on dashboard creation.
  • title : the title of your dashboard.
  • tags : dashboard can be assigned tags in order to retrieve them quicker in the future.
  • timezone : the timezone for your dashboard, should be set to browser on dashboard creation.
  • schemaVersion : constant value that should be 16.
  • version : your dashboard version, should be set to zero as it is the first version of your dashboard.
  • folderId : you can choose to set a folder id to your dashboard if you already have existing folders
  • overwrite : you could update an existing dashboard, but it should be set to false in our case as we creating it.
  • Click on “Send”. You choose see the following success message.
{
    "id": 3,
    "slug": "production-overview",
    "status": "success",
    "uid": "uX5vE8nZk",
    "url": "/d/uX5vE8nZk/production-overview",
    "version": 1
}
  • Make sure that your dashboard was created in Grafana.

That’s it! You know have a complete idea of the two ways to create a Grafana dashboard in 2019.

If you have any comments on this content, or if you found that this guide run out of date in the future, make sure to leave a comment below.

Until then, have fun, as always.

You may also like

7 comments

Akshay April 6, 2020 - 11:37 am

I have exported JSON for one dashboard with all the panels and now I want to send that JSON to create the same dashboard in grafana. how can we do this?

Reply
Lokesh October 30, 2020 - 10:47 am

Did you get this ?

Reply
Pranay April 15, 2020 - 1:08 am

You can also do via ‘curl’ (for example)

curl –header “Content-Type: application/json” \
–request POST \
–data ‘{
“dashboard”: {
“id”: null,
“uid”: null,
“title”: “Production Overview”,
“tags”: [ “templated” ],
“timezone”: “browser”,
“schemaVersion”: 16,
“version”: 0
},
“folderId”: 0,
“overwrite”: false
}’ \
http://admin:admin@:30300/api/dashboards/db

Reply
schkn April 15, 2020 - 5:12 pm

Awesome, thank you for the tips!

Reply
prachi May 13, 2020 - 12:05 pm

I am also trying similar way but for every POST/DELETE call I am getting 403 Forbidden in Postman. I am able to see all GET methods response. I am not sure what is happening or do I need to change any configuration. Please let me know.

Reply
Sai Hemanth June 22, 2021 - 9:46 am

We are using iframe to embed dashboards in our UI(Website). Instead of using iframe how can we load grafana dashboards using API and also how can we embed it in our website.is there any other alternatives to embed dashboards in our UI page instead of iframe.

Reply
Seb July 29, 2021 - 12:35 pm

I have the same problem. Does anyone have a solution to implement the grafana GUI in you own mobile application without an iFrame but via the Grafana API? Does Grafana support such an API dashboard implementation?

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.