Getting Started with Prometheus – Part 2

As you’ve probably guessed by Docker posts, I’m a huge fan of containerisation. Therefore instead of installing Prometheus on a host, let’s instead spin it up in a container. As described on the Prometheus website, we can accomplish this by issuing only a single command:

Let’s break down each component of this command to make sure we fully understand what it is doing:

  • docker run: Spin up a container
  • -p 9090:9090: Bind a port on our Docker host to a container port. This enables devices outside of the Docker host to reach the container on port 9090
  • -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml: Binds the /tmp/prometheus.yml file stored on the Docker host to  /etc/prometheus/prometheus.yml inside of the container
  • prom/prometheus: The <user_account>/<container_name> that we want to use

Before we move on, it’s important to note that the binding mentioned in the third port above is not a copy and paste of the file, but rather a symbolic link. That is to say, only a single copy of the file exists. Further to this, both the Docker host and the container can edit it.

Now, if we try to issue the command as is, we’ll receive the following error message:

That’s because, as per the error message, we don’t actually have a prometheus.yml file yet. Let’s go ahead and grab this one, which is pasted below for convenience:

You might notice something quite interesting here. In the previous post it was mentioned that Scraping is the primary method Prometheus uses to obtains host metrics. In fact, as per the configuration file above, it is the way that Prometheus gathers statistics on itself too!

After copying and pasting this configuration to /tmp/prometheus.yml on our Docker host, we should be good to go. However, instead of using the command provided by the Prometheus website, let’s use this one instead:

These additional options achieve the following:

  • -d: Run as a daemon. This enables us to continue using our CLI session while the container runs in the background
  • --rm: Deletes the container once we stops running. This is useful for when you’re playing around with Docker and/or Prometheus
  • --name: Names the container

To check on our container, we can use the docker logs prom and  docker ps -l commands, like so:

And because Prometheus posts metrics about itself at http://<Prometheus_Address>:9090/metrics , we can browse to this address to see what data it is providing. Below is an excerpt of what you will see:


Now that we’ve got Prometheus up and running, we can start looking at writing Queries. A query, as its name suggests, is simply a database query. Using queries you can obtain an original copy of the data which has been stored, or you can apply functions to it such as aggregations. This flexibility allows you to monitor and graph information which is most important to you.

The Prometheus website covers queries in multiple locations throughout their documentation:

Using these queries, as well as the information Prometheus is collecting about itself, we can head over to http://<Prometheus_Address>:9090/graph and start putting what we’ve learned into action.

Once we’ve gotten the hang of that, we can take things to the next level by graphing our data in Grafana. If you’re not sure how to do that, stay tuned as it will be covered in a post in the near future.

As always, if you have any questions or have a topic that you would like me to discuss, please feel free to post a comment at the bottom of this blog entry, e-mail at, or drop me a message on Twitter (@OzNetNerd).

Note: This website is my personal blog. The opinions expressed in this blog are my own and not those of my employer.