å®è¡äžã®ã¢ããªã±ãŒã·ã§ã³ã®ã¹ããŒã¿ã¹ãç£èŠããã«ã¯ãåžžã«ç£èŠããå¿
èŠããããŸãã ãŸããã¢ããªã±ãŒã·ã§ã³ãDocker Swarmãªã©ã®éåžžã«ã¹ã±ãŒã©ãã«ãªç°å¢ã§å®è¡ãããå Žåãéåžžã«ã¹ã±ãŒã©ãã«ãªç£èŠããŒã«ãå¿
èŠã§ãã ãã®èšäºã§ã¯ããã®ãããªããŒã«ã®ãã¥ãŒãã³ã°ã«ã€ããŠèª¬æããŸãã
ãã®ããã»ã¹ã§ã¯ãåããŒãã«cAdvisorãšãŒãžã§ã³ããã€ã³ã¹ããŒã«ããŠããã¹ããšã³ã³ãããŒã®ã¡ããªãã¯ãåéããŸãã ã¡ããªãã¯ã¯InfluxDBã«ä¿åãããŸã ã ãããã®ã¡ããªãã¯ã«åºã¥ããŠã°ã©ããäœæããã«ã¯ã Grafanaã䜿çšããŸã ã ãããã®ããŒã«ã¯ãªãŒãã³ãœãŒã¹ã§ãããã³ã³ãããšããŠå±éã§ããŸãã
ã¯ã©ã¹ã¿ãŒãæ§ç¯ããã«ã¯ãDocker Swarmã¢ãŒãã䜿çšããå¿
èŠãªãµãŒãã¹ãã¹ã¿ãã¯ã®åœ¢ã§ãããã€ããŸãã ããã«ãããåçç£èŠã·ã¹ãã ãç·šæã§ããããã«ãªããæ°ããããŒããswarmã«è¿œå ããããšèªåçã«ç£èŠãéå§ã§ããŸãã ãããžã§ã¯ããã¡ã€ã«ã¯ãã¡ãã«ãããŸã ã
ããŒã«ã®æŠèŠ
ç£èŠã·ã¹ãã ã®éžæã¯éåžžã«åºãã§ãã ã¹ã¿ãã¯ãæ§ç¯ããã«ã¯ãã³ã³ããã§é©åã«æ©èœãããªãŒãã³ãœãŒã¹ãµãŒãã¹ã䜿çšããŸãã 次ã«ãã¹ã¿ãã¯ã®æ§æã«ã€ããŠèª¬æããŸãã
cAdvisor
cAdvisorã¯ãã¹ããšã³ã³ãããŒã®ã¡ããªãã¯ãåéããŸãã ãã¹ãäžã®å
±æããªã¥ãŒã ããã³ã«ãŒããã¡ã€ã«ã·ã¹ãã ãšããŠæ¥ç¶ãããããã«ãŒãœã±ãããåããããã«ãŒã€ã¡ãŒãžãšããŠã€ã³ã¹ããŒã«ãããŸãã cAdvisorã¯ãInfluxDBãPrometheusãªã©ãå«ãããã€ãã®ã¿ã€ãã®æç³»åããŒã¿ããŒã¹ã«åéãããã¡ããªãã¯ãèšé²ã§ããŸããåéãããããŒã¿ããã°ã©ããæ§ç¯ãããWebã€ã³ã¿ãŒãã§ã€ã¹ãåããŠããŸãã
Influxdb
ãªã¢ã«ã¿ã€ã ã®ã¡ããªãã¯ãã€ãã³ããããã³åæçšã®ã¹ã±ãŒã©ãã«ãªã¹ãã¬ãŒãžã
InfluxDBã¯ãæ°å€ã¡ããªãã¯ãä¿åãããããã«ã¿ã°ãå²ãåœãŠããªãŒãã³ãœãŒã¹ã®æç³»åããŒã¿ããŒã¹ã§ãã ãã®ã·ã¹ãã ã¯ãä¿åãããããŒã¿ã®æäœã«äœ¿çšã§ããSQLã«äŒŒãã¯ãšãªèšèªãå®è£
ããŠããŸãã ãã¹ããŸãã¯ã³ã³ããã§ã¿ã°ã䜿çšããŠã€ãã³ãããã£ã«ã¿ãªã³ã°ããŸãã
ã°ã©ãã¡ã
Grafanaã¯ãGraphiteãElasticsearchãOpenTSDBãPrometheusãInfluxDBããååŸããã¡ããªãã¯ã«åºã¥ããŠããŒã«ããŒãšã°ã©ããäœæã§ããå€æ©èœã®ãªãŒãã³ãœãŒã¹ã·ã¹ãã ã§ãã
Grafanaã¯ãGraphiteãElasticsearchãOpenTSDBãPrometheusããããŠãã¡ããInfluxDBããããŒã¿ãååŸããããšã§ããŒã«ããŒãäœæã§ããäžè¬çãªèŠèŠåããŒã«ã§ãã 4çªç®ã®ããŒãžã§ã³ãããã¯ãšãªçµæã«åºã¥ããŠã¢ã©ãŒããæ§æã§ããããã«ãªããŸããã ç¹å®ã®ãã¹ããšãµãŒãã¹ã®ããŒã¿ã衚瀺ã§ããããŒã«ããŒãäœæããŸãã
Docker Swarmã¢ãŒã
Swarm Mode
ãããŒãžã§ã³1.12.0以éãDockerã«ç»å ŽããŠããŸãã è€æ°ã®ãã¹ãããç°¡åã«çŸ€ããäœæããç°¡åã«ç®¡çã§ããŸãã ãµãŒãã¹ãšãªãŒã±ã¹ãã¬ãŒã·ã§ã³ãæ€åºããããã®çµã¿èŸŒã¿ã¡ã«ããºã ãæäŸããããã«ãSwarmã¢ãŒãã¯ããŒãšå€ã®ã¹ãã¬ãŒãžãå®è£
ããŠããŸãã ãã¹ãã¯ããããŒãžã£ãŒãŸãã¯äœæ¥ããŒããšããŠæ©èœã§ããŸãã äžè¬ã«ããããŒãžã£ãŒã¯ãªãŒã±ã¹ãã¬ãŒã·ã§ã³æ©èœãæ
åœããã³ã³ãããŒã¯äœæ¥ããŒãã§å®è¡ãããŸãã ããã¯ãã¢ã€ã³ã¹ããŒã«ãªã®ã§ããããŒãžã£ãŒã«InfluxDBãšGrafanaãé
眮ããŸãã
Swarm Modeã«ã¯ãä»®æ³ããŒããã©ã³ãµãŒãšããŠæ©èœããèå³æ·±ãã«ãŒãã£ã³ã°ã¡ãã·ã¥æ©èœããããŸãã 5ã€ã®ããŒãã§å®è¡ãããããŒã80ã§ãªãã¹ã³ãã10åã®ã³ã³ãããŒããããšããŸãã ãããã®ã³ã³ããã®ããããã®80çªç®ã®ããŒãã«ã¢ã¯ã»ã¹ããããšãããšãèŠæ±ã¯ãããã®ããããã«éä¿¡ãããå¥ã®ãã¹ãã§å®è¡ãããŠããå ŽåããããŸãã ãããã£ãŠãä»»æã®ããŒãã®IPã¢ãã¬ã¹ãå
¬éããããšã«ããã10åã®ã³ã³ãããŒéã®ã¯ãšãªãã©ã³ã·ã³ã°ãèªåçã«æå¹ã«ããŸãã
ãã®ãã¢ã§æå®ãããã³ãã³ããã·ã¹ãã ã§åå¥ã«å®è¡ããäºå®ãããå Žåã¯ã次ã®ããã°ã©ã ãå¿
èŠã§ãã
- Docker ïŒversion> = 1.13ïŒDocker Compose FileããŒãžã§ã³3ããã³Swarmã¢ãŒãã®å ŽåïŒ;
- Docker Machine ïŒããŒãžã§ã³> = 0.8;
- Docker Compose ïŒversion> = 1.10ïŒDocker Compose FileããŒãžã§ã³3ã®å ŽåïŒã
swarmã¯3ã€ã®ããŒã«ã«ä»®æ³ãã·ã³ã§æ§æããã Virtualbox docker-machine ãã©ã°ã€ã³ã䜿çšããŠãããã€ããŸãã ãããè¡ãã«ã¯ã Virtualboxä»®æ³åãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã ä»ã®ãã©ã°ã€ã³ã䜿çšããŠãã¯ã©ãŠããµãŒãã¹ã«ä»®æ³ãã·ã³ããããã€ã§ããŸãã ãã·ã³ãäœæããåŸã®æé ã¯ããã¹ãŠã®ãã©ã°ã€ã³ã§åãã§ãã docker-machineã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
ä»®æ³ãã·ã³ãäœæãããšããããã©ã«ãã®ãªãã·ã§ã³ã®ãŸãŸã«ããŸãã å©çšå¯èœãªãªãã·ã§ã³ã®è©³çŽ°ã«ã€ããŠã¯ã ãããã¯ãªãã¯ããŠãã ãã ã swarm managerãšããŠæ©èœãããã¹ãã¯managerãšåŒã°ããäœæ¥ããŒãã¯agent1ãšagent2ã§ãã å¿
èŠãªæ°ã®ããŒããäœæã§ããŸãã äžèšã®ã³ãã³ããå¥ã®ãã¹ãåã§ç¹°ãè¿ããŸãã ä»®æ³ãã·ã³ãäœæããã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
docker-machine create manager docker-machine create agent1 docker-machine create agent2
ãããã®ã³ãã³ãã®å®äºã«ã¯æéããããå ŽåããããŸãã ãã·ã³ãäœæãããšã docker-machine ls
åºåã¯æ¬¡ã®ããã«ãªããŸãã
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS agent1 - virtualbox Running tcp://192.168.99.101:2376 v17.03.1-ce agent2 - virtualbox Running tcp://192.168.99.102:2376 v17.03.1-ce manager - virtualbox Running tcp://192.168.99.100:2376 v17.03.1-ce
ãããŒãžã£ãŒãã¹ãã§dockerãšã³ãžã³ã䜿çšããã«ã¯ãã³ã³ããã¹ããåãæ¿ããå¿
èŠããããŸãã 次ã«ãããŒã«ã«ã·ã¹ãã ã§ã¯ãªãã ãããŒãžã£ãŒãã¹ãã«ã€ã³ã¹ããŒã«ãããdockerã§ã³ãã³ããå®è¡ããŸãã ãããè¡ãã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
eval `docker-machine env manager`
managerã§dockerã«åãæ¿ããã®ã§ããã®ãã¹ããswarmãããŒãžã£ãŒãšããŠåæåããŸãã ä»ã®æ¥ç¶ãããããŒãã§å
¬éãããIPãå¿
èŠã«ãªããŸãã docker-machine ip manager
ã¯ãå¿
èŠãªæ
å ±ãæäŸããŸãã ãããã£ãŠãã¹ãŠã©ãŒã ãäœæããã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
docker swarm init --advertise-addr `docker-machine ip manager`
次ã«ã2ã€ã®äœæ¥ããŒããå¿
èŠã§ãã ãããè¡ãã«ã¯ãswarmã®äœææã«å
¬éãããJoin TokenãšIPãæž¡ãå¿
èŠããããŸãã ããŒã¯ã³ãååŸããã«ã¯ã docker swarm join-token -q worker
çºè¡ãdocker swarm join-token -q worker
ã åè¿°ã®docker-machine ip manager
ã䜿çšãããšãIPãããŒãžã£ãŒãšãã®æšæºããŒã2377ãååŸã§ããŸããåã¯ãŒã¯ããŒãã®ã³ã³ããã¹ãã«é çªã«åãæ¿ããŠãæ°ãããã·ã³ãswarmã«è¿œå ã§ããŸãããSSHãä»ããŠãããã®ã³ãã³ããå®è¡ããæ¹ãã¯ããã«ç°¡åã§ãã äœæ¥ããŒããswarmã«æ¥ç¶ããã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
docker-machine ssh agent1 docker swarm join --token `docker swarm join-token -q worker` `docker-machine ip manager`:2377 docker-machine ssh agent2 docker swarm join --token `docker swarm join-token -q worker` `docker-machine ip manager`:2377
swarmã«å«ãŸããããŒãã®ãªã¹ãã¯ã docker node ls
ã§docker node ls
ã§ããŸãã äœæ¥ããŒããè¿œå ãããšãåºåã¯æ¬¡ã®ããã«ãªããŸãã
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 3j231njh03spl0j8h67z069cy * manager Ready Active Leader muxpteij6aldkixnl31f0asar agent1 Ready Active y2gstaqpqix1exz09nyjn8z41 agent2 Ready Active
Dockerã¹ã¿ãã¯
3çªç®ã®ããŒãžã§ã³ã®docker-composeãã¡ã€ã«ã1ã€ã®ãã¡ã€ã«ã«å«ãããšãå±éæŠç¥ãå«ããµãŒãã¹ã¹ã¿ãã¯å
šäœãå®çŸ©ãã1ã€ã®deployã³ãã³ãã§å±éã§ããŸãã docker-composeãã¡ã€ã«ã®3çªç®ã®ããŒãžã§ã³ãš2çªç®ã®ããŒãžã§ã³ã®äž»ãªéãã¯ãåãµãŒãã¹ã®èª¬æã«ããdeployãã©ã¡ãŒã¿ãŒã®å€èŠ³ã§ãã ãã®èšå®ã«ãããã³ã³ããã®å±éæ¹æ³ã決ãŸããŸãã ãã¹ãç£èŠã·ã¹ãã ã®docker-composeãã¡ã€ã«ã以äžã«ç€ºããŸãã
version: '3' services: influx: image: influxdb volumes: - influx:/var/lib/influxdb deploy: replicas: 1 placement: constraints: - node.role == manager grafana: image: grafana/grafana ports: - 0.0.0.0:80:3000 volumes: - grafana:/var/lib/grafana depends_on: - influx deploy: replicas: 1 placement: constraints: - node.role == manager cadvisor: image: google/cadvisor hostname: '{{.Node.ID}}' 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/docker/:/var/lib/docker:ro depends_on: - influx deploy: mode: global volumes: influx: driver: local grafana: driver: local
ã¹ã¿ãã¯ã«ã¯3ã€ã®ãµãŒãã¹ãããã以äžã§èª¬æããŸãã
æµå
¥
ããã§ã¯ã influxdbã€ã¡ãŒãžã䜿çšããŸãã æ°žç¶çãªã¹ãã¬ãŒãžã®å Žåãã³ã³ãããã©ã«ã/ var / lib / influxdbã«ããŠã³ããããæµå
¥ããªã¥ãŒã ãäœæããŸãã ãããŒãžã£ãŒãã¹ãã§ãã¹ããããInfluxDBã®ã³ããŒã1ã€ã ãå¿
èŠã§ãã DockerãµãŒããŒã¯åããã¹ãã§å®è¡ãããŠãããããã³ã³ãããŒã®ã³ãã³ãã¯ããã§å®è¡ã§ããŸãã æ®ãã®äž¡æ¹ã®ãµãŒãã¹ã«ã¯influxDBãå¿
èŠã§ããããããããã®ãµãŒãã¹ã®èª¬æã«depend_onããŒãšå€influxãè¿œå ããŸãã
ã°ã©ãã¡ã
grafana / grafanaã€ã¡ãŒãžã䜿çšããŠãã³ã³ããã®3000çªç®ã®ããŒãããã¹ãã®80çªç®ã®ããŒãã«è»¢éããŸãã ã«ãŒãã°ãªããã䜿çšãããšãã¹ãŠã©ãŒã ã®äžéšã§ãããã¹ãã®80çªç®ã®ããŒããä»ããŠgrafanaã«æ¥ç¶ã§ããŸãã ããŒã¿ãæ°žç¶çã«ä¿åããã«ã¯ã grafanaãšããå¥ã®ããªã¥ãŒã ãäœæããŸãã ã³ã³ãããã©ã«ã/ var / lib / grafanaã«ããŠã³ããããŸãã ãŸããGrafanaããããŒãžã£ãŒãã¹ãã«å±éããŸãã
æå°è
cAdvisorãã»ããã¢ããããã«ã¯ã以åã®ãµãŒãã¹ãããå°ãå€ãäœæ¥ããå¿
èŠããããŸãã 詳现ã«ã€ããŠã¯ã ãã®ãªã³ã¯ãåç
§ããŠãã ãã ã ãã®å Žåã ãã¹ãåã®å€ãéžæããã®ã¯ç°¡åãªããšã§ã¯ãããŸããã åããŒãã«ãšãŒãžã§ã³ããã€ã³ã¹ããŒã«ããŸãããã®ã³ã³ããã¯ãããŒããšãã®ããŒãã§å®è¡ãããŠããã³ã³ããã®ã¡ããªãã¯ãåéããŸãã cAdvisorãã¡ããªãã¯ãInfluxDBã«éä¿¡ãããšããcAdvisorãå«ãã³ã³ããã®ååãå«ããã·ã³ã¿ã°ãèšå®ããŸãã ãã®å€ã¯ãå®è¡äžã®ããŒãã®IDã«å¯Ÿå¿ããå¿
èŠããããŸãã Dockerã¹ã¿ãã¯ã¯ãååã«ãã¿ãŒã³ã䜿çšã§ããŸãã 詳现ã¯ãã¡ããã芧ãã ãã ã ã³ã³ããã«ã¯ãå®è¡äžã®ããŒãã®IDãå«ãååãä»ããŸãããããã«ãããã¡ããªãã¯ã®ååŸå
ãç¹å®ã§ããŸãã ããã¯ã次ã®åŒ'{{.Node.ID}}'
ã䜿çšããŠå®çŸãããŸãã
ãŸããcadvisorã«ããã€ãã®ã³ãã³ãã©ã€ã³ãªãã·ã§ã³ãè¿œå ããŸãã logtostderrãã©ã¡ãŒã¿ãŒã¯ãçæãããcadvsiorãã°ãstderrã«ãªãã€ã¬ã¯ããããããã°ãç°¡çŽ åããŸãã docker_onlyãã©ã°ã¯ã Dockerã³ã³ããã«ã®ã¿é¢å¿ãããããšã瀺ããŠããŸãã 次ã®3ã€ã®ãã©ã¡ãŒã¿ãŒã¯ãåéãããã¡ããªãã¯ãé
眮ãããªããžããªå
ã®å Žæã決å®ããŸãã cAdvisorã«ã influxïŒ8086ã§ãªãã¹ã³ããŠããInfluxDBãµãŒããŒäžã®cadvisorããŒã¿ããŒã¹ã«ããããé
眮ããããã«äŸé ŒããŸãã ããã«ãããã¹ã¿ãã¯ã®æµå
¥ãµãŒãã¹ãžã®ã¡ããªãã¯ã®éä¿¡ãæ§æã§ããŸãã ã¹ã¿ãã¯å
ã§ã¯ããã¹ãŠã®ããŒããå
¬éïŒå
¬éïŒããããããåå¥ã«æå®ããå¿
èŠã¯ãããŸããã
ããªã¥ãŒã ãã¡ã€ã«ã§æå®ãããããªã¥ãŒã ã¯ããã¹ããšããã«ãŒããã¡ããªãã¯ãåéããããã«cAdvisorã«å¿
èŠã§ãã cadvisorãå±éããã«ã¯ã ã°ããŒãã«ã¢ãŒãã䜿çšããŸãã ããã«ãããåSwarmããŒãã§cadvisorãµãŒãã¹ã®1ã€ã®ã€ã³ã¹ã¿ã³ã¹ã®ã¿ãå®è¡ãããŸãã
ãã¡ã€ã«ã®æåŸã«ããªã¥ãŒã ããŒãããã æµå
¥ããŒãšã°ã©ããããªã¥ãŒã ã瀺ããŠããŸãã äž¡æ¹ã®ããªã¥ãŒã ã¯ãããŒãžã£ãŒãã¹ãã§ãã¹ããããããã ããŒã«ã«ãã©ã€ããŒãäœæããŸãã
ã¹ã¿ãã¯ããããã€ããã«ã¯ãäžèšã®ãã¡ã€ã«ãdocker-stack.ymlãšããååã§ä¿åãã次ã®ã³ãã³ããå®è¡ããŸãã
docker stack deploy -c docker-stack.yml monitor
ã¢ãã¿ãŒã¹ã¿ãã¯ã®ãµãŒãã¹ãéå§ããŸãã ããŒãã¯ã³ã³ããã€ã¡ãŒãžãããŒãããå¿
èŠããããããã³ãã³ãã®æåã®å®è¡ã«ã¯æéããããå ŽåããããŸãã ãŸããcadvisorãšåŒã°ããã¡ããªãã¯ãä¿åããããã®ããŒã¿ããŒã¹ãInfluxDBã«äœæããå¿
èŠããããŸãã
docker exec `docker ps | grep -i influx | awk '{print $1}'` influx -execute 'CREATE DATABASE cadvisor'
ã³ãã³ãã®å®è¡ã¯ã æµå
¥ã³ã³ãããååšããªããšããã¡ãã»ãŒãžã§å€±æããå ŽåããããŸãã ãã®ãšã©ãŒã®çç±ã¯ãã³ã³ããã®æºåããŸã æŽã£ãŠããªãããšã§ãã å°ãåŸ
ã£ãŠããã³ãã³ããåå®è¡ããŠãã ããã influxãµãŒãã¹ã¯ãããŒãžã£ãŒãã¹ãã§å®è¡ãããŠãããããã«ã€ã³ã¹ããŒã«ãããŠããdockerã䜿çšãããããã³ãã³ããå®è¡ã§ããŸãã InfluxDBã§ã³ã³ãããŒIDã確èªããã«ã¯ãdocker docker ps | grep -i influx | awk '{print $1}'
docker ps | grep -i influx | awk '{print $1}'
docker ps | grep -i influx | awk '{print $1}'
ã cadvisorãšããããŒã¿ããŒã¹ãäœæããã«ã¯ã influx -execute 'CREATE DATABASE cadvisor'
ãå®è¡ããå¿
èŠããããŸãã
ã¹ã¿ãã¯ãµãŒãã¹ãäžèŠ§è¡šç€ºããã«ã¯ã docker stack services monitor
ãŸãã ã³ãã³ãããã®åºåã¯æ¬¡ã®ããã«ãªããŸãã
ID NAME MODE REPLICAS IMAGE 0fru8w12pqdx monitor_influx replicated 1/1 influxdb:latest m4r34h5ho984 monitor_grafana replicated 1/1 grafana/grafana:latest s1yeap330m7e monitor_cadvisor global 3/3 google/cadvisor:latest
å®è¡äžã®ã³ã³ããã®ãªã¹ãã¯ã docker stack ps monitor
ã³ãã³ãã§ååŸã§ããŸããåºåã¯æ¬¡ã®ããã«ãªããŸãã
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS n7kobaozqzj6 monitor_cadvisor.y78ac29r904m8uy6hxffb7uvn google/cadvisor:latest agent2 Running Running about a minute ago 1nsispop3hsu monitor_cadvisor.z52c9vloiutl5dbuj5lnykzvl google/cadvisor:latest agent1 Running Running about a minute ago 9n6djc80mamd monitor_cadvisor.qn82bfj5cpin2cpmx9qv1j56s google/cadvisor:latest manager Running Running about a minute ago hyr8piriwa0x monitor_grafana.1 grafana/grafana:latest manager Running Running about a minute ago zk7u8g73ko5w monitor_influx.1 influxdb:latest manager Running Running about a minute ago
Grafanaã®ã»ããã¢ãã
ãã¹ãŠã®ãµãŒãã¹ããããã€ãããããgrafanaãéãããšãã§ããŸãã ããã«ã¯ãSwarmããŒãã®IPãé©ããŠããŸãã 次ã®ã³ãã³ããå®è¡ããŠIPãããŒãžã£ãŒãæå®ããŸãã
open http://`docker-machine ip manager`
ããã©ã«ãã§ã¯ããŠãŒã¶ãŒåadminãšãã¹ã¯ãŒãadminãgrafanaãžã®ãã°ã€ã³ã«äœ¿çšãããŸãã grafanaã§ã¯ãInfluxDBãããŒã¿ãœãŒã¹ãšããŠè¿œå ããå¿
èŠããããŸãã ããŒã ããŒãžã«[ æåã®ããŒã¿ãœãŒã¹ãäœæ ]ãªã³ã¯ããããŸã ããããã¯ãªãã¯ããŸãã ãªã³ã¯ããªãå Žåã¯ã[ ããŒã¿ãœãŒã¹ ]ã¡ãã¥ãŒãã[ ããŒã¿ãœãŒã¹ã®è¿œå ]ãéžæããŸããããã«ãããæ°ããããŒã¿ãœãŒã¹ãè¿œå ããããã®ãã©ãŒã ãéããŸãã
Grafanaãžã®ããŒã¿ãœãŒã¹ã®è¿œå
ããŒã¿ãœãŒã¹ã«ã¯ä»»æã®ååãä»ããããšãã§ããŸãã ããã©ã«ãã®ãã§ãã¯ããã¯ã¹ããªã³ã«ããŠãä»åŸä»ã®ãã©ãŒã ã§æå®ããå¿
èŠããªãããã«ããŸãã 次ã«ãTypeãInfluxDB ãURL- httpïŒ// influxïŒ8086ããã³Access- proxyã«èšå®ããŸãã ãã®ãããInfluxDbã³ã³ãããŒãæããŸããã [ããŒã¿ããŒã¹]ãã£ãŒã«ãã«ã cadvisorããšå
¥åãã[ ä¿åããŠãã¹ã ]ãã¯ãªãã¯ããŸã -[ ããŒã¿ãœãŒã¹ãæ©èœããŠããŸã]ãšããã¡ãã»ãŒãžã衚瀺ãããŸãã
ãããžã§ã¯ãã®githubãªããžããªã«ã¯ãGrafanaã«ã€ã³ããŒãããããã«äœæãããdashboard.jsonãã¡ã€ã«ããããŸãã Swarmã§å®è¡ãããã·ã¹ãã ãšã³ã³ãããç£èŠããããã®ããŒã«ããŒã«ã€ããŠèª¬æããŸãã 次ã«ããã®ããŒã«ããŒãã€ã³ããŒãããŠã次ã®ã»ã¯ã·ã§ã³ã§èª¬æããŸãã [ ããã·ã¥ããŒã ]ã¡ãã¥ãŒé
ç®ã«ã«ãŒãœã«ãåããã[ ã€ã³ããŒããªãã·ã§ã³ ]ãéžæããŸãã [ .jsonãã¡ã€ã«ã®ã¢ããããŒã ]ãã¿ã³ãã¯ãªãã¯ããŠã dashboard.jsonãéžæããŸãã 次ã«ãããŒã¿ãœãŒã¹ãéžæãã[ ã€ã³ããŒã ]ãã¿ã³ãã¯ãªãã¯ããŸãã
Grafanaããã·ã¥ããŒã
Grafanaããã·ã¥ããŒã
Grafanaã«ã€ã³ããŒããããããŒã«ããŒã¯ãSwarmã®ãã¹ããšã³ã³ãããŒãç£èŠããããã«èšèšãããŠããŸãã ãã¹ãã¬ãã«ãšãã®äžã§å®è¡ãããŠããã³ã³ããã«ããªã«ããŠã³ã§ããŸãã 2ã€ã®å€æ°ãå¿
èŠã«ãªããŸããããããGrafanaããŒã«ããŒã«è¿œå ããã«ã¯ããã³ãã¬ãŒããæäœããæ©èœãå¿
èŠã§ãã InfluxDBãšçµã¿åããããã³ãã¬ãŒãã®æäœã«é¢ãã詳现ã¯ã ãã®ããŒãžã«ãããŸã ã ããŒããéžæãããã¹ããšã ã³ã³ãããéžæããã³ã³ããã®2ã€ã®å€æ°ããããŸãã ãããã®å€æ°ã衚瀺ããã«ã¯ãããŒã«ããŒããŒãžã§[ èšå®]ãéžæãã[ ãã³ãã¬ãŒã ]ãã¯ãªãã¯ããŸãã
æåã®å€æ°-host-ã§ã¯ãããŒããšãã®ã¡ããªãã¯ãéžæã§ããŸãã cAdvisorãInfluxDBã«ã¡ããªãã¯ãéä¿¡ãããšããã£ã«ã¿ãªã³ã°ã«äœ¿çšã§ããããã€ãã®ã¿ã°ãã¡ããªãã¯ã«è¿œå ãããŸãã cAdvisorã€ã³ã¹ã¿ã³ã¹ã®ãã¹ãåãå«ãmachineãšããã¿ã°ããããŸãã ãã®å Žåãswarmã®ãã¹ãIDãšäžèŽããŸãã ã¿ã°å€ãååŸããã«ã¯show tag values with key = "machine"
ã¯ãšãªã§show tag values with key = "machine"
䜿çšããŸãã
2çªç®ã®å€æ°-container-ã¯ãã³ã³ããã®ã¬ãã«ãŸã§ããªã«ããŠã³ã§ããŸãã container_nameãšããååã®ã¿ã°ããããã³ã³ãããŒã®ååãäºæ³ã©ããã«å«ãŸããŠããŸãã ãŸãããã¹ãã¿ã°ã®å€ã§ã¡ããªãã¯ããã£ã«ã¿ãªã³ã°ããå¿
èŠããããŸãã ãªã¯ãšã¹ãã¯æ¬¡ã®ããã«ãªããŸãïŒ show tag values with key = "container_name" WHERE machine =~ /^$host$/
ã ãã¹ãå€æ°ã«é¢å¿ã®ãããã¹ãã®ååãå«ãŸããã³ã³ããã®ãªã¹ããè¿ãããŸãã
ã³ã³ããåã¯æ¬¡ã®ããã«ãªããŸãã
monitor_cadvisor.y78ac29r904m8uy6hxffb7uvn.3j231njh03spl0j8h67z069cy ãã ããé¢å¿ãããã®ã¯monitor_cadvisoréšåã®ã¿ã§ãïŒæåã®ç¹ãŸã§ïŒã åããµãŒãã¹ã®è€æ°ã®ã€ã³ã¹ã¿ã³ã¹ãå®è¡ãããŠããå Žåããããã®ããŒã¿ãå¥ã
ã®è¡ã«è¡šç€ºããå¿
èŠããããŸãã éšåæååãæåã®ãã€ã³ããŸã§ååŸããã«ã¯ãæ£èŠè¡šçŸ/([^.]+)/
䜿çšããŸãã
å€æ°ãèšå®ããããã°ã©ãã§äœ¿çšã§ããããã«ãªããŸããã ããã«ã ã¡ã¢ãªã°ã©ãã£ãã¯ã¹ã«ã€ããŠã説æããŸãããæ®ãã«ã€ããŠãåãåçã§äœæ¥ã§ããŸãã ã¡ã¢ãªé¢é£ã®ããŒã¿ã¯InfluxDBã®memory_usageè¡ã«ãããããã¯ãšãªã¯SELECT "value" FROM "memory_usage"
ãŸãã
ããã§ã WHEREå¥ã«ãã£ã«ã¿ãŒãè¿œå ããå¿
èŠããããŸãã æåã®æ¡ä»¶ã¯ã machineã ãã¹ãå€æ°ã®å€ãšçããããšã§ãïŒ "machine" =~ /^$host$/
ã 次ã®æ¡ä»¶ã§ã¯ã container_nameã¯containerå€æ°ã®å€ã§å§ãŸãå¿
èŠããããŸãã ããã§ã¯ã ã³ã³ããå€æ°ãæåã®ãã€ã³ãã«ãã£ã«ã¿ãŒããããããstarts withãæŒç®åã䜿çšããŸãïŒ "container_name" =~ /^$container$*/
ã åŸè
ã®æ¡ä»¶ã¯ãgrafanaããŒã«ããŒã§éžæãããæééé$ timeFilterã«åŸã£ãŠã€ãã³ãã«æéå¶éã課ããŸãã ã¯ãšãªã¯æ¬¡ã®ããã«ãªããŸãã
SELECT "value" FROM "memory_usage" WHERE "container_name" =~ /^$container$*/ AND "machine" =~ /^$host$/ AND $timeFilter
ãã¹ããšã³ã³ããããšã«å¥ã
ã®è¡ãå¿
èŠãªã®ã§ã machineã¿ã°ãšcontainer_nameã¿ã°ã®å€ã«åºã¥ããŠããŒã¿ãã°ã«ãŒãåããå¿
èŠããããŸãã
SELECT "value" FROM "memory_usage" WHERE "container_name" =~ /^$container$*/ AND "machine" =~ /^$host$/ AND $timeFilter GROUP BY "machine", "container_name"
ãã®ã¯ãšãªã®ãšã€ãªã¢ã¹ïŒ Memory {host: $tag_machine, container: $tag_container_name}
ãäœæããŸããã ããã§ã $ tag_machineã¯machineã¿ã°ã®å€ã«ã tag_container_nameã¯container_nameã¿ã°ã®å€ã«çœ®ãæããããŸãã æ®ãã®ã°ã©ããåæ§ã®æ¹æ³ã§æ§æãããã·ãªãŒãºïŒã·ãªãŒãºïŒã®ååã®ã¿ãå€æŽãããŸãã Grafanaã§ãããã®ã¡ããªãã¯ã®ã¢ã©ãŒããäœæã§ããŸãã ã¢ã©ãŒãã·ã¹ãã ïŒã¢ã©ãŒãïŒã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããåç
§ããŠãã ãã ã
ãããã«
ãã®èšäºã§ã¯ãDocker Swarmã®ã¹ã±ãŒã©ãã«ãªç£èŠã·ã¹ãã ãäœæããŸãããããã¯ãswarmã«å«ãŸãããã¹ãŠã®ãã¹ããšã³ã³ãããŒããã¡ããªãã¯ãèªåçã«åéããŸãã ãã®éçšã§ã人æ°ã®ãããªãŒãã³ãœãŒã¹ããŒã«ã§ããGrafanaãInfluxDBãcAdvisorã«äŒããŸããã
ãã¢ãå®äºããåŸã次ã®ã³ãã³ãã§ã¹ã¿ãã¯ãåé€ã§ããŸãã
docker stack rm monitor
äžèŠãªä»®æ³ãã·ã³ã¯ã次ã®ã³ãã³ãã§åæ¢ããã³åé€ãããŸãã
docker-machine stop manager agent1 agent2 docker-machine rm -f manager agent1 agent2
åç
§ïŒ
- ãªãªãžãã«ïŒ cAdvisorãInfluxDBãGrafanaã䜿çšããDocker Swarmã®ç£èŠ ã