The Docker swarm cluster has many monitoring options, and the Cadvisor+influxdb+grafana solution is powerful and flexible. The most important thing is that this program is open source, free, easy to use, is an inexpensive version of the monitoring program. Reference Document: https://botleg.com/stories/monitoring-docker-swarm-with-cadvisor-influxdb-and-grafana/
Component description
Cadvisor: A data collection module that needs to be deployed on every node in the cluster, if the node accepts a task. In this experiment, there were three nodes, because one of the nodes did drain and did not accept any task scheduling, so the final result was deployed on two nodes.
InfluxDB: Data storage module.
Grafana: Data Presentation module
Environment preparation
Docker version: 18.04.0 CE.
参考79923218 创建包含三个节点的docker swarm集群。
Create a Docker compose file
Create a file on the manager node and enter the following:
version: ' 3 ' services:influx:image:influxdb volumes:-Influx:/var/lib/influxdb Deploy: Replicas:1 placement:constraints:-node.role = = Manager Grafana:image:grafana/grafana PO RTS:-0.0.0.0:3000:3000 volumes:-Grafana:/var/lib/grafana depends_on:-Influx Deploy:rep Licas:1 placement:constraints:-node.role = = Manager Cadvisor:image:google/cadvisor Host Name: ' {{. Node.hostname}} ' command:-logtostderr-docker_only-storage_driver=influxdb-storage_driver_db=cadvisor-storage_ driver_host=influx:8086 volumes:-/:/rootfs:ro-/VAR/RUN:/VAR/RUN:RW-/sys:/sys:ro-/var/lib/do Cker/:/var/lib/docker:ro-/SYS/FS/CGROUP/CPU,CPUACCT:/SYS/FS/CGROUP/CPUACCT,CPU:RW-/dev/disk/:/dev/disk:ro DEPENDS_ON:-Influx Deploy:mode:global volumes:influx:driver:local grafana:driver:local
Deploy container stacks
Execute the following command on the manager node:
docker stack deploy -c docker-stack.yml monitor
命令返回以后并不代表task已经完成部署,需要花一些时间,运行如下命令监控容器栈的部署状态:
Docker Stack Services Monitor
As shown in the following:
When the numbers in the Red box match, the deployment is done on behalf of the container stack, and then the subsequent steps are performed.
Create a name for the Cadvisor database to store data
Confirm the node that the Monitor_cadvisor service is running by executing the following command:
Docker Service PS Monitor_influx
The result is as shown in the red box:
登录worker2结点,执行事下指令创建数据库:
docker exec `docker ps | grep -i influx | awk ‘{print $1}‘` influx-execute ‘CREATE DATABASE cadvisor‘
Set Grafana
Because Grafana is deployed on the Worker1 node, access http://192.168.30.40:3000 in the browser, using the default user name \ password: admin\admin, such as:
Click "Add Data Source". As shown, fill in the red box in the picture, and the other items are ignored:
点击"Save &Test",如果出现"Data source is working"表示数据源添加成功。增加Dashboard配置。首先从
- Https://github.com/botleg/swarm-monitoring/blob/master/dashboard.json
https://grafana.com/dashboards/1367
Download the sample configuration file as shown, upload as prompted
Configuration file:
At this point, the Docker swarm cluster monitoring system is deployed to enable monitoring of the host and the containers it runs on. On this basis, we can experiment with some other functions, such as self-righteous dashboard, custom alarm rules, etc. As can be seen from this example, the key point of this scheme is the dashboard configuration, which is good to display and very flexible.
Docker Swarm Cadvisor+influxdb+grafana Monitoring