Provisioning Datasources - Selecting Flux Query Language

Two days of sweat and finally solved ! This solution is not only for flux in Influxdb but also for any datasource that you struggle to configure manually in a datasources file but can easily do it through the web interface.

1. Solution for using flux (not influxql) by provisioning a datasources file (good for docker)

apiVersion: 1
datasources:
- orgId: 1
  version: 2
  name: InfluxDB
  type: influxdb
  access: proxy
  url: https://eu-central-1-1.aws.cloud2.influxdata.com/api/v2/
  basicAuth: true
  isDefault: true
  jsonData:
    defaultBucket: <my-bucket>
    httpMode: POST
    organization: <my-organization>
    version: Flux
  secureJsonData:
    token: <my-token>

2. To find/create the yaml file for any datasources created in the grafana web interface.

You need admin/sudo access to both the website and the OS.

I used this very useful script with instructions here : GitHub - trivago/hamara: Export datasource from the existing Grafana DB into a YAML provisioning file to extract the datasources from a runnning grafana installation.

These are the instructions for a fresh blank docker linux os (ubuntu 20.04)

# Run a docker container if you don't want to install on a VM or your host machine
docker run -it -p 3000:3000 ubuntu bash

# The default ubuntu docker image when run bash will put you into root
# If you use a normal user or installation, then note that many commands here will need sudo access.

# Install Go and the Hamara program which will extract the datasources from grafana
apt-get -y update
apt-get install -y wget git
wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | tar -xz -C /usr/local
export PATH=$PATH:/usr/local/go/bin
source ~/.profile
go version
go get -u github.com/trivago/hamara

# Install and start Grafana
apt-get install -y apt-transport-https
apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
echo "deb https://packages.grafana.com/enterprise/deb stable main" | tee -a /etc/apt/sources.list.d/grafana.list
apt-get update
apt-get install -y grafana-enterprise 
service grafana-server start
service grafana-server status

# Now go to web interface at http://grafana.staged-by-discourse.com
# and setup all your datasources and test them
# And create an API token with admin privileges

# Now export all the datasources into a local file
export GRAFANA_API_KEY=<your token>
hamara export --host=community.grafana.com --key=$GRAFANA_API_KEY > datasources.yaml
./go/bin/hamara export --host=community.grafana.com --key=$GRAFANA_API_KEY > datasources.yaml

# Now read and copy all datasources
cat datasources.yaml
2 Likes