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://grafana.staged-by-discourse.com/ in a browser and Hurra!

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

image

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

Cheers!

6 Likes

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

@ned created a PR

1 Like

Hello! First of all thanks, this tutorial help-me a lot!
But i got a problem.
I followed step by step and now can execute tests using docker-compose run k6 run but in my case, all times that i run k6 tests via docker-compose, the docker create a new container instead start an old one.
I was try create a containers using docker-compose up -d grafana influxdb k6 instead docker-compose up -d grafana influxdb but when i run a new one is created.

docker-k6

Do you have any ideas?

1 Like

Hmm from docker compose up | Docker Docs, it seems like the --no-recreate might help you

If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation, docker-compose up picks up the changes by stopping and recreating the containers (preserving mounted volumes). To prevent Compose from picking up changes, use the --no-recreate flag.

That said, if you just want to avoid clutter, you might also just use docker run --rm to clean up the containers after they finish running?

3 Likes

Thanks! Solved my problem.
I read docker/compose docs but i overlook

really useful …thanks

1 Like

This was incredibly helpful, thanks!

1 Like