1. 获取镜像

  1. # 搜索镜像
  2. sudo docker search prometheus
  3. sudo docker search node-exporter
  4. sudo docker search cadvisor
  5. # 拉取镜像
  6. sudo docker pull prom/node-exporter
  7. sudo docker pull google/cadvisor
  8. sudo docker pull prom/prometheus
  9. sudo docker pull prom/pushgateway
  10. # 查看镜像
  11. sudo docker image ls |grep -E 'prometheus|node-exporter|cadvisor|pushgateway'

2. 安装Exporters(探针)

1. node-exporter

  1. sudo docker run -d --name node-exporter -p 19100:9100 \
  2. -v "/proc:/host/proc:ro" \
  3. -v "/sys:/host/sys:ro" \
  4. -v "/:/rootfs:ro" \
  5. prom/node-exporter
  6. sudo docker ps |grep node-exporter
  7. sudo docker start node-exporter
  8. sudo docker restart node-exporter
  9. sudo docker stop node-exporter
  10. sudo docker rm node-exporter
  • 验证
    1. # 端口查看
    2. netstat -anpt
    Web UIhttp://LTSR003:19100
    Metric URLhttp://LTSR003:19100/metrics

    2. cAdvisor

    ```bash sudo docker run -d —name cadvisor \ —volume=/:/rootfs:ro \ —volume=/var/run:/var/run:ro \ —volume=/sys:/sys:ro \ —volume=/var/lib/docker/:/var/lib/docker:ro \ —volume=/dev/disk/:/dev/disk:ro \ —publish=18087:8080 \ —detach=true \ —name=cadvisor \ google/cadvisor

sudo docker ps |grep cadvisor sudo docker start cadvisor sudo docker restart cadvisor sudo docker stop cadvisor sudo docker rm cadvisor

  1. - **验证**
  2. ```bash
  3. # 端口查看
  4. netstat -anpt

Web UIhttp://LTSR003:18087
Metric URLhttp://LTSR003:18087/metrics

3. 启动Pushgateway

  1. sudo docker run -d --name pushgateway \
  2. -p 19091:9091 \
  3. prom/pushgateway
  4. sudo docker ps |grep pushgateway
  5. sudo docker start pushgateway
  6. sudo docker restart pushgateway
  7. sudo docker stop pushgateway
  8. sudo docker rm pushgateway
  • 验证
    1. # 端口查看
    2. netstat -anpt
    Web UIhttp://LTSR003:19091
    Metric URLhttp://LTSR003:19091/metrics

    4. 启动prometheus

    1. mkdir -p /root/docker/prometheus && cd /root/docker/prometheus
    2. rm -rf /root/docker/prometheus/prometheus.yml
    3. vi /root/docker/prometheus/prometheus.yml
    内容如下: ```yaml global: scrape_interval: 60s evaluation_interval: 60s

scrape_configs:

  • job_name: prometheus static_configs:

    • targets: [‘10.8.0.125:19090’] labels: instance: prometheus
  • job_name: linux static_configs:

    • targets: [‘10.8.0.125:19100’] labels: instance: localhost
  • job_name: “docker” static_configs:

    • targets: [‘10.8.0.125:18087’] labels: instance: docker
  • job_name: pushgateway static_configs:

    • targets: [‘10.8.0.125:19091’] labels: instance: pushgateway 启动:bash sudo docker run -d —name prometheus \ -p 19090:9090 \ -v /root/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus

sudo docker ps |grep prometheus sudo docker start prometheus sudo docker restart prometheus sudo docker stop prometheus sudo docker rm prometheus

  1. - **验证**
  2. ```bash
  3. # 端口查看
  4. netstat -anpt

Web UIhttp://LTSR003:19090/graph
Targets UIhttp://LTSR003:19090/targets

参考

博客园:基于Docker搭建Prometheus+Grafana
https://www.cnblogs.com/xiao987334176/p/9930517.html
简书:容器监控实践—node-exporter
https://www.jianshu.com/p/e3c9fc929d8a
B站:Prometheus+Grafana监控Docker
https://www.bilibili.com/video/BV1T54y1Q7VY?p=1