Docker Cookbook


| Chapter 9: Monitoring Containers



Download 6,31 Mb.
Pdf ko'rish
bet229/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   225   226   227   228   229   230   231   232   ...   260
Bog'liq
Docker Cookbook

292 | Chapter 9: Monitoring Containers


all the running containers, and obtains the statistics for them. For the stats called
cpu_stats
, it writes a 
PUTVAL
string to 
stdout
. This string is understood by Collectd
and sent to the Graphite data store (a.k.a Carbon) for storage and visualization. The
PUTVAL
string follows the Collectd 
exec
plug-in syntax:
#!/usr/bin/env python
import
random
import
json
import
docker
import
sys
cli
=
docker
.
Client
(
base_url
=
'unix://var/run/docker.sock'
)
types
=
[
"gauge-cpu0"
]
for
h
in
cli
.
containers
():
if
not
h
[
"Status"
]
.
startswith
(
"Up"
):
continue
stats
=
json
.
loads
(
cli
.
stats
(
h
[
"Id"
])
.
next
())
for
k
,
v
in
stats
.
items
():
if
k
==
"cpu_stats"
:
print
(
"PUTVAL 
%s
/
%s
/
%s
N:
%s
"
%
(
h
[
'Names'
][
0
]
.
lstrip
(
'/'
),
\
'docker-cpu'
,
types
[
0
],
\
v
[
'cpu_usage'
][
'total_usage'
]))
The example plug-in in this recipe is minimal, and the statistics
need to be processed further. You might want to consider using 
this
Python-based plug-in instead.
See Also
• Collectd 
website
• Collectd Exec 
plug-in
• Graphite 
website
• Logstash 
website
• Collectd Docker 
plug-in
9.9 Using Collectd to Visualize Container Metrics | 293


9.10 Using cAdvisor to Monitor Resource Usage
in Containers
Problem
Although Logspout (see 
Recipe 9.6
) allows you to stream application logs to remote
endpoints, you need a resource utilization monitoring system.
Solution
Use 
cAdvisor
, created by Google to monitor resource usage and performance of its
lcmtfy
containers. cAdvisor runs as a container on your Docker hosts. By mounting
local volumes, it can monitor the performance of all other running containers on that
same host. It provides a local web UI, exposes an 
API
, and can stream data to
InfluxDB
. Streaming data from running containers to a remote InfluxDB cluster
allows you to aggregate performance metrics for all your containers running in a
cluster.
To get started, let’s use a single host. Download the 
cAdvisor
image as well as 
borja/
unixbench
, an image that enables you to simulate a workload inside a container:
$ docker pull google/cadvisor:latest
$ docker pull borja/unixbench
$ docker run -v /var/run:/var/run:rw\
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-p 8080:8080 \
-d \
--name cadvisor \
google/cadvisor:latest
$ docker run -d borja/unixbench
With the two containers running, you can open your browser a:8080">t 
:8080">http://
:8080">:8080
and you will enjoy the cAdvisor UI (see 
Figure 9-4
).
You will be able to browse the running containers and access metrics for each of
them.

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   225   226   227   228   229   230   231   232   ...   260




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish