Your application is now deployed. Head over to the Beanstalk console (shown in
Figure 8-12
) and you will find the URL of the application.
Click the URL and it will
open the
2048 game
. This is fronted by an elastic load-balancer, which means that
increased load on the game will trigger the creation of additional instances serving
the game behind the load-balancer.
Figure 8-12. AWS Beanstalk console
Discussion
In the preceding example, our application is encapsulated in a single Dockerfile with
no additional dependencies.
272 | Chapter 8: Docker in the Cloud
CHAPTER 9
Monitoring Containers
9.0 Introduction
When operating distributed systems and distributed applications, you need access to
as much information as possible. You will never need to monitor a large number of
resources, extract trends, and trigger alerts. You will also need
to collect logs from all
processes running in containers and aggregate those logs in data stores for further
indexing and searching. Finally, you will need to visualize all this information to
quickly navigate your application and debug it if need be.
This chapter starts with some Docker commands that give you basic debugging tools
that you can use in small-scale deployments or when you have to dive deeper into a
specific container.
Recipe 9.1
introduces the
docker inspect
method that gives you
all the information about a container of an image.
Recipe 9.2
shows you how to use
docker stats
to get a stream of resource usage for a specific container. Finally,
Recipe 9.3
presents
docker
events
, which listens to Docker events on a particular
host. These capabilities are available through the Docker API and hence can be used
through any Docker client that supports them.
As you build your application you will want to collect the logs of your services run‐
ning in containers. This is not specifically monitoring, but logs can be used to derive
new metrics that you need to monitor. Docker provides a simple mechanism to look
at
stdout
of the foreground process running in a container,
Recipe 9.4
. You can also
redirect those logs to a remote syslog server of another
log aggregation system like
Fluentd, which we show in
Recipe 9.5
. Prior to the log driver feature, a container was
made famous for solving the logging challenge in Docker,
logspout
. In
Recipe 9.6
we
show you how
logspout
works. While it does not need to be used anymore it is still
an interesting system worth your time. To wrap up this
section we show you how to
deploy an ELK stack using containers in
Recipe 9.8
. ELK stands for Elastic, Logstash,
273
and Kibana. Logstash is a log aggregator system that can feed data to Elastic. Elastic is
a distributed data store that provides efficient indexing and searching capability.
Kibana is a dashboard system to visualize data stored in Elastic. If you want an alter‐
native to ELK you might like
Recipe 9.11
, which lays the foundation for using
InfluxDB
as
a data store and
Grafana
as a dashboard.
While
docker stats
gives you single-container usage statistics, you might want to
collect these metrics for multiple containers and aggregate them.
Recipe 9.9
is an
advanced recipe that brings together multiple concepts. It features a two-hosts setup.
One host runs an ELK stack, and the other host runs
logspout
and
collectd
, which is
the system statistics collection daemon. What this recipe shows is that the resource
usage of all containers started on the second
host will be collected by
collectd
via the
docker stats
API and further aggregated by
logspout
, which will send the data to
the ELK setup. Certainly worth your time if you need to bring up your own monitor‐
ing solution. While this setup works perfectly,
Recipe 9.10
introduces cAdvisor, a
containerized solution to container monitoring. You can deploy cAdvisor on all your
Docker hosts and it will monitor all the rescue usage of all the containers running on
your hosts.
We finish this chapter with
a look at Weave Scope in
Recipe 9.12
. This is a container
infrastructure visualization tool. If you imagine thousands of containers composing
your complete applications, having an interactive explorer for a distributed applica‐
tion is very appealing. Weave Scope has the potential to fulfill that promise and give
you quick insight into your application.
Do'stlaringiz bilan baham: