标签:
关于 Docker 容器的监控,google cAdvisor 是个很好的工具,但是它默认只显示实时数据,不储存历史数据。为了存储和显示历史数据、自定义展示图,可以把将cAdvisor与InfluxDB、Grafana 集成起来,国外的专家 Brian Christner 写了一篇文章 ”How to setup Docker Monitoring“,描述了部署方法。
Brian 的方法是手动运行 docker run 命令进行部署,为了能在 Mesos Marathon 平台上自动部署,我对他的方法进行了一些修改,下面我的部署过程。
注:
读者需要提前了解 mesos、marathon、InfluxDB 特别是 Grafana 的基本操作。
为了实现 InfluxDB 数据库和 Grafana 配置的持久化存储,使他们重新部署后不会丢失历史数据,我启用了 nfs4作为共享存储,把 InfluxDB 容器里的 /data 目录、Grafana 容器的 /var/lib/grafana 目录映射到 nfs4共享存储上。
/var/nfsshare 172.31.17.0/24(rw,sync,no_root_squash,no_all_squash)
172.31.17.74:/var/nfsshare/ /var/nfsshare/ nfs defaults 0 0
在每个mesos slave上拉取下述几个images:
tutum/influxdb
google/cadvisor
grafana/grafana
172.31.17.34 influxdb.gkkxd.com
172.31.17.34 cadvisor-1.gkkxd.com
172.31.17.34 cadvisor-2.gkkxd.com
172.31.17.34 cadvisor-3.gkkxd.com
172.31.17.34 grafana.gkkxd.com
{ "id": "influxdb", "instances": 1, "cpus": 0.5, "mem": 128, "constraints": [["hostname", "LIKE", "slave[1-3]"]], "labels": { "HAPROXY_GROUP":"external", "HAPROXY_0_VHOST":"influxdb.gkkxd.com" }, "container": { "type": "DOCKER", "docker": { "image": "172.31.17.36:5000/influxdb:latest", "network": "BRIDGE", "portMappings": [ { "containerPort": 8083, "hostPort": 0, "servicePort": 0, "protocol": "tcp" }, { "containerPort": 8086, "hostPort": 0, "servicePort": 28086, "protocol": "tcp" } ] }, "volumes": [ { "containerPath": "/etc/localtime", "hostPath": "/etc/localtime", "mode": "RO" }, { "containerPath": "/data", "hostPath": "/var/nfsshare/influxdb", "mode": "RW" } ] } }
设置marathon-lb所在主机的防火墙:
{ "id": "influxdb-fw", "instances": 2, "cpus": 0.2, "mem": 64, "cmd": "firewall-cmd --add-port=28086/tcp && sleep 3 && curl -X DELETE master1:8080/v2/apps/influxdb-fw", "constraints": [["hostname", "LIKE", "slave[4-5]"]] }
打开 http://influxdb.gkkxd.com ,设置 Host 和 Port 分别为 influxdb.gkkxd.com 和 28086:
为每个mesos slave创建一个单独的数据库,分别为:cadvisor_1, cadvisor_2, cadvisor_3 ...
{ "id": "cadvisor-6", "instances": 1, "cpus": 0.5, "mem": 128, "constraints": [["hostname", "LIKE", "slave[6]"]], "labels": { "HAPROXY_GROUP":"external", "HAPROXY_0_VHOST":"cadvisor-6.gkkxd.com" }, "container": { "type": "DOCKER", "docker": { "image": "172.31.17.36:5000/cadvisor:latest", "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "hostPort": 0, "servicePort": 0, "protocol": "tcp" } ] }, "volumes": [ { "containerPath": "/etc/localtime", "hostPath": "/etc/localtime", "mode": "RO" }, { "containerPath": "/rootfs", "hostPath": "/", "mode": "RO" }, { "containerPath": "/var/run", "hostPath": "/var/run", "mode": "RW" }, { "containerPath": "/sys", "hostPath": "/sys", "mode": "RO" }, { "containerPath": "/var/lib/docker", "hostPath": "/var/lib/docker", "mode": "RO" }, { "containerPath": "/cgroup", "hostPath": "/cgroup", "mode": "RO" } ] }, "args": [ "-storage_driver", "influxdb", "-storage_driver_host", "cadvisor.gkkxd.com:28086", "-storage_driver_db", "cadvisor_6" ] }
查看cAdvisor UI:
http://cadvisor-6.gkkxd.com
{ "id": "grafana", "instances": 1, "cpus": 0.5, "mem": 128, "constraints": [["hostname", "LIKE", "slave[4-5]"]], "labels": { "HAPROXY_GROUP":"external", "HAPROXY_0_VHOST":"grafana.gkkxd.com" }, "container": { "type": "DOCKER", "docker": { "image": "172.31.17.36:5000/grafana:latest", "network": "BRIDGE", "portMappings": [ { "containerPort": 3000, "hostPort": 0, "servicePort": 0, "protocol": "tcp" } ] }, "volumes": [ { "containerPath": "/etc/localtime", "hostPath": "/etc/localtime", "mode": "RO" }, { "containerPath": "/var/lib/grafana", "hostPath": "/var/nfsshare/grafana", "mode": "RW" } ] } }
打开 Grafana UI:
http://grafana.gkkxd.com/
创建graph:
效果图:
可以将Prometheus集成进来,后续我将进行相关测试;
我们在 Grafana 上创建针对app实例的监控图的时候,往往需要通过 "where container_name=容器名" 的条件筛选相关的数据,但是mesos marathon部署的docker 容器名称是以mesos-uuid形式命名的(docker ps 查看),没有明显的特征可以识别。
下面的方法可以查看一个app ID对应的docker 容器名称:
打开 mesos 管理页面:
http://master1:5050
在mesos task里,点击要查找的app ID后面的 Sandbox,
点击 stdout 即可看到这个app ID对应的docker 容器名称:
[经验交流] 在 Mesos Marathon 上部署 cAdvisor + InfluxDB + Grafana Docker监控
标签:
原文地址:http://www.cnblogs.com/hahp/p/5588379.html