尊龙凯时人生就是搏

LinuxÉϵÄDockerÈÝÆ÷¼à¿Ø£ºÔõÑùʵʱ¼à²âÈÝÆ÷µÄÔËÐÐ״̬£¿

linuxÉϵÄdockerÈÝÆ÷¼à¿Ø£ºÔõÑùʵʱ¼à²âÈÝÆ÷µÄÔËÐÐ״̬£¿

СÐò£º

Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÆÕ±éÓ¦Óà £¬DockerÒѳÉΪ×îÊܽӴýµÄÈÝÆ÷»¯Æ½Ì¨Ö®Ò»¡£È»¶ø £¬½ö½ö½¨ÉèºÍÔËÐÐÈÝÆ÷ÊDz»·óµÄ £¬¶ÔÈÝÆ÷¾ÙÐмà¿ØÒÔÈ·±£ÆäÎȹÌÔËÐÐÊÇÖÁ¹ØÖ÷ÒªµÄ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxƽ̨ÉÏʵʱ¼à²âDockerÈÝÆ÷µÄÔËÐÐ״̬ £¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

Ò»¡¢DockerÈÝÆ÷¼à¿ØµÄÖ÷ÒªÐÔ

ͨ¹ý¼à¿ØDockerÈÝÆ÷ £¬ÎÒÃÇ¿ÉÒÔʵʱ׷×ÙÈÝÆ÷µÄCPUʹÓÃÂÊ¡¢ÄÚ´æÕ¼Óá¢ÍøÂçÁ÷Á¿¡¢´ÅÅÌIOµÈÖ¸±ê £¬ÒÔ±ãʵʱ·¢Ã÷²¢½â¾öDZÔÚµÄÎÊÌ⡣ͬʱ £¬¼à¿Ø»¹¿ÉÒÔ×ÊÖúÎÒÃÇÓÅ»¯×ÊԴʹÓà £¬Ìá¸ßÕûϵһÇеÄÐÔÄÜ¡£

¶þ¡¢Ê¹ÓÃcAdvisor¼à¿ØDockerÈÝÆ÷

cAdvisorÊÇÒ»¸ö¿ªÔ´¹¤¾ß £¬×¨ÃÅÓÃÓÚ¼à¿ØÈÝÆ÷µÄ×ÊԴʹÓÃÇéÐΡ£Ëü¿ÉÒÔÔÚDockerÖ÷»úÉÏͨ¹ýDocker APIÓëDockerÒýÇæ¾ÙÐÐͨѶ £¬²¢ÍøÂçÈÝÆ÷Äڵĸ÷ÏîÖ¸±ê¡£

×°ÖÃcAdvisor

ÔÚLinuxϵͳÉÏ×°ÖÃcAdvisorºÜÊǼòÆÓ¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

docker run 
  --volume=/:/rootfs:ro 
  --volume=/var/run:/var/run:rw 
  --volume=/sys:/sys:ro 
  --volume=/var/lib/docker/:/var/lib/docker:ro 
  --publish=8080:8080 
  --detach=true 
  --name=cadvisor 
  google/cadvisor:latest

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁî»áÔÚÍâµØÆô¶¯Ò»¸öcAdvisorÈÝÆ÷ £¬²¢½«ÆäÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú¡£

Éó²é¼à¿ØЧ¹û

ÔÚä¯ÀÀÆ÷Öлá¼ûhttp://localhost:8080¼´¿ÉÉó²écAdvisorµÄ¼à¿Ø½çÃæ¡£¸Ã½çÃæÄܹ»ÏÔʾÈÝÆ÷µÄ¸÷ÏîÖ¸±ê £¬°üÀ¨CPU¡¢ÄÚ´æ¡¢ÍøÂç¡¢´ÅÅ̵È¡£

Èý¡¢Ê¹ÓÃDocker API¼à¿ØÈÝÆ÷

³ýÁËʹÓÃcAdvisorÍâ £¬ÎÒÃÇ»¹¿ÉÒÔͨ¹ýDocker APIÀ´¼à¿ØÈÝÆ÷µÄÔËÐÐ״̬¡£Docker APIÌṩÁËһϵÁÐ½Ó¿Ú £¬¿ÉÒÔÅÌÎʺÍÖÎÀíÈÝÆ÷µÄÐÅÏ¢¡£

×°ÖÃDocker SDK for Python

Ê×ÏÈ £¬ÎÒÃÇÐèҪװÖÃDocker SDK for Python £¬ËüÊÇDocker¹Ù·½ÌṩµÄPython¿â £¬ÓÃÓÚÓëDocker API¾ÙÐн»»¥¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

pip install docker

µÇ¼ºó¸´ÖÆ

ʹÓôúÂë¼à¿ØÈÝÆ÷

ÏÂÃæÊÇÒ»¸öʹÓÃDocker SDK for PythonÀ´¼à¿ØÈÝÆ÷µÄʾÀý´úÂ룺

import docker

def monitor_container(container_id):
    client = docker.from_env()
    container = client.containers.get(container_id)
    
    stats = container.stats(stream=True)
    for stat in stats:
        # ´¦ÀíÈÝÆ÷µÄͳ¼ÆÊý¾Ý
        print(stat)

µÇ¼ºó¸´ÖÆ

¸Ã´úÂëÊ×ÏÈʹÓÃdocker.from_env()½¨ÉèÁËÒ»¸öDocker¿Í»§¶ËʵÀý £¬È»ºóͨ¹ýclient.containers.get(container_id)»ñÈ¡Ö¸¶¨µÄÈÝÆ÷¹¤¾ß¡£½Ó×Å £¬Í¨¹ýcontainer.stats(stream=True)»ñÈ¡ÈÝÆ÷µÄʵʱͳ¼ÆÊý¾Ý £¬²¢¾ÙÐÐÏìÓ¦µÄ´¦Àí¡£

ËÄ¡¢×ܽá

±¾ÎÄÏÈÈÝÁËÔÚLinuxÉÏÔõÑùʵʱ¼à¿ØDockerÈÝÆ÷µÄÔËÐÐ״̬¡£Í¨¹ýʹÓÃcAdvisorºÍDocker API £¬ÎÒÃÇ¿ÉÒÔÀû±ãµØ»ñÈ¡ÈÝÆ÷µÄ¸÷ÏîÖ¸±ê £¬²¢¾Ý´Ë¾ÙÐÐÐÔÄÜÓÅ»¯ºÍ¹ÊÕÏÅŲ顣ϣÍû±¾ÎĶÔÄãÏàʶDockerÈÝÆ÷¼à¿ØÓÐËù×ÊÖú¡£

´úÂëʾÀýºÍAPIÎĵµ¿ÉÒԲο¼ÒÔÏÂÁ´½Ó£º

cAdvisor: https://github.com/google/cadvisor

Docker SDK for Python: https://docker-py.readthedocs.io/

ÒÔÉϾÍÊÇLinuxÉϵÄDockerÈÝÆ÷¼à¿Ø£ºÔõÑùʵʱ¼à²âÈÝÆ÷µÄÔËÐÐ״̬£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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