1. 获取镜像
# 搜索镜像sudo docker search prometheussudo docker search node-exportersudo docker search cadvisor# 拉取镜像sudo docker pull prom/node-exportersudo docker pull google/cadvisorsudo docker pull prom/prometheussudo docker pull prom/pushgateway# 查看镜像sudo docker image ls |grep -E 'prometheus|node-exporter|cadvisor|pushgateway'
2. 安装Exporters(探针)
1. node-exporter
sudo docker run -d --name node-exporter -p 19100:9100 \-v "/proc:/host/proc:ro" \-v "/sys:/host/sys:ro" \-v "/:/rootfs:ro" \prom/node-exportersudo docker ps |grep node-exportersudo docker start node-exportersudo docker restart node-exportersudo docker stop node-exportersudo docker rm node-exporter
- 验证
Web UI:http://LTSR003:19100# 端口查看netstat -anpt
Metric URL:http://LTSR003:19100/metrics2. 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
- **验证**```bash# 端口查看netstat -anpt
Web UI:http://LTSR003:18087
Metric URL:http://LTSR003:18087/metrics
3. 启动Pushgateway
sudo docker run -d --name pushgateway \-p 19091:9091 \prom/pushgatewaysudo docker ps |grep pushgatewaysudo docker start pushgatewaysudo docker restart pushgatewaysudo docker stop pushgatewaysudo docker rm pushgateway
- 验证
Web UI:http://LTSR003:19091# 端口查看netstat -anpt
Metric URL:http://LTSR003:19091/metrics4. 启动prometheus
内容如下: ```yaml global: scrape_interval: 60s evaluation_interval: 60smkdir -p /root/docker/prometheus && cd /root/docker/prometheusrm -rf /root/docker/prometheus/prometheus.ymlvi /root/docker/prometheus/prometheus.yml
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
- targets: [‘10.8.0.125:19091’]
labels:
instance: pushgateway
sudo docker ps |grep prometheus sudo docker start prometheus sudo docker restart prometheus sudo docker stop prometheus sudo docker rm prometheus
- **验证**```bash# 端口查看netstat -anpt
Web UI:http://LTSR003:19090/graph
Targets UI:http://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
