下载镜像包
docker pull prom/prometheus # prometheus存储的是时序数据,即按相同时序(相同名称和标签),以时间维度存储连续的数据的集合。
docker pull grafana/grafana # Grafana
docker pull prom/node-exporter # linux 信息导出
docker pull oliver006/redis_exporter # redis 信息导出
linuxl启动node-exporter
docker run -d -p 8500:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter
#访问url查看收集的信息
192.18.0.10:8500/metrics
启动prometheus
mkdir -p /data/prometheus
vim prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux83
static_configs:
- targets: ['192.18.0.10:8500']
labels:
instance: linux83
docker run -d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
#访问 http://192.18.0.10:9090
这里开启的任务
#创建存储地址
mkdir /data/grafana/storage
chmod 777 /data/grafana/storage
#启动 grafana
docker run -d -p 9091:3000 --name=grafana -v /data/grafana/storage:/var/lib/grafana grafana/grafana
#访问网页 默认账号密码都是admin
192.18.0.10:9091
添加数据源,选prometheus,里面添加prometheus网址测试保存就OK了
去这个网址 找想要的图 https://grafana.com/dashboards 添加node-exporter dashboards
Cadvisor容器安装(获取容器数据,网络数据)
使用脚本方式创建容器
vi cadvisor-start.sh
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=9092:8080\
--detach=true \
--name=cadvisor \
google/cadvisor:latest
http://IP:9092 可以查看Docker Containers
http://IP:9092/metrics 可以查看那些数据暴露给prometheus
grafana 添加容器的10566的dashboard
完成监控
cadvisor 的
docker-compose
cat > docker-compose.yml <<-'EOF'
version:'2'
services:
cadvisor:
image: google/cadvisor:latest
container_name:cadvisor
restart: unless-stopped
ports:
- '9092:8080'
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
EOF