Join Arun Gupta for an in-depth discussion in this video Monitor Docker with Prometheus, part of Docker for Java Developers.
- [Instructor] In the previous section we looked at what monitoring tools are available as part of Docker CLI. We looked at Docker stats, we looked at Docker remote API, we looked at Docker system events, and this one we're going to look at two additional tools that are available to you. Well, first is Prometheus which is built into Docker 113, and then we'll also look at C Advisor on what capabilities does it offer for us to monitor Docker containers. Let's get hands-on. Let's clean up our screen here.
Let's take a look at the container that are running right now. Well, there is one container running, and once again, we can clean it up, just to make sure nothing is running here, and we are good to go. Okay, so for this particular exercise I will be referring to my exercise notes, which you'll have access to anyway. Let me copy this JSON fragment here. Now, the support for Prometheus endpoint is available as per of Docker 113 as an experimental build. Now, I'm running Docker for Mac, so let's see how we can enable that support here.
Here is my Docker icon up on the status bar. Go to Preferences. Now we are in the Advanced tab, and I'm going to change this setting here. All I'm specifying is there is a metrics address endpointers, all network interfaces on this host at port 1337, and experimental true is important because this is only an experimental support at this point of time. So, let's restart the Docker engine. And you can see how the containers are dancing around here.
It takes a few seconds for the Docker engine to get up and running, and this is indicated by Docker is running over here. So, let's go back to our terminal. See what we can do over there now. First thing we're going to do here is let's do a curl, and we're going to do a curl on http://localhost:1337. This is the same port that we defined where our metrics endpoint is going to be available. And the metrics endpoint is /metrics. As you would expect, very intuitive. There are lots of metrics that are available to you by default that are pushed by this Prometheus endpoint.
I can call it again and grab for engine. So, these are different engine endpoints that are available to you as well. So, that's the first thing that you want to understand over here that there are several metrics that are available to you. Now, let's run a node exporter, which will scrape those metrics, and show this to me in a nice graph. So, we are in the couchbase directory. We're going to go a level up. We going to make a new directory by the name prom, short for Prometheus basically.
And here first of all I'm going to go to the directory. I'm going to create a file by the name prometheus.yml, and the content for these are going to come from my exercise notes. We'll copy this here, and insert the content in here and paste it here. Well, what we're doing over here is we are defining the scrape config, saying scrape itself every five seconds. The job name is Prometheus, scrape interval is five seconds, and in terms of the target, this is localhost:9090.
9090 is because that's where we will run the Prometheus container. So, let's get out of it here, and now what I want to do is I want to run my Prometheus container. So, docker container run in a detached mode, give this container a name, call it metrics, and do the port forwarding, and then we're going to do a volume mapping in this case, and in our case, we just going to say pwd, and we know where it picks it up from.
Well, pwd/prometheus.yml, and then we're going to map it to etc/prometheus/prometheus.yml. So, that's the configuration file that the Prometheus container is looking for. And finally, the image name. Okay? So, this will start up the Prometheus container for us. Let's give it a shot. It cannot find the Prometheus image, so it's going to download it.
Okay. This is ready now, so let's go to our browser, and in my browser, I can look at my Prometheus dashboard at localhost:9090. Here is my Prometheus dashboard. Let's take a look at the metrics that are available to me. Everything that was available to me on the command line is now available here as well. So, you can go through the entire set of metrics over here. The one that we're going to particularly look at it is http_request_duration_microseconds.
So, if I take a look at this one here, it says there is no data here. Let's look at some other metric here. We can look at microseconds count, or we can look at microsecond sum. Well, you got to be running a container, and then it'll start monitoring those containers and it'll start running some data over here. So remember, the important part to understand is this is still in a very, very early phase, but the fact that you have these metrics available you can start playing around with them.
If the metrics were available and the values were legitimate, then you can start showing these values in a graph as well. And as you can see here, it's a very nice colorful legend that is available to you. And if I can turn down the window in which the metrics need to be displayed, so there are some real numbers that are being displayed over here, and what's the real legend over here? That legend is explained over here. So, a basic support for container metrics, engine metrics that is available as part of Prometheus as a future version of Docker is released this metrics will be a lot more comprehensive, so stay tuned on that.
Now, that's what is available in Prometheus today. Let's take a look at what happens with C Advisor. Well, C Advisor is open source project by Google. C Advisor means Container Advisor and it gives you some metrics on container. So, let's rend that container next and show what kind of dashboard that provides us. We'll go here. We will remove our container for Prometheus here, so that removes the metrics container. That's it.
Arun Gupta explains how to run containers and build images, as well as how to deploy multi-container applications on multiple hosts. Arun also covers Docker clustering, demonstrates how to run stateful containers, shares strategies on how to persist the state of stateful containers, and goes into monitoring Docker containers.
- Getting started with Docker
- Running your first Docker container
- Creating your first Docker image
- Copying files in a Docker image
- Running JAR files from a Docker image
- Working with Docker Compose
- Creating a multi-node swarm mode cluster using Docker Machine
- Deploying services to swarm mode
- Creating a multi-node swarm mode cluster on AWS
- Creating a database cluster using Docker Service
- Monitoring Docker with Prometheus
- Monitoring Docker with cAdvisor