Dzone - Docker Monitoring
Dzone - Docker Monitoring
Dzone - Docker Monitoring
CONTENTS
236
Overview
The Docker Monitoring Challenge
Architectural Models
Troubleshooting Options
BY A P U RVA DAV
OVERVIEW
Docker started as a tool for developers and test engineers to
simplify software delivery, but it has rapidly evolved into a
production-ready infrastructure platform. It promises to deliver
software more flexibly and more scalably to your end users,
while at the same time making microservices a reality.
As any new platform moves into production, monitoring
becomes an important aspect of its viability. Thats especially
true with a platform like Docker, where its architectural model
actually changes how you need to instrument your systems in
order to monitor it properly.
This Refcard will lay out the basics of the Docker monitoring
challenge, give you hands on experience with basic monitoring
options, and also spell out some more advanced options.
DZONE, INC.
DZONE.COM
To show this lets query the API via curl and ask for all containers
running. For brevity were showing the JSON blob below for just
one container, and prettied up the JSON.
curl --unix-socket /var/run/docker.sock http:/containers/json
| python -m json.tool
{
Command: python bot.py,
Created: 1470960101,
HostConfig: {
NetworkMode: default
},
Id: 8a9973a456b3af0601c 44cf0ec19b35f01355622
b5d5061552f5b84a6a335d25,
Image: sysdig/sysdig-bot,
ImageID: sha256:90d5bbf5afc4
ce73223b5d57a249c5e05451f d4ab2414a799498e333503ffe4a,
Labels: {},
Mounts: [],
Names: [
Lets now put some of this into practice with some common, opensource-based ways of gleaning metrics from Docker.
/sysdig-bot
],
NetworkSettings: {
Networks: {
bridge: {
Aliases: null,
DESCRIPTION
cAdvisor
Google-provided agent
that graphs 1-minute data
from the Docker Stats API.
Time-series
databases
Sysdig
Container-focused Linux
troubleshooting and
monitoring tool.
EndpointID: 253f6015
2b62e4d0a551657895bc84ec2e0e15657d f90d403f09ca6021425227,
Gateway: 172.17.0.1,
GlobalIPv6Address: ,
GlobalIPv6PrefixLen: 0,
IPAMConfig: null,
IPAddress: 172.17.0.2,
IPPrefixLen: 16,
IPv6Gateway: ,
Links: null,
MacAddress: 02:42:ac:11:00:02,
NetworkID:
}
}
},
Ports: [],
D Z ONE, INC.
State: running,
Status: Up 20 hours
},
Now lets apply this API to our monitoring needs. The /stats/
endpoint gives you streaming output of a wide selection of
resource-oriented metrics for your containers. Lets get the
available stats for just one container:
DZONE.COM
If you are looking to historically graph this data, you could also
route data from cAdvisor to numerous time-series datastores
via plugins, described here. Tying an open-source visualization
engine on top of this, like Grafana, will allow you to produce
something like this:
cAdvisor is a simple server that taps the Docker API and provides
one minute of historical data in 1-second increments. Its a useful
way to visualize whats going on at a high level with your Docker
containers on a given host. cAdvisor simply requires one container
per host that youd like to visualize.
D Z ONE, INC.
DZONE.COM
5
which container each process belongs to.
\$ sudo sysdig -pc -c topprocs\_cpu
As you can see, this includes details such as both the external and
the internal PID and the container name.
Keep in mind: -pcwill add container context to many of the
command lines that you use, including the vanilla sysdig output.
By the way, you can do all of these actions live or create a capture
of historical data. Captures are specified by:
\$ sysdig w myfile.scap
Now lets move on to the network, where things get even more
interesting.
We can see network utilization broken up by process:
sudo sysdig -pc -c topprocs\_net
Bytes Process Host\_pid Container\_pid container.
name
--------------------------------------------------------72.06KB haproxy 7385
13 haproxy
56.96KB docker.io 1775 7039 host
44.45KB mysqld 6995 91 mysql
44.45KB mysqld 6995 99 mysql
29.36KB apache2 7893 124 wordpress1
29.36KB apache2 26895 126
wordpress4
29.36KB apache2 26622 131 wordpress2
29.36KB apache2 27935 132 wordpress3
29.36KB apache2 27306 125 wordpress4
22.23KB mysqld 6995 90 mysql
Note how this includes the internal PID and the container name
of the processes that are causing most network activity, which is
useful if we need to attach to the container to fix stuff. We can
also see the top connections on this machine:
sudo sysdig -pc -c topconns
Bytes container.name Proto Conn
What if we want to zoom into a single container and only see the
processes running inside it? Its just a matter of using the same
topprocs_cpuchisel, but this time with a filter:
\$ sudo sysdig -pc -c topprocs\_cpu container.name=client
CPU% Process container.name
----------------------------------------------
172.17.0.2:3306
So to recap, we can:
This command line shows the top files in terms of file I/O, and
tells you which container they belong to:
\$ sudo sysdig -pc -c topfiles\_bytes
Bytes container.name Filename
----------------------------------------------------------63.21KB mysql /tmp/\#sql\_1\_0.MYI
6.50KB client /lib/x86\_64-linux-gnu/libc.so.6
3.25KB client /lib/x86\_64-linux-gnu/libpthread.so.0
3.25KB client /lib/x86\_64-linux-gnu/libgcrypt.so.11
3.25KB client /usr/lib/x86\_64-linux-gnu/libwind.so.0
3.25KB client
/usr/lib/x86\_64-linux-gnu/libgssapi\_
krb5.so.2
3.25KB client /usr/lib/x86\_64-linux-gnu/liblber2.4.so.2
3.25KB client /lib/x86\_64-linux-gnu/libssl.so.1.0.0
3.25KB client /usr/lib/x86\_64-linux-gnu/libheimbase.
so.1
3.25KB client /lib/x86\_64-linux-gnu/libcrypt.so.1
Naturally there is a lot more you can do with a tool like this, but
that should be a sufficient start to put our knowledge to work in
some real-life examples.
Firstis using 2 times the Host CPU than the others because it
has 2 times the shares. All of them are using 100% of CPU shares
assigned. But what happens if Thirddoes not need any CPU at all?
D Z O NE, INC .
DZ O NE .C O M
One linethats it. In this case were showing the average network
data across all three containers, but you could easily calculate
anything that helps you better understand the performance of this
collection of containers.
But lets go a little further with labels, network data, and the top
connections example we showed in the open-source section.
Now instead of giving CPU to other containers, the kernel is
enforcing the absolute quota given. The total CPU usage we will see
they are communicating with. Here we can see the aggregated java
map of our services, the containers that make them up, and who
Regardless of your platform, some things dont change and
(in a more complete view) would show all the other services in
that this is a little more advanced than the other examples, and
D Z O NE, INC .
DZ O NE .C O M
Mongo service and a Redis service, and presumably those are made
CONCLUSION
In this Refcard, weve walked from first principles using the
Docker Stats API all the way up to more complex analysis of our
systems performance. Weve used data sources such as cAdvisor
and sysdig to analyze real-world use cases such as greedy
containers or mapping network communication.
Here we see a few different things: our javaapp consists of three
containers (blue) and a service called javapp (grey), which is just
an abstraction created by whoever is routing requests to those
containers. We see each of those containers communicating with a
As you can see, Docker monitoring can start very simply but grow
complex as you actually take containers into production. Get
experience early and then grow your monitoring sophistication to
what your environment requires.
RESOURCES
JOIN NOW
DZONE, INC.
150 PRESTON EXECUTIVE DR.
CARY, NC 27513
DZone communities deliver over 6 million pages each month to more than 3.3 million software
888.678.0399
developers, architects and decision makers. DZone offers something for everyone, including
919.678.0300
news, tutorials, cheat sheets, research guides, feature articles, source code and more.
Copyright 2016 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
SPONSORSHIP OPPORTUNITIES
[email protected]