ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×Ô¶¯»¯ÔËάºÍ¼à¿Ø
Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÉú³¤£¬Docker³ÉΪÁËÏÖÔÚ×îÊ¢ÐеÄÈÝÆ÷ƽ̨֮һ¡£Docker²»µ«Äܹ»ÈÃÓ¦ÓóÌÐòÔ½·¢ÇáÓ¯¡¢¿çƽ̨£¬»¹¿ÉÒÔÌá¸ßÓ¦ÓõĿÉÒÆÖ²ÐԺ͵¯ÐÔ¡£DockerÖÐÒ²ÌṩÁ˸»ºñµÄ¹¤¾ßºÍ×é¼þ£¬¿ÉÒÔʵÏÖÈÝÆ÷µÄ×Ô¶¯»¯ÔËάºÍ¼à¿Ø¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÉîÈë̽ÌÖÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×Ô¶¯»¯ÔËάºÍ¼à¿Ø¡£
Ç°ÖÃ֪ʶ
ÔÚѧϰÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×Ô¶¯»¯ÔËάºÍ¼à¿Ø֮ǰ£¬ÎÒÃÇÐèÒªÏÈÕÆÎÕÒÔÏ»ù±¾ÖªÊ¶£º
Docker»ù´¡ÖªÊ¶£¬°üÀ¨Docker¾µÏñ¡¢DockerÈÝÆ÷µÈ¿´·¨¡£
Linux»ù´¡ÖªÊ¶£¬°üÀ¨LinuxÏÂÁîÐлù±¾²Ù×÷¡¢LinuxÎļþϵͳµÈ¿´·¨¡£
Docker-composeµÄ»ù´¡ÖªÊ¶£¬Docker-composeÊÇÒ»¸öÓÃÀ´½ç˵ºÍÔËÐжà¸öDockerÈÝÆ÷µÄ¹¤¾ß£¬¿ÉÒÔ¼ò»¯dockerÓ¦ÓõݲÅÅ¡£
ÈÝÆ÷×Ô¶¯»¯ÔËά
DockerÌṩÁËһЩ×Ô¶¯»¯ÔËάµÄ·½·¨£¬Ê¹µÃÈÝÆ÷ÉúÃüÖÜÆÚÖÎÀíÔ½·¢±ã½ÝºÍ¸ßЧ¡£ÔÚ±¾Õ½ÚÖУ¬ÎÒÃǽ«ÏÈÈÝʹÓÃDocker¾ÙÐÐÈÝÆ÷×Ô¶¯»¯ÔËάµÄÈý¸ö·½Ã棺
ÈÝÆ÷×Ô¶¯ÖØÆô
µ±×ðÁú¿Ê±ÈÝÆ÷·ºÆðÒ쳣ʱ£¬¿ÉÒÔʹÓÃDockerÌṩµÄ×Ô¶¯ÖØÆô¹¦Ð§£¬µ±ÈÝÆ÷×èÖ¹ÔËÐÐʱ£¬Docker»á×Ô¶¯½«ÈÝÖØÊÓÆô¡£
docker run --restart always image_name
µÇ¼ºó¸´ÖÆ
ÈÝÆ÷×Ô¶¯¸üÐÂ
µ±Docker¾µÏñ°æ±¾¸üÐÂʱ£¬DockerÌṩÁËÒ»ÖÖ×Ô¶¯¸üеķ½·¨£¬×Ô¶¯ÖØа汾µÄ¾µÏñÀÈ¡²¢Æô¶¯ÈÝÆ÷¡£
docker run -d --name my_container --restart=always image_name:latest
µÇ¼ºó¸´ÖÆ
ÈÝÆ÷×Ô¶¯¼à¿Ø
³ýÁËDocker×Ô´øµÄÈÝÆ÷¿µ½¡¼ì²éÍ⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃDocker×Ô´øµÄ¼à¿Ø¹¤¾ß£¬ºÃ±ÈDocker StatsÖ¸Áî¿ÉÒÔʵʱ¼à¿ØÈÝÆ÷ÔËÐеÄ״̬ÐÅÏ¢¡£
docker stats container_name»òÕßcontainer_id
µÇ¼ºó¸´ÖÆ
ÈÝÆ÷¼à¿Ø
DockerÌṩÁËÓÃÓÚ¼à¿ØÈÝÆ÷µÄ¹¤¾ß£¬ÆäÖÐÒ»¸ö½ÏÁ¿³£ÓõÄÊÇPrometheus£¬ËüÊÇÒ»¸ö¿ªÔ´¹¤¾ß¼¯£¬ÓÃÓÚÖ¸±ê¼Ç¼ºÍչʾ£¬¿ÉÒÔʵÏÖÈÝÆ÷ʱ¼äÐòÁÐÊý¾ÝÊÕÂÞºÍչʾ¡£ÔÚ±¾Ð¡½ÚÖУ¬ÎÒÃǽ«ÏêϸÏÈÈÝÔõÑùʹÓÃPrometheus¼à¿ØDockerÈÝÆ÷¡£
×°ÖÃPrometheus
Ê×ÏÈ£¬ÎÒÃÇÐèÒª´ÓPrometheusµÄ¹Ù·½ÍøÕ¾£¨https://prometheus.io/download/£©ÏÂÔØ×îеÄ×°Öðü£¬È»ºó½âѹËõµ½LinuxÖС£
tar -zxvf prometheus-*.tar.gz cd prometheus-*
µÇ¼ºó¸´ÖÆ
ÉèÖÃPrometheus
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½prometheus.ymlÎļþÖУ¬ÓÃÓÚÔÚPrometheusÉÏÉèÖÃDocker¼à¿Ø
scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090']
µÇ¼ºó¸´ÖÆ
ʹÓÃDocker ComposeÆô¶¯Prometheus
Æô¶¯PrometheusÏà¹ØЧÀÍ£¨Docker daemon£¬Prometheus£©µÄ×î¼òÆÓÒªÁìÊÇʹÓÃDocker Compose¡£ÒÔÏÂΪʾÀýdocker-compose.ymlÎļþ£¬ÓÃÓÚÆô¶¯PrometheusºÍÏà¹ØЧÀÍ¡£
version: '3' services: prometheus: image: prom/prometheus ports: - "9090:9090" volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml restart: always
µÇ¼ºó¸´ÖÆ
ÔÚPrometheusÉÏÉèÖÃDocker¼à¿Ø
½«ÒÔÏÂÄÚÈÝÌí¼Óµ½prometheus.ymlÎļþÖУ¬ÓÃÓÚÔÚPrometheusÉÏÉèÖÃDocker¼à¿Ø¡£
scrape_configs: - job_name: 'docker' scrape_interval: 5s static_configs: - targets: ['localhost:9323']
µÇ¼ºó¸´ÖÆ
ÔËÐÐexporter
Òª½«Docker״̬µ¼³öΪPrometheusÖ¸±ê£¬ÐèҪʹÓÃPrometheus Exporter£¬ÒÔÏÂΪdocker-compose.ymlÎļþʾÀý¡£
version: '3' services: prometheus: image: prom/prometheus ports: - "9090:9090" volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml restart: always prometheus-exporter: image: prom/node-exporter:v0.15.2 command: - '--path.rootfs=/hostfs' ports: - "9323:9323" volumes: - /proc:/hostfs/proc:ro - /sys:/hostfs/sys:ro - /:/hostfs:ro restart: always
µÇ¼ºó¸´ÖÆ
ÖØÆôЧÀͲ¢Éó²é¼à¿ØÐÅÏ¢
ÖØÆôDockerЧÀÍ£¬²¢Éó²éPrometheusµÄ¼à¿ØÐÅÏ¢£¬¿ÉÒÔ¿´µ½CPU¡¢ÄÚ´æµÈÖ¸±ê£¬ÒÔ¼°DockerÊØ»¤³ÌÐòµÄÖ¸±ê¡£
sudo systemctl daemon-reload sudo systemctl restart docker docker-compose up http://localhost:9090
µÇ¼ºó¸´ÖÆ
×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷×Ô¶¯»¯ÔËάºÍ¼à¿Ø£¬´ÓÈÝÆ÷×Ô¶¯ÖØÆô¡¢ÈÝÆ÷×Ô¶¯¸üС¢ÈÝÆ÷×Ô¶¯¼à¿ØÈëÊÖ£¬Ïêϸ½â˵ÁËÔõÑùʹÓÃPrometheusÀ´¼à¿ØDockerÈÝÆ÷ÔËÐÐÇéÐΡ£ÎÒÃÇÏàʶµ½£¬Ê¹ÓÃDocker¿ÉÒÔÈÃÈÝÆ÷ÔËάºÍ¼à¿ØÔ½·¢¸ßЧºÍ¼òÆÓ£¬ÈÃÎÒÃǸüºÃµØÖÎÀíÈÝÆ÷»¯Ó¦ÓóÌÐò¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ×Ô¶¯»¯ÔËάºÍ¼à¿ØµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡