运行容器
启动node-exporter容器
docker run -d --net="host" -v "/:/host:ro,rslave" hub.c.163.com/qingzhou/prometheus/node-exporter:v0.17.0 --path.rootfs=/host
说明:该容器和宿主机共享网络栈。验证是否和宿主机在一个网络栈。
宿主机网络栈
[root@ceph01 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:d3:e0:07 brd ff:ff:ff:ff:ff:ff
inet 192.168.229.114/24 brd 192.168.229.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::d927:ef4:3fcd:a1d4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@ceph01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e63dbef9a57 hub.c.163.com/qingzhou/grafana:6.7.1-with-simpod-json-datasource "/run.sh" 2 days ago Up 2 days 0.0.0.0:3001->3000/tcp grafana
0f5f0a366566 hub.c.163.com/qingzhou/cadvisor:v0.30.2 "/usr/bin/cadvisor -…" 2 days ago Up 2 days 0.0.0.0:8081->8080/tcp cadvisor
2d1f82717dc7 hub.c.163.com/qingzhou/prometheus:v2.9.2 "/bin/prometheus --c…" 2 days ago Up 8 minutes 0.0.0.0:9091->9090/tcp prometheus
9b185bc37a6b hub.c.163.com/qingzhou/prometheus/node-exporter:v0.17.0 "/bin/node_exporter …" 2 days ago Up 2 days elegant_pasteur
node-exporter网络栈
[root@ceph01 ~]# docker exec -it elegant_pasteur sh
/ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether fa:16:3e:d3:e0:07 brd ff:ff:ff:ff:ff:ff
inet 192.168.229.114/24 brd 192.168.229.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::d927:ef4:3fcd:a1d4/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
link/ether 02:42:69:e3:5a:22 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:69ff:fee3:5a22/64 scope link
valid_lft forever preferred_lft forever
启动cadvisor容器
docker run -itd --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=8080:8080\
--detach=true\
--name=cadvisor hub.c.163.com/qingzhou/cadvisor:v0.30.2
启动prometheus容器
docker run -d -p 9090:9090 -v /etc/prometheus/ --name prometheus hub.c.163.com/qingzhou/prometheus:v2.9.2
验证是否获取监控项目
curl 192.168.229.114:9091/metrics
curl 192.168.229.114:8081/metrics
curl 192.168.229.114:9100/metrics
配置prometheus
查看prometheus在宿主机的工作目录
docker inspect prometheus|grep -i source
"Source": "/var/lib/docker/volumes/306ce921c7c9abe564624c2d0584948e3964640f13d70133cd70a265a02e269e/_data",
"Source": "/var/lib/docker/volumes/83f3a9f464aaba86c3034bc522e5cb54b8516129461959e935e57c33cd20f968/_data",
进入工作目录
cd /var/lib/docker/volumes/306ce921c7c9abe564624c2d0584948e3964640f13d70133cd70a265a02e269e/_data
修改配置文件,增加3个job
cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.229.114:9090']
- job_name: 'host'
static_configs:
- targets: ['192.168.229.114:9100']
- job_name: 'containers'
static_configs:
- targets: ['192.168.229.114:8081']
配置grafana
登录grafana
浏览器输入宿主机ip:9091
默认用户名admin密码admin
添加数据源
查看添加的dashboard
创建新的dashboard
根据metrics添加dashboard
根据dashboard id添加dashboard
查看dashboard的id
https://grafana.com/
效果
再将id为11277和13112的dashboard添加进去即可。
11277dashboard
13112dashboard