Preload grafana dashbaord with docker-compose setup

I personally felt it a little frustrating to import a dashboard everytime when i run k6 tests locally and use grafana for result visualisation using docker-compose setup as specified here. And i was not able to find tutorial to preload dashboards and datasources.

So, why not write a tutorial here in the community lounge and here is the tutorial on how one can preload a grafana dashboard when one runs the test locally using docker-compose setup.

The first step would creating yml files for dashboard and datasources with the options.

dashboard.yml and dashboard.json under dashboards folder and
datasource.yml under the datasources folder.

Note here that the datasource in dashboard.json has to be updated with the name of the datasource mentioned in datasource.yml file. In this case, it is myinfluxdb.

Refer the files here.

The next step for it would be mounting / copying the configurations for datasources and dashboards into the folder etc/grafana/provisioning/ inside grafana container that is started using
docker-compose up -d grafana influxdb

Refer the updated docker-compose file here

Start the containers for influxdb and grafana using
docker-compose up -d grafana influxdb

Open http://localhost:3000/ in a browser and Hurra!

One could see that datasource and dashboard has been preloaded and visible under recently viewed dashboards.


Now it just to run your tests with docker-compose run k6 run /scripts/es6sample.js and visualize the results.!



@jeevananthank, this looks much better indeed! Do you want to make a PR to k6 with your changes?

@ned created a PR

1 Like