Welcome to Part 2 of my series on setting up Monitoring for your Infrastructure using Grafana and InfluxDB.

Last week as well as the series Introduction, we started our Monitoring build with Part 1, which was creating our Ubuntu Server to serve as a host for our Docker Images. Onwards we now go to Part 2, where the fun really starts and we pull our images for Grafana and InfluxDB from Docker Hub, create persistent storage and get them running.

Firstly, lets get Grafana running!

  • That’s created, but where is it located? Run this command to find out: “sudo find / -type d -name “grafana-storage
  • This tells us where the file location is (in this case, the location as we can see above is:

var/snap/docker/common/var-lib-docker/volumes/grafana-storage

  • Now, we need to download the Grafana image from the docker hub. Run “sudo docker search grafana” to search for a list of Grafana images:
  • As we can see, there are a number of images available but we want to use the official one at the top of the list. So we run “sudo docker pull grafana/grafana” to pull the image:
  • This will take a few seconds to pull down. We run the “sudo docker images” command to confirm the image has downloaded:
  • Now the image is downloaded and we have our storage volume ready to persist our data. Its time to get our image running. Lets run this command:

sudo docker run -d -p 3000:3000 — name=grafana -v grafana-storage:var/snap/docker/common/var-lib-docker/volumes/grafana-storage grafana/grafana”

  • Wow, that's a mouthful ….. lets explain what the command is doing. We use “docker run -d” to start the container in the background. We then use the “-p 3000:3000” to make the container available on port 3000 via the IP Address of the Ubuntu Host. We then use “-v” to point at our persistent storage location that we created, and finally we use “grafana/grafana” to specify the image we want to use.
  • The IP of my Ubuntu Server is 10.210.239.186. Lets see if we can browse to 10.210.239.186:3000 …..
  • Well hello there beautiful ….. the default username/password is admin/admin, and you will be prompted to change this at first login to something more secure.

Now we need a Data Source!

  • As you can see, InfluxDB is the most commonly used, so we’re going to use that. But what is this “InfluxDB” that I speak of.
  • InfluxDB is a “time series database”. The good people over at InfluxDB explain it a lot better than I will, but in summary a time series database is optimized for time-stamped data that can be tracked, monitored and sampled over time.
  • I’m going to keep using docker for hosting all elements of our monitoring solution. Lets search for the InfluxDB image on the Docker Hub by running “sudo docker search influx”:
  • Again, I’m going to use the official one, so run the “sudo docker pull influxdb:1.8” command to pull the image. Note that I’m pulling the InfluxDB image with tag 1.8. Versions after 1.8 use a new DB Model which is not yet widely used:
  • And to confirm, lets run “sudo docker images”:
  • At this point, I’m ready to run the image. But first, lets create another persistent storage area on the host for the InfluxDB image, just like I did for the Grafana one. So we run “sudo docker volume create influx18-storage”:
  • Again, lets run the command to find it and get the exact location:
  • And this is what we need for our command to launch the container:

sudo docker run -d -p 8086:8086 — name=influxdb -v influx18-storage:var/snap/docker/common/var-lib-docker/volumes/influx18-storage influxdb:1.8”

  • We’re running InfluxDB on port 8086 as this is its default. So now, lets check our 2 containers are running by running “sudo docker ps”:
  • OK great, so we have our 2 containers running. Now, we need to interact with the InfluxDB Container to create our database. So we run “sudo docker exec -it 99ce /bin/bash”:
  • This gives us an interactive session (docker exec -it) with the container (we’ve used the container ID “99ce” from above to identify it) so we can configure it. Finally, we’ve asked for a bash session (/bin/bash) to run commands from. So now, lets create our database and set authentication. We run “influx” and setup our database and user authentication:

Next time….

Cloud and Devops Enthusiast with a passion for learning and helping others. Azure, MCSE, Juniper Certified.