Data Source on Startup

In grafana v5+ you can use the provisioning method described here: http://docs.grafana.org/administration/provisioning/

An example using docker-compose.yml can look like this:

grafana:
  image: grafana/grafana:latest
  ports:
    - "3000:3000"
  volumes:
    - ./provisioning:/etc/grafana/provisioning

inside the provisioning directory:

provisioning/datasources/automatic.yml

apiVersion: 1

deleteDatasources:
  - name: MYINFLUX
    orgId: 1

datasources:
- name: MYINFLUXDB
  type: influxdb
  access: proxy
  url: https://myinfluxdb
  password:
  user:
  database: MYINFLUXDB
  basicAuth: false
  basicAuthUser:
  basicAuthPassword:
  withCredentials:
  isDefault: true
  jsonData:
     tlsAuth: false
     tlsAuthWithCACert: false
  secureJsonData:
    tlsCACert: ""
    tlsClientCert: ""
    tlsClientKey: ""
  version: 1
  editable: true

It’s easiest to login as admin, setup the datasource, then issue a GET /api/datasources the API to get the config, and then edit it as yaml, then drop into the provisioning/datasources directory, like this (using admin/admin username/pass):

curl -X GET
http://grafana.staged-by-discourse.com/api/datasources
-H ‘Authorization: Basic YWRtaW46YWRtaW4=’

You can also pre-create dashboards using the same method.

Hope this helps.

4 Likes