In Grafana, How to setup datasource and load templates from cli?

1.7k Views Asked by At

I am using grafana in Ubuntu. I want to automate two things.

1. Setting up Datasource.
2. Load json template to dashboard.

Rather than GUI is there any option available like CLI ?

2

There are 2 best solutions below

0
On

Yes you can automate such things with the Grafana HTTP API.

Taken from the docs you can for example create a new datasource with:

POST /api/datasources HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
  "name":"test_datasource",
  "type":"graphite",
  "url":"http://mydatasource.com",
  "access":"proxy",
  "basicAuth":false
}

I use python to automate such things with grafana since its straight forward. But you can use any language that can do http requests.

0
On

Or you can use wizzy to automate Grafana entities with two commands:

wizzy export datasource <datasource_name>
wizzy insert temp-var <temp-var-name>

Here are the links for getting starting with wizzy:

https://github.com/utkarshcmu/wizzy

https://utkarshcmu.github.io/wizzy-site/home/getting-started/#installation