Using Gnocchi with Docker

Thursday 17 August 2017 Docker, Gnocchi Comments

I've recently started to look into Docker to build images ready to be used with Gnocchi in it. I found it would be a great way to distribute a working instance of Gnocchi.

To this end, we created the gnocchi-docker repository on GitHub. It contains:

  • a 11 lines long (only!) Dockerfile to build a Linux image containing Gnocchi;
  • a Dockerfile to create a Grafana image that will use Gnocchi as datasource (preconfigured);
  • a Dockerfile to create a collectd image that gather various metrics for your container in order to feed Gnocchi and have something to display in Grafana;
  • a docker-compose file that orchestrates and runs those containers.

If you don't know docker-compose, it's a tool to define and run applications using multiple containers. This is very handy in our case, as we need to start a few services, and therefore a few containers, to have our whole stack running.

If you just want to use and run Gnocchi in a snap using this, it's easy. First clone the repository:

$ git clone https://github.com/gnocchixyz/gnocchi-docker.git


Then, just ask docker-compose to start your stack of containers:

$ cd gnocchi-docker
$ docker-compose up


On the first run, docker-compose will build the various images (this should take only a few minutes) and then will start them.

Once everything is started, you can connect to Grafana by typing the URL http://<ip of your docker server>:3000 in your browser and using "admin" as username and "password" as password. Just click on the dashboard entitled "Gnocchi" and wait a few minutes: you will see the chart being drawn in real time!

Grafana dashboard with Gnocchi as backend

The data fed into Gnocchi come from the collectd container, which gathers various metrics (CPU, network interface statistics, etc).

You can then edit the docker files as you like to add new features or test your code. The files are also a good basis if you want to deploy Gnocchi in production running Docker!

If you want to access and play with Gnocchi in command line, just install gnocchiclient and do the following:

$ export GNOCCHI_ENDPOINT=http://`docker-machine ip`:8041
$ gnocchi resource list
+----------+----------+------------+---------+----------------------+------------+----------+----------------+--------------+---------+
| id | type | project_id | user_id | original_resource_id | started_at | ended_at | revision_start | revision_end | creator |
+----------+----------+------------+---------+----------------------+------------+----------+----------------+--------------+---------+
| c31e4adc | collectd | None | None | collectd:fake-phy- | 2017-08-17 | None | 2017-08-17T12: | None | admin |
| -2cff-5f | | | | host-719acbad336c | T12:20:27. | | 20:27.643790+0 | | |
| 78-8206- | | | | | 643778+00: | | 0:00 | | |
| f5ca66e4 | | | | | 00 | | | | |
| 6cce | | | | | | | | | |
+----------+----------+------------+---------+----------------------+------------+----------+----------------+--------------+---------+


You can now have fun creating new resources and metrics!

Feel free to contribute patches to the GitHub project too, obviously!