尊龙凯时人生就是搏

ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎö

ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎö

¸ÅÊö£º

DockerÊÇÒ»ÖÖÊ¢ÐеÄÈÝÆ÷»¯Æ½Ì¨£¬Í¨¹ý¸ôÀëÓ¦ÓóÌÐòºÍÆäÒÀÀµµÄÈí¼þ°ü£¬Ê¹µÃÓ¦ÓóÌÐò¿ÉÒÔÔÚ×ÔÁ¦µÄÈÝÆ÷ÖÐÔËÐС£È»¶ø£¬Ëæ×ÅÈÝÆ÷ÊýÄ¿µÄÔöÌí£¬¶ÔÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎö±äµÃÔ½À´Ô½Ö÷Òª¡£ÔÚ±¾ÎÄÖУ¬½«ÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎö£¬²¢ÌṩһЩÏêϸµÄ´úÂëʾÀý¡£

ʹÓÃDocker×Ô´øµÄÈÝÆ÷¼à¿Ø¹¤¾ß

DockerÌṩÁËһЩ×Ô´øµÄÈÝÆ÷¼à¿Ø¹¤¾ß£¬¿ÉÒÔÀû±ãµØÉó²éÈÝÆ÷µÄ״̬ºÍÐÔÄÜÖ¸±ê¡£

1.1 Docker StatsÏÂÁî

Docker StatsÏÂÁî¿ÉÒÔÓÃÀ´ÊµÊ±Éó²éÈÝÆ÷µÄ×ÊԴʹÓÃÇéÐΣ¬°üÀ¨CPU¡¢ÄÚ´æ¡¢ÍøÂçºÍ´ÅÅ̵È¡£

ʾÀý´úÂ룺

docker stats [container_name]

µÇ¼ºó¸´ÖÆ

1.2 Docker TopÏÂÁî

Docker TopÏÂÁî¿ÉÒÔÉó²éÈÝÆ÷ÄÚ²¿ÔËÐеÄÀú³ÌºÍ×ÊԴʹÓÃÇéÐΡ£

ʾÀý´úÂ룺

docker top [container_name]

µÇ¼ºó¸´ÖÆ

ʹÓõÚÈý·½¹¤¾ß¾ÙÐÐÈÝÆ÷¼à¿Ø

³ýÁËDocker×Ô´øµÄ¼à¿Ø¹¤¾ß£¬ÉÐÓÐһЩµÚÈý·½¹¤¾ß¿ÉÒÔ¸üÖÜÈ«µØ¼à¿ØºÍÆÊÎöÈÝÆ÷µÄÐÔÄÜ¡£

2.1 cAdvisor

cAdvisorÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷¼à¿Ø¹¤¾ß£¬¿ÉÒÔÌṩÈÝÆ÷µÄ×ÊԴʹÓÃÇéÐκÍÐÔÄÜÖ¸±ê¡£

ʾÀý´úÂ룺

¢Ù ×°ÖÃcAdvisor

docker run -d --name=cadvisor --privileged=true -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock google/cadvisor:latest

µÇ¼ºó¸´ÖÆ

¢Ú Éó²écAdvisorµÄ¼à¿ØÐÅÏ¢

·­¿ªä¯ÀÀÆ÷£¬ÊäÈëhttp://localhost:8080£¬¿ÉÒÔÉó²é¼à¿ØÐÅÏ¢¡£

2.2 Prometheus

PrometheusÊÇÒ»¸ö¿ªÔ´µÄ¼à¿Øϵͳ£¬¿ÉÒÔͨ¹ýÉèÖþÙÐÐÈÝÆ÷¼à¿Ø£¬²¢Ìṩ¿ÉÊÓ»¯µÄ¼à¿ØÃæ°å¡£

ʾÀý´úÂ룺

¢Ù ×°ÖÃPrometheus

git clone https://github.com/prometheus/prometheus.git
cd prometheus
make build

µÇ¼ºó¸´ÖÆ

¢Ú ÉèÖÃPrometheus

ÔÚPrometheusµÄÉèÖÃÎļþprometheus.ymlÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º

scrape_configs:
  - job_name: 'docker'
    metrics_path: '/metrics'
    static_configs:
      - targets: ['<docker_host>:<exporter_port>']

µÇ¼ºó¸´ÖÆ

¢Û Æô¶¯Prometheus

./prometheus --config.file=prometheus.yml

µÇ¼ºó¸´ÖÆ

¢Ü Éó²éPrometheusµÄ¼à¿ØÃæ°å

·­¿ªä¯ÀÀÆ÷£¬ÊäÈëhttp://localhost:9090£¬¿ÉÒÔÉó²é¼à¿ØÃæ°å¡£

ÈÝÆ÷ÐÔÄÜÆÊÎö

³ýÁ˼à¿ØÈÝÆ÷µÄ״̬ºÍÐÔÄÜÖ¸±ê£¬»¹¿ÉÒÔ¶ÔÈÝÆ÷¾ÙÐÐÐÔÄÜÆÊÎö£¬ÒÔÕÒ³öÐÔÄÜÆ¿¾±ºÍ¾ÙÐÐÓÅ»¯¡£

3.1 ʹÓÃDockerµÄstats API»ñÈ¡ÈÝÆ÷µÄÐÔÄÜÖ¸±ê

DockerÌṩÁËstats API£¬¿ÉÒÔ»ñÈ¡ÈÝÆ÷µÄÐÔÄÜÖ¸±ê¡£

ʾÀý´úÂ룺

import docker

client = docker.from_env()
container = client.containers.get('container_id')

stats = container.stats(stream=False)
print(stats)

µÇ¼ºó¸´ÖÆ

3.2 ʹÓÃFlameGraph¾ÙÐÐÈÝÆ÷µÄÐÔÄÜÆÊÎö

FlameGraphÊÇÒ»¸ö¿ªÔ´µÄÐÔÄÜÆÊÎö¹¤¾ß£¬¿ÉÒÔƾ֤CPUʹÓÃÇéÐÎÌìÉú»ðÑæͼ£¬×ÊÖú¶¨Î»ÐÔÄÜÎÊÌâ¡£

ʾÀý´úÂ룺

¢Ù ×°ÖÃFlameGraph

git clone https://github.com/brendangregg/FlameGraph.git

µÇ¼ºó¸´ÖÆ

¢Ú Ö´ÐÐÐÔÄÜÆÊÎö

docker run -d --name=performance_container <image>
docker cp ./FlameGraph/perf-map-agent/build/lib/linux-x64/libperfmap.so performance_container:/tmp/libperfmap.so
docker exec -it performance_container /bin/bash
cd /tmp
perf record -F 99 -e cpu-clock -g -- /usr/bin/java -agentpath:/tmp/libperfmap.so ...
perf script | stackcollapse-perf.pl | flamegraph.pl > flamegraph.svg

µÇ¼ºó¸´ÖÆ

·­¿ªä¯ÀÀÆ÷£¬ÊäÈëhttp://localhost:8080/flamegraph.svg£¬¿ÉÒÔÉó²éÌìÉúµÄ»ðÑæͼ¡£

½áÂÛ£º

ͨ¹ýÒÔÉÏÏÈÈÝ£¬¿ÉÒÔÏàʶµ½ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎö¡£ÎÞÂÛÊÇʹÓÃDocker×Ô´øµÄ¹¤¾ß£¬ÕÕ¾ÉʹÓõÚÈý·½¹¤¾ß£¬¶¼¿ÉÒÔÀû±ãµØÉó²éÈÝÆ÷µÄ״̬ºÍÐÔÄÜÖ¸±ê¡£Í¬Ê±£¬Í¨¹ýÈÝÆ÷µÄÐÔÄÜÆÊÎö£¬¿ÉÒÔÕÒ³öÐÔÄÜÆ¿¾±²¢¾ÙÐÐÓÅ»¯£¬Ìá¸ßÓ¦ÓóÌÐòµÄÎȹÌÐÔºÍÐÔÄÜ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ¼à¿ØºÍÐÔÄÜÆÊÎöµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ