Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Monitoring Docker with Mackerel (2015 ver.)

Monitoring Docker with Mackerel (2015 ver.)

クラウドごった煮 2015/3/28

A76985bd77fecba82109dee506b1fec2?s=128

Shinji Tanaka

March 29, 2015
Tweet

Transcript

  1. Monitoring Docker with Mackerel 
 2015೥ฤ Ϋϥ΢υͬͨࣽ͝ #11, 2015/03/28 Hatena

    Co., Ltd. Shinji Tanaka @stanaka
  2. Shinji Tanaka / ాத৻࢘ @stanaka / id:stanaka גࣜձࣾ͸ͯͳ ࣥߦ໾һCTO 2

  3.  ͋͋ ࠷ۙɺిࢠ൛΋ग़ͨΑ͏Ͱ͢

  4. Agenda • Docker (cgroup) Statics • Host/Container Patterns • Monitoring

    Docker with Mackerel
  5. 1 Docker (cgroup) Statistics

  6. DockerͷϞχλϦϯάͷجຊ • cgroupͷ࡞๏ʹै͏ • ίϯςφଆ͔Β͸ɺϗετશମ͔͠ ݟ͑ͳ͍ • /proc/loadavg,  /proc/stat  

    • ݟ͍ͨ৔߹͸`-­‐v`ͰऔΓࠐΉ
  7. ϗετଆ͔ΒͷϞχλϦϯά • cgroupͷϨϙʔτΛར༻ • /sys/fs/cgroup/
          {cpuacct,

     memory}   • ଞʹblkio,  cpu,  devicesͳͲͷα ϒγεςϜ͕͋Δ(֤छ੍ݶͳͲͷ੍ ޚ༻) VCVOUVͷ৔߹
 LFSOFMHFOFSJDEPDLFS
  8. CPU࢖༻཰ • /sys/fs/cgroup/cpuacct/docker/{ίϯςφID}/cpuacct.stat ! ! ! • user … ϢʔβʔϞʔυͷCPU

    ࣌ؒ • system … γεςϜϞʔυͷCPU ࣌ؒ • CPU࣌ؒͷ୯Ґ: USER_HZ (σϑΥϧτ͸10ms) user  480   system  116
  9. cpuacctͷଞͷࢦඪ • cpuacct.usage: ૯CPU࣌ؒ (φϊඵ)
 echo 0 > /cgroup/cpuacct/cpuacct.usage 


    ͰϦηοτ • cpuacct.usage_percpu: ֤CPUͷCPU ࣌ؒ (φϊඵ)
  10. ϝϞϦ࢖༻཰ • /sys/fs/cgroup/memory/docker/{ίϯςφID}/memory.stat cache  761856   rss  25681920   rss_huge

     0   mapped_file  16384   pgpgin  12569   …   total_cache  761856   total_rss  25681920   …   ͍ΘΏΔ344STT NBQQFE@pMF
  11. memory.statৄࡉ • cache   • rss   • mapped_file  

    • pgpgin   • pgpgout   • swap   • active_anon   • inactive_anon   • active_file   • inactive_file   • unevictable   • hierarchical_memory _limit   • hierarchical_memsw   • total_͸ࢠάϧʔϓΛ ؚΉ஋ ৄࡉIUUQTXXXLFSOFMPSHEPD%PDVNFOUBUJPODHSPVQTNFNPSZUYU
  12. memoryؔ࿈(ͦͷଞ) memory.usage_in_bytes ϝϞϦ࢖༻ྔ memory.memsw.usage_in_bytes ϝϞϦ࢖༻ྔͱεϫοϓྖҬͷ࿨ memory.max_usage_in_bytes ϝϞϦ࠷େ࢖༻ྔ memory.memsw.max_usage_in_bytes εϫοϓ࠷େ࢖༻ྔ memory.limit_in_bytes

    ϝϞϦͷ੍ݶ஋ memory.memsw.limit_in_bytes ϝϞϦͱεϫοϓ੍ݶ஋ memory.failcnt ϝϞϦ੍ݶ஋ʹୡͨ͠ճ਺ memory.memsw.failcnt ϝϞϦ੍ݶ஋ʹୡͨ͠ճ਺
  13. ڞ௨Ϩϙʔτ • tasks ࣮ߦதͷϓϩηεͷҰཡ(PID) • cgroup.procs ࣮ߦதͷεϨουάϧʔϓͷҰཡ(TGID) %  cat  /sys/fs/cgroup/memory/docker/…./cgroup.procs

      31218   31307   %  ps  aux  |  egrep  '(31218|31307)'   root          31218    0.0    0.0      4408      164  ?                Ss      13:15      0:00  /bin/sh  -­‐ c  rackup  -­‐p4567   root          31307    0.0    5.2  281364  26336  ?                Sl      13:15      0:06  ruby1.9.1   /usr/local/bin/rackup  -­‐p4567
  14. 2 Host/Container Patterns

  15. ϗετͱίϯςφͷؔ܎ • 1:n • CIαʔόɾ։ൃαʔόͳͲ • 1:1 • ϓϩμΫγϣϯ؀ڥͳͲ

  16. Pattern 1:n • CIαʔόɾ։ൃαʔό • ίϯςφԾ૝Խ؀ڥΛଟ਺ಈ࡞ • ಠཱͨ͠؀ڥ • ىಈఀࢭ͕ߴ଎

    • Ϧιʔεͷڞ༗ʹΑΔޮ཰Խ
  17. Pattern 1:n • CIαʔόɾ։ൃαʔό )PTU "QQ qVFOUE NBDLFSFM BHFOU "QQ

    +FOLJOT
  18. Pattern 1:1 • ίϯςφԾ૝؀ڥΛҰͭͷΈಈ࡞ • ϦιʔεΛಠ઎ • ؀ڥߏங໘ʹಛԽ • ϓϩμΫγϣϯ؀ڥʹ߹͏

    • AWS BeanstalkͷDocker support
  19. Pattern 1:1 • ϓϩμΫγϣϯαʔό )PTU qVFOUE NBDLFSFM BHFOU "QQ

  20. 3 Monitoring Docker with Mackerel

  21. Mackerel https://mackerel.io/

  22. ಛ௃ • ʮ໾ׂʯʹΑΔϗετ܈ͷ؅ཧ • ΤʔδΣϯτʹΑΔϦιʔε؂ࢹ ϩ ʔ ϧ

  23. ϩʔϧຖͷάϥϑͰՄࢹԽ

  24. mackerel-agent • Go Ͱॻ͔ΕͨެࣜΤʔδΣϯτ • Linux αϙʔτ (CentOS 5/6, Debian

    6/7) • ϗετεϖοΫͱϝτϦοΫΛऩू mackerelio/mackerel-agent
  25. Blue-green DeploymentରԠ • ϩʔϧ୯ҐͰͷՄࢹԽ • ୀ໾ࡁΈίϯςφͷάϥϑ΋อ࣋ Deployment

  26. ΦʔτεέʔϧରԠ • αʔό͕ॖୀͯ͠΋άϥϑ͸࢒Δ

  27. Raspberry Pi Ͱ΋ಈ͖·͢ • Թ౓ɾ࣪౓ηϯα → Slack௨஌

  28. Docker
 with Mackerel

  29. mackerel/mackerel-agent on Docker Hub https://registry.hub.docker.com/u/stanaka/mackerel-­‐agent/

  30. How to Use • ίϚϯυҰൃ • ඞཁͳύεɾAPIKEYΛ౉͢ docker  run  -­‐h

     `hostname`  \      -­‐v  /var/run/docker.sock:/var/run/docker.sock  \      -­‐v  /var/lib/mackerel-­‐agent/:/var/lib/mackerel-­‐agent/  \      -­‐v  /proc/mounts:/host/proc/mounts:ro  \      -­‐v  /sys/fs/cgroup/:/host/sys/fs/cgroup:ro        -­‐e  'apikey=<APIKEY>‘  \      mackerel/mackerel-­‐agent  
  31. DockerFile(ൈਮ) FROM  debian:jessie   ! #  setup  mackerel-­‐agent   RUN

     apt-­‐get  update  \   ..      &&  apt-­‐get  -­‐y  install  mackerel-­‐agent  \   ..   ! #  setup  docker  plugin   COPY  mackerel-­‐plugin-­‐docker.rb  /mackerel-­‐plugin-­‐docker.rb   RUN  echo  [plugin.metrics.docker]  \      >>  /etc/mackerel-­‐agent/mackerel-­‐agent.conf   RUN  echo  command  =  \"ruby  /mackerel-­‐plugin-­‐docker.rb\"  \      >>  /etc/mackerel-­‐agent/mackerel-­‐agent.conf   ! #  boot  mackerel-­‐agent   CMD  /startup.sh
  32. ֤ίϯςφͷ৘ใΛऩू )PTU qVFOUE NBDLFSFM BHFOU "QQ

  33. ༷ࢠ(ίϯςφຖͷCPU)

  34. ༷ࢠ(ίϯςφຖͷϝϞϦ)

  35. ༷ࢠ(·ͱΊͯ)

  36. ίϯςφͷத਎ͷ ৘ใΛऩू͍ͨ͠

  37. ίϯςφͷத਎ͷ৘ใΛऩू )PTU NBDLFSFM BHFOU "QQ

  38. Memcachedͷྫ %  docker  run  -­‐d  -­‐P  \      

     -­‐-­‐name  memcached  -­‐p  11211:11211  \      sylvainlasnier/memcached )PTU NBDLFSFM BHFOU NFNDBDIFE
  39. linkΦϓγϣϯͰ઀ଓ %  docker  run  -­‐i  -­‐t  -­‐h  `hostname`  \  

       -­‐v  /var/run/docker.sock:/var/run/docker.sock  \      -­‐v  /proc/mounts:/host/proc/mounts:ro  \      -­‐v  /sys/fs/cgroup/:/host/sys/fs/cgroup:ro  \      -­‐e  'apikey=<APIKEY>'  -­‐-­‐link  memcached:memcached  \      mackerel-­‐agent  /bin/bash   ! root@dev:/#  env   HOSTNAME=develop04.host.h   MEMCACHED_PORT_11211_TCP_PORT=11211   MEMCACHED_PORT_11211_TCP_PROTO=tcp   MEMCACHED_NAME=/tender_curie/memcached   MEMCACHED_PORT=tcp://172.17.0.88:11211   MEMCACHED_PORT_11211_TCP_ADDR=172.17.0.88   MEMCACHED_PORT_11211_TCP=tcp://172.17.0.88:11211
  40. ؀ڥม਺ͰΞυϨεࢦఆ root@dev:/#  /usr/local/bin/mackerel-­‐plugin-­‐memcached  \      -­‐host=$MEMCACHED_PORT_11211_TCP_ADDR   memcached.connections.curr_connections  

     10            1427507503   memcached.cmd.cmd_get      0              1427507503   memcached.cmd.cmd_set      0              1427507503
  41. ϓϥάΠϯઃఆΛ࢓ࠐΉ %  docker  run  -­‐h  `hostname`  \      -­‐v

     /var/run/docker.sock:/var/run/docker.sock  \      -­‐v  /var/lib/mackerel-­‐agent/:/var/lib/mackerel-­‐agent/  \      -­‐v  /proc/mounts:/host/proc/mounts:ro  \      -­‐v  /sys/fs/cgroup/:/host/sys/fs/cgroup:ro        -­‐e  'apikey=<APIKEY>‘  \      -­‐-­‐link  memcached:memcached  \      -­‐v  /etc/mackerel-­‐agent/conf.d:/etc/mackerel-­‐agent/conf.d:ro      -­‐e  ‘include=/etc/mackerel-­‐agent/conf.d/*'  \      mackerel/mackerel-­‐agent %  cat  /etc/mackerel-­‐agent/conf.d/memcached.conf   [plugin.metrics.memcached]   command  =  "/usr/local/bin/mackerel-­‐plugin-­‐memcached  -­‐ host=$MEMCACHED_PORT_11211_TCP_ADDR"
  42. MemcachedͷϝτϦοΫ

  43. ·ͱΊ • AgentΛίϯςφͰཱͯΔͱ؆୯ • ॏ͍ίϯςφ͕͙͢ʹൃݟͰ͖Δ • ֤ίϯςφͷத਎΋ݟΕΔ

  44. Q & A