ÔõÑùÔÚLinuxÉÏÉèÖÃÈÝÆ÷¼à¿Ø
ÔõÑùÔÚlinuxÉÏÉèÖÃÈÝÆ÷¼à¿Ø
СÐò£º
Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÉú³¤£¬Ô½À´Ô½¶àµÄÆóҵѡÔñʹÓÃÈÝÆ÷À´°²ÅÅÓ¦ÓóÌÐò¡£È»¶ø£¬ÈÝÆ÷µÄʹÓÃÒ²´øÀ´ÁËеÄÌôÕ½£¬ÈçÔõÑù¼à¿ØºÍÖÎÀíÈÝÆ÷µÄ״̬ºÍÐÔÄÜ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖÃÈÝÆ÷¼à¿Ø£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
Ò»¡¢×°ÖÃDockerºÍDocker Compose
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°ÖÃDockerºÍDocker Compose¡£DockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷ÒýÇ棬ÓÃÓÚ½¨ÉèºÍÖÎÀíÈÝÆ÷¡£Docker ComposeÊÇÒ»¸ö¹¤¾ß£¬ÓÃÓÚ½ç˵ºÍÖÎÀí¶à¸öDockerÈÝÆ÷µÄÓ¦Óá£ÒÔÏÂÊÇÔÚUbuntuÉÏ×°ÖÃDockerºÍDocker ComposeµÄÏÂÁ
# ×°ÖÃDocker sudo apt-get update sudo apt-get install docker.io # ×°ÖÃDocker Compose sudo apt-get install docker-compose
µÇ¼ºó¸´ÖÆ
¶þ¡¢Æô¶¯Prometheus
PrometheusÊÇÒ»¸ö¿ªÔ´µÄϵͳ¼à¿ØºÍ¾¯±¨¹¤¾ß£¬¿ÉÒÔÓÃÓÚ¼à¿ØÈÝÆ÷µÄ״̬ºÍÐÔÄÜ¡£ÒÔÏÂÊÇÔõÑùʹÓÃDocker ComposeÆô¶¯PrometheusµÄʾÀýÉèÖÃÎļþdocker-compose.yml£º
version: '3' services: prometheus: image: prom/prometheus ports: - 9090:9090 volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml
µÇ¼ºó¸´ÖÆ
ÔÚ¸ÃÉèÖÃÎļþÖУ¬ÎÒÃÇʹÓÃPrometheus¹Ù·½ÌṩµÄDocker¾µÏñ£¬²¢½«PrometheusµÄ¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ9090¶Ë¿Ú¡£ÎÒÃÇ»¹½«¹ÒÔØÍâµØµÄprometheus.ymlÉèÖÃÎļþµ½ÈÝÆ÷ÄÚ²¿µÄ/etc/prometheus/Ŀ¼¡£
Èý¡¢ÉèÖÃPrometheus
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃPrometheusÀ´¼à¿ØÈÝÆ÷¡£ÔÚÉÏÒ»²½ÖУ¬ÎÒÃǽ«ÍâµØµÄprometheus.ymlÉèÖÃÎļþ¹ÒÔص½ÁËÈÝÆ÷ÄÚ²¿¡£ÎÒÃÇ¿ÉÒÔ±à¼Õâ¸öÉèÖÃÎļþÀ´½ç˵ÐèÒª¼à¿ØµÄÄ¿µÄ¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄprometheus.ymlʾÀý£º
global: scrape_interval: 15s scrape_configs: - job_name: 'docker-containers' static_configs: - targets: ['cadvisor:8080']
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÉèÖÃÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪdocker-containersµÄjob£¬ÓÃÓÚ¼à¿ØDockerÈÝÆ÷¡£ÎÒÃǽ«¼à¿ØÄ¿µÄÉèÖÃΪcadvisor:8080£¬ÌåÏÖÎÒÃǽ«¼à¿ØcadvisorÈÝÆ÷µÄ8080¶Ë¿Ú¡£×¢ÖØ£¬cadvisorÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷¼à¿Ø¹¤¾ß£¬¿ÉÒÔÓÃÓÚÍøÂçÈÝÆ÷µÄÐÔÄÜÊý¾Ý¡£
ËÄ¡¢Æô¶¯cAdvisor
ΪÁËÈÃPrometheusÄܹ»¼à¿ØÈÝÆ÷µÄ״̬ºÍÐÔÄÜ£¬ÎÒÃÇÐèҪͨ¹ýcAdvisorÀ´ÍøÂçÕâЩÊý¾Ý¡£cAdvisorÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷¼à¿Ø¹¤¾ß£¬¿ÉÒÔÔÚDockerÖÐÆô¶¯¡£ÒÔÏÂÊÇʹÓÃDocker ComposeÆô¶¯cAdvisorµÄʾÀýÉèÖÃÎļþdocker-compose.yml£º
version: '3' services: cadvisor: image: google/cadvisor ports: - 8080:8080 volumes: - /:/rootfs:ro - /var/run:/var/run:rw - /sys:/sys:ro - /var/lib/docker:/var/lib/docker:ro
µÇ¼ºó¸´ÖÆ
ÔÚ¸ÃÉèÖÃÎļþÖУ¬ÎÒÃÇʹÓÃGoogle¹Ù·½ÌṩµÄcAdvisor¾µÏñ£¬²¢½«cAdvisorµÄ¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú¡£ÎÒÃÇ»¹¹ÒÔØÁËһЩÖ÷»úĿ¼µ½ÈÝÆ÷ÄÚ²¿£¬ÒÔ±ãcAdvisorÄܹ»»á¼ûÏà¹ØµÄÈÝÆ÷Êý¾Ý¡£
Îå¡¢ÉèÖÃGrafana
GrafanaÊÇÒ»¸ö¿ªÔ´µÄ¿ÉÊÓ»¯¼à¿ØºÍÆÊÎö¹¤¾ß£¬¿ÉÒÔÓÃÓÚչʾPrometheusÍøÂçµÄ¼à¿ØÊý¾Ý¡£ÒÔÏÂÊÇÔõÑùʹÓÃDocker ComposeÆô¶¯GrafanaµÄʾÀýÉèÖÃÎļþdocker-compose.yml£º
version: '3' services: grafana: image: grafana/grafana ports: - 3000:3000
µÇ¼ºó¸´ÖÆ
ÔÚ¸ÃÉèÖÃÎļþÖУ¬ÎÒÃÇʹÓÃGrafana¹Ù·½ÌṩµÄDocker¾µÏñ£¬²¢½«GrafanaµÄ¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ3000¶Ë¿Ú¡£
Áù¡¢Ê¹ÓÃÈÝÆ÷¼à¿Ø
ÏÖÔÚ£¬ÎÒÃÇÒѾÍê³ÉÁËÔÚLinuxÉÏÉèÖÃÈÝÆ÷¼à¿ØµÄ°ì·¨¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚä¯ÀÀÆ÷Öлá¼ûPrometheusºÍGrafanaµÄµØµãÀ´Éó²é¼à¿ØÊý¾Ý¡£ÒÔÏÂÊÇ»á¼ûÕâЩ¹¤¾ßµÄʾÀýµØµã£º
Prometheus: http://localhost:9090
Grafana: http://localhost:3000
ÔÚGrafanaÖУ¬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒDZíÅÌÀ´Õ¹Ê¾ÈÝÆ÷µÄ¼à¿ØÊý¾Ý¡£ÎÒÃÇ¿ÉÒÔʹÓÃPrometheus×÷ΪÊý¾ÝÔ´£¬²¢Ê¹ÓÃPromQLÅÌÎÊÓïÑÔÀ´½ç˵Êý¾ÝÅÌÎÊ¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öÒDZíÅÌ£¬Õ¹Ê¾ÈÝÆ÷µÄCPUʹÓÃÂʺÍÄÚ´æʹÓÃÂÊ¡£
½áÂÛ£º
ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÎÒÃÇÏàʶÁËÔõÑùÔÚlinuxÉÏÉèÖÃÈÝÆ÷¼à¿Ø£¬²¢ÌṩÁËÏìÓ¦µÄ´úÂëʾÀý¡£Í¨¹ýʹÓÃPrometheus¡¢cAdvisorºÍGrafana£¬ÎÒÃÇ¿ÉÒÔ¼à¿ØºÍÆÊÎöÈÝÆ÷µÄ״̬ºÍÐÔÄÜ£¬×ÊÖúÎÒÃǸüºÃµØÖÎÀíºÍÓÅ»¯ÈÝÆ÷»¯Ó¦ÓóÌÐò¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú£¬Ð»Ð»ÔĶÁ£¡
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖÃÈÝÆ÷¼à¿ØµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡