Docker Cookbook


| Chapter 9: Monitoring Containers



Download 6,31 Mb.
Pdf ko'rish
bet216/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   212   213   214   215   216   217   218   219   ...   260
Bog'liq
Docker Cookbook

276 | Chapter 9: Monitoring Containers


Restart your Docker daemon with 
sudo service docker restart
. You are now
ready to use 
curl
 and target the Docker remote API. The 
syntax
 is again simple: it is
an HTTP GET request to the 
/containers/(id)/stats
URI. Try it like so:
$ $ docker -H tcp://127.0.0.1:2375 run -d -p 5001:5000 runseb/flask
$ curl http://127.0.0.1:2375/containers/agitated_albattani/stats
{"read":"2015-04-01T11:48:40.609469913Z",\
"network":{"rx_bytes":648,"rx_packets":8,"...
Do not forget to replace 
agitated_albattani
with the name of your container. You
will start receiving a stream of statistics that you can interrupt with Ctrl-C. For practi‐
cal purposes, I truncated most of the results from the previous command. This is
handy for trying things out, but if (like me) you like Python, you might want to
access these statistics from a Python program. To do this, you can use 
docker-py
(see
Recipe 4.10
). A Python script like the one here will put you on the right track:
#!/usr/bin/env python
import
json
import
docker
import
sys
cli
=
docker
.
Client
(
base_url
=
'tcp://127.0.0.1:2375'
)
stats
=
cli
.
stats
(
sys
.
argv
[
1
])
print
json
.
dumps
(
json
.
loads
(
next
(
stats
)
.
rstrip
(
'\n'
)),
indent
=
4
)
The 
stats
object in this Python script is a 
generator
, which yields
results instead of the standard return behavior of functions. It is
used to capture the statistics stream and pick up where it left off.
next(stats)
in the script is the way to yield the latest result from
the stream.
See Also
• Original GitHub 
pull request
 for 
stats
• API 
documentation

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   212   213   214   215   216   217   218   219   ...   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