$30 off During Our Annual Pro Sale. View Details »

即、New Relic / New Relic NOW!

uzulla
June 15, 2022

即、New Relic / New Relic NOW!

at: NRUG (New Relic User Group) Vol.3
https://nrug.connpass.com/event/247057/

uzulla

June 15, 2022
Tweet

More Decks by uzulla

Other Decks in Programming

Transcript

  1. ଈɺNew Relic ʙPHPer͕ҙࣝ௿͘΍͍ͬͯ͘ʙ at: NRUG (New Relic User Group) Vol.3

    https://nrug.connpass.com/event/247057/ date: 2022/06/15 speaker: uzulla
  2. uzulla • ௿͔Βߴ·ͰରԠPHPer • όʔδϣϯ • ن໛ • ೉౓ɾෳࡶ౓ •

    ۀ຿ൣғ • ͍͖͠
  3. ҙࣝ • ߴ͍Ͱ͔͢ʁࢲ͸௿͍Ͱ͢ • ʮNRUG͸͵Δ͙Ͱψϧ͍τʔΫ΋͋ΓͰ͠ΐʯ • ͜ͷεϥΠυ΋ҙ͕ࣝ௿͍ • ໨ʹ༏͍͠…͍΍New RelicͳͷͰ྘

  4. ·ͣɺNew Relic͸ศར • օ͞Μ͸ͬͯͦ͠͏ • ͋Δ͍͸ʮศརͦ͏ʯͱࢥͬͯͦ͏ • Ͱ΋ɺ࢖ͬͨ͜ͱͳ͍ਓ΋͍ͦ͏ • ͦ͏͍͏ਓʹ޲͚ͯͷτʔΫͰ͢

    • ʮͦΕ͸ਖ਼͍͠࢖͍ํ͡Όͳ͍Ͱ͢ʂʯͬͯޙͰౖΒΕͦ͏
  5. ʮҙࣝߴ͍໰୊ʯ • (͜͜ͷΑ͏ͳҙࣝߴ͍ձ) • ʮśŲƄšƄŖŰƄűƄžũŎʯ ʮͳʹͦΕා͍ʯ • αΠτ͕ӳޠͰා͍ https://newrelic.com/ ਓ͸Α͘Θ͔Βͳ͍ࣄΛ΍Γͨ͘ͳ͍

    ʮΘ͔ͬͯͳ͍ͷʹ࢖͏ʯͷ͸μϝʁ
  6. ͦΜͳࣄͳ͍ • Α͘ΈΕ͹ɺ͍͏΄Ͳҙࣝߴ͘ͳ͍ • ʮϑϦʔΞΧ΢ϯτΛήοτͩͥʂʯ ͬͯ͋ΔɺΫϨΧ΋ෆཁ ("Work Email"͕ѹ͕͋Δ͕ɺ ՚ྷʹεϧʔ) (ن໿͸ಡ΋͏ͳʂʂʢ͍ͬͺΜΖΜʣ)

  7. ۦ͚଍ͰαΠϯΞοϓ

  8. None
  9. None
  10. None
  11. None
  12. ͜͜͸EUډॅऀɾձࣾҎ֎͸ United StatesʢGDPRͷΞϨʣ

  13. ͜͜Ͱ੒ޭͨ͠ͳ…ͱͳͬͨΒ…

  14. ଈɺ΢Οβʔυ͕࢝·ΔͷͰɺ

  15. ଈϩάΞ΢τͰνϡʔτϦΞϧΛ୤ग़ɺRTAͰ͋Δ (νϡʔτϦΞϧ͸λΠϜϩε)

  16. ࠶ϩάΠϯ͢Δͱ͜ͷΑ͏ʹͳΔ

  17. ӈ্PullDown͔ΒAPI Keys

  18. Ingest LicenseΛίϐʔ

  19. None
  20. ͸͍

  21. ͜͜·ͰʹήοτͰ͖ͨ΋ͷ • New RelicͷΞΧ΢ϯτ • INGESTͷAPIΩʔʢLicense Key)

  22. ʮΑͬ͠ΌɺσʔλૹΖ͏͔ʂʯ • ʮ͡Ό͋ɺαʔόʔΛ༻ҙͯ͠…ʯ • ʮ͔͔ۚΔ͡ΌΜʯʮҙࣝߴਿʯʮࠓ౓ʹ͠Α͏ʯ • ͦ͏͡Όͳ͍ɺखݩͷPCͰ͍͍ͬ͠ΐʂʂʂ • DockerͰ͍͍΍ʂdocker-compose ΋͍ΒͶ͑΍ʂ

    • (ૉdocker Ұपճͬͯҙࣝߴ͍Մೳੑ΋͋Δ)
  23. docker-compose ʹॻ͖׵͑ͨαϯϓϧ͸ ͬͪ͜ʹ͓͍͓͖ͯ·͢ • https://github.com/uzulla/unconscious-new-relic-sample.php • ʮLicense keyΛ.envʹ͍Εͯɺίϯςφ಺Ͳ͜ʹ΋ϋʔυίʔ υͯ͠ͳ͍ͷҙ͔ࣝͨ͘Ͷ͑ʁʯʮΘ͔Δ͕GitHubʹ্͍͛ͨ ͠…ʯ

  24. $ mkdir unconscious-app; cd unconscious-app; $ docker run -d -v

    `pwd`:/var/www -p 8080:80 \ --name unconscious-app php:8.1-apache $ echo "<?php phpinfo();" > html/index.php $ find . ./html/index.php ʢphp-fpm͡Όͳ͍ͷ΋ҙࣝ௿͍ʢॾઆ͋Δʣʣ ʢhtmlҎԼʹ͓޷͖ͳPHPΛ͓͚͹ΑΖ͍͠ʣ ʢhtml͸dockerىಈ࣌ʹࣗಈ࡞੒͞ΕΔҙࣝͷ௿͞ʣ
  25. http://localhost:8080Λ։͘ ΈͳΕͨ෩ܠɺͱΓ͋͑ͣApache+mod_phpͰ͖ͨʂ

  26. ҰԠɺىಈɾఀࢭɾফ͠ํ # ఀࢭ $ docker stop unconscious-app # ࠶։ $

    docker start unconscious-app # ࡟আ $ docker rm unconscious-app # image΋ফ͍ͨ͠ਓ $ docker image ls |grep 8.1-apache php 8.1-apache c9248ee25e78 34 hours ago 458MB $ docker image rm c9248ee25e78 imageͷ c9248ee25e78 ͸มΘΔͷͰɺదٓஔ͖׵͍͑ͯͩ͘͞ɻ ଞίϯςφͰ࢖ͬͯΔͱফͤ·ͤΜ͠ɺ࡟আඞਢͰ͸ͳ͍Ͱ͢ɻ
  27. Αͬ͠ΌʂNR͍ΕΔͧʂ $ docker exec -it unconscious-app bash # γΣϧʹೖΔ root@5b8ea9bb3d5a:/var/www/html#

    <= DockerͷதɺҎԼ͜ͷதͰ࣮ߦ
  28. # ҎԼɺNRࢦఆͷϫϯϥΠφʔΛվ଄ͨ͠෺ɺ౰࠲͸ಈ͘ͱࢥ͍·͢ $ apt update -y && apt install -y

    gnupg $ echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | \ tee /etc/apt/sources.list.d/newrelic.list # wgetͱ͔ɺPHPerͳΒ͍ΒΜΑͶʂphpͰ୅༻ʂ $ php -r "readfile('https://download.newrelic.com/548C16BF.gpg');" | \ apt-key add - # php5ͬͯ͋Δ͚Ͳɺ8Ͱ΋5Ͱ͢ ☺ $ apt-get update && apt-get -y install newrelic-php5 $ newrelic-install install
  29. ର࿩ܗࣜΠϯετʔϥ͕͘ΔͷͰ ૉ௚ʹINGESTͷAPIΩʔΛ͍Ε·͢

  30. ͳΜ͔੒ޭ͠·͢(ޙΖ͸ແࢹ)

  31. Ωʔ͕ೖ͔ͬͨνΣοΫ $ php -i |grep newrelic |grep license newrelic.license =>

    b7...AL => b7...AL Φοέʔʂʂʂ ʢ͜ΕͰnewrelic.soͷϩʔυνΣοΫ΋ಉ࣌ʹ͍ͯ͠·͢ʣ
  32. mod_phpʹ൓ө͢ΔͨΊɺ࠶ىಈ root@5b8ea9bb3d5a:/var/www/html# exit # docker಺͔Βexit͠ɺϗετͰ $ docker stop unconscious-app $

    docker start unconscious-app # ҰԠىಈΛ֬ೝʢStatus͕਺ඵͳΒ࠶ىಈͯ͠ΔͰ͠ΐ͏ʣ $ docker ps CONTAINER ID IMAGE ུ STATUS PORTS NAMES 27f0166df71b php:8.1-apache ུ Up 6 seconds 0.0.0.0:8080->80/tcp unconscious-app
  33. Agent͕ىಈ͍ͯ͠Δ͔νΣοΫ # Dockerͷίϯςφʹ͸͍Δ $ docker exec -it unconscious-app bash psͰ֬ೝ

    root@27f0166df71b:/var/www/html# ps -fax PID TTY STAT TIME COMMAND 1 ? Ss 0:00 apache2 -DFOREGROUND 27 ? Sl 0:00 /usr/bin/newrelic-daemon --agent (ུ) newrelic-daemon ͕͍Ε͹OKʢPHP͕ىಈͯ͘͠Ε·͢ʣ
  34. ҰԠ agentͷ log΋ΈΔʢτϥϒϧγϡʔτʹศརʣ root@b:/var/www/html# tail /var/log/newrelic/newrelic-daemon.log (ུ) (ུ) (44) Info:

    app 'PHP Application' connected with run id (ུ) connected ͕͋Ε͹ଟ෼OK
  35. ϫΫϫΫ͠ͳ͕Β଴ͭ • phpinfoͷϖʔδͰF5࿈ଧ͓͖ͯ͠·͢ • 10෼͘Β͍଴ͪ·͢ʢׂͱ଴ͭͷͰɺযΒͣʣ • New RelicͷϖʔδΛϦϩʔυͯ͠ΈΔͱ…

  36. དྷ·ͨ͠ʂ PHP ApplicationΛΫϦοΫ͠·͠ΐ͏ ʢͳ͓ɺAPMҎ֎͸Ͱ͖ͯ·ͤΜɺ͍Εͯͳ͍ͷͰʣ

  37. APM ΈΕ·ͨ͠ʂউརʂʂ (APMͱ͸ɺΞϓϦέʔγϣϯͷϞχλϦϯάͰ͢(ࡶ))

  38. ׬!!

  39. ׬Ͱ͸ͳ͍ • ͱΓ͋͑ͣࠨଆͷ • Transactionsͱ͔Έ·͠ΐ͏ • ࣮ࡍࣗ෼ͰݟͯΈͯ΄͍͠ͷͰɺུ

  40. Errorൃੜͤ͞·͠ΐ͏ • html/index.php ʹ asdf(); ͱ͔͍Εͯյ͠·͠ΐ͏ • ͪΐͬͱ͢ΔͱɺError inboxʹ͜ͷΤϥʔ͕ݱΕ·͢

  41. ग़·ͨ͠ʂ

  42. None
  43. ·͋σϓϩΠ࣌ͷ؂ࢹʹศར ʢന໨ʣ

  44. ༨ஊɿPR TIMESʹ͓͚ΔվળใࠂʢࠨɿҰࡢ೔ɺӈɿࡢ೔ʣ ʮ͖Ε͍ͳը໘ͩΖ…ຊ൪ͳΜͩͥ…ʯʮѹ౗తվળ…ʯ

  45. ׬!!

  46. ׬Ͱ͸ͳ͍ • ʮ೚ҙͷϩάసૹ͘Β͍ͯ͠ΈΔ͔…ʯ • ೚ҙͷϩά(ϑΝΠϧ)ΛɺϦΞϧλΠϜʹNRʹసૹͰ͖·͢ • ෳ਺ͷϗετʢ΍VMʣ͔Βແਚʹૹ৴Ͱ͖·͢

  47. ͜͜Ͱ໰୊ • ϩάసૹ͸ެࣜͷ newrelic-infra agent ͕ఆ൪ • ࣮͸ɺ݁ߏ Installཁ͕݅͋ΔɺDockerͰ͸໘౗ •

    ࢲʮ໘౗…ҙࣝߴ͍…͋ɺsyslogରԠͯ͠Δ͡ΌΜʂʯ • https://docs.newrelic.com/jp/docs/logs/log-api/use-tcp- endpoint-forward-logs-new-relic
  48. ͱΓ͋͑ͣɺϩάϑΝΠϧΛͭ͘Δ index.phpʹҎԼͱ͔ॻ͘ɻ ͜Ε͸ద౰Ͱ͋Γɺผʹmonologͷग़ྗͱ͔Ͱ΋ྑ͍ɻ error_log( "MyApp: this is log! can you

    hear me??.".PHP_EOL, 3, "/var/www/my.log" );
  49. Ϧϩʔυͯ͠ɺϑΝΠϧ͕Ͱ͖͍ͯΔ͜ͱΛݟΔ # cat /var/www/my.log MyApp: can you hear me??. MyApp:

    can you hear me??. MyApp: can you hear me??. MyApp: can you hear me??.
  50. syslog-ngΛ͍ΕΔ $ docker exec -it unconscious-app bash root@27f0166df71b:/var/www/html# apt install

    -y syslog-ng
  51. ConfigΛॻ͘ $ apt install -y vim # Ͱ΋͍͍͠ɺnanoͰ΋ྑ͍͕ $ vi

    /etc/syslog-ng/syslog-ng.conf (NR΁ͷϩάసૹʹ͔͠࢖Θͳ͍ͷͰɺ த਎Λશ෦ফͯ͠ɺ࣍ͷϖʔδͷ಺༰ΛೖΕΔ)
  52. @version: 3.27 source s_files { file("/var/www/my.log"); }; template NRFormat {

    template( "b77{ུ}NRAL <${PRI}>1 ${ISODATE} ${HOST:--} ${PROGRAM:--} ${PID:--} ${MSGID:--} ${SDATA:--} $MSG\n" ); template_escape(no); }; destination d_newrelic { network( "newrelic.syslog.nr-data.net" port(6514) transport("tls") tls(peer-verify(no)) template(NRFormat) ); }; log { source(s_files); destination(d_newrelic); }; ʢ࠷௿ݶͷҙࣝ௿͍ConfྫɺΩʔ͸ॻ͖׵͍͑ͯͩ͘͞ʣ
  53. ىಈͱ֬ೝ # dockerͩ͠ɺҙࣝ௿͘ಛݖෆཁͳ no-capsʹ͓͖ͯ͠·͢ root@27f0166df71b:/etc/syslog-ng# syslog-ng --no-caps # ϓϩηε্͕͕͍ͬͯΕ͹OK root@27f0166df71b:/etc/syslog-ng#

    ps -fax |grep syslog-ng (ུ) 1452 ? S 0:00 supervising syslog-ng 1453 ? Ssl 0:00 \_ syslog-ng --no-caps
  54. • ʮsyslogͱ͔ҙ͔ࣝͨ͘Ͷ͑ʁʯʮ·͋σϞͳΜͰ…ʯ • ʮ͑ͬࣗಈىಈ͸ʁʯʮ·͋ɺσϞͳΜͰ…ɺ͠Β΂ͯ͘Εʯ • (ࡶͳྫͳͷͰɺຖճdocker execͰىಈ͢Δඞཁ͕͋Γ·͢) • (͜ͷ͋ͨΓ͸৭ʑద౰ʹͯ͠΄͍͠)

  55. 5෼10෼଴ͬͯΔͱ… ͔͜͜Β͍͚ΔLogsʹͰͯ͘Δ

  56. Find Log where͔Βݕࡧͱ͔΋Ͱ͖Δͧʂʂ

  57. 10෼଴ͬͯ΋ग़ͳ͍ͳΒࣦഊͯ͠Δ͔΋ # ࣏͢ɺΩʔؒҧ͑ͯͳ͍͔ʁͱ͔ root@27f0166df71b:/etc/syslog-ng# vi /etc/syslog-ng/syslog-ng.conf # PID͠Β΂ͯkillʢ͋Δ͍͸࠶ىಈʣ root@27f0166df71b:/etc/syslog-ng# ps

    -A|grep syslog-ng 1452 ? 00:00:00 syslog-ng 1453 ? 00:00:00 syslog-ng root@27f0166df71b:/etc/syslog-ng# kill 1452 1453 # ىಈ root@27f0166df71b:/etc/syslog-ng# syslog-ng --no-caps # ͜ͷޙͰɺԿ౓͔Ϧϩʔυͯ͠ϩάΛ࠶౓௥ه͢Δ
  58. ͕͢͞ʹ΋͏10෼ͨͬͨ΍Ζ • ऴΘΓऴΘΓʂʂ • ҙࣝ௿͘΍ͬͯΈͨͧʂʂ

  59. ʁʮNR͸ʓʓͰͳ͍ͱ࢖͑ͳ͍ʯ • ͕ۚͳ͍ͱ • ஌͕ࣝͳ͍ͱ • Ϋϥ΢υΠϯϑϥ͕ͳ͍ͱ

  60. NO!!

  61. ศརʂʂʂ • Կ୆΋ೖΕΒΕ·͢ • ͔͠΋ɺجຊແྉͰ͢ • ʮجຊͱ͍͏͜ͱ͸ŗŕʯʮŲŰŰʯ (·͋Ͱ΋͍͏ͯϩά100GBͩͧɺ޻෉ͤΑ) • SUGOI!!!!

    • ࢼ͞ͳ͍ཧ༝ɺͳ͍ͷͰ͸ʁ
  62. φ΢ʂ࢖͑ΔʂNew Relicʂ

  63. ʮ͜ͷτʔΫେৎ෉ͳͷ͔…ʁʯ • NRͷਓʮҙࣝͷ௿͍τʔΫ͓ئ͍͠·͢ʯ • ࢲʮ͓̺ʯ • ͳͷͰେৎ෉ͩͱࢥ͏ɺଟ෼ɻ • NRೖΕ͚ͨͩͰ͔͍͍͔ͬ͜Β·ͣຬ଍͠Α͏

  64. Incident Driven New Relic • ൃੜͨ͠Τϥʔ΍ྫ֎͕ͲΜͲΜೖͬͯศར • ϩάΛసૹ͢Δͱݕࡧ͠์୊ͩ͠ɺΞϥʔτ΋Մೳ • ʮΞϥʔτઃఆͱ͔ͪΐͬͱҙ͕ࣝߴ͍ͳʁʯ

    • ͱΓ͍͋͑ͣΕͱ͘ɺ໰୊͕Ͱͯ͘Δ·Ͱ͸์ஔ • ࢲ͕NRΛΈΔͷ͸େମ໰୊͕ى͖ͨ࣌ • ·͋ɺౖΒΕ͔ͯΒݟ͍͍ͨͬͯ͡Όͳ͍
  65. ৮͓ͬͯ΅͑ΖNew Relic • NR͕ͳͯ͘΋ੈք͸ճΔ͕ศར • खݩͷDockerͱ͔Ͱ׳ΕΔ => ʮͱΓ͍͋͑ͣΕͱ͔͘ʯ • ʮࣗ෼ͷNRʯ͕ͳ͍ͱɺؾܰʹࢼͤͳ͍ΑͶɺΘ͔Δ

    • ͱΓ·ɺαΠϯΞοϓͯ͠ςϨϝτϦͱ͔ϩάͱ͔ૹΓ͚ͭͯ ͓͚͹͍ʔΜ͡ΌͶʔͷʁ • ා͘ͳ͘ͳͬͨʁͦͨ͠ΒstgʹͰ΋Ϳͬ͜ΜͰΈ·͠ΐ͏ʙʙ
  66. Ͳ͏ͩɺҙࣝ௿͍ͩΒ͏ʁ • ͓ࢼ͍ͩ͘͠͞ʙʙ • ࣮͸ଞͷػೳ΋ΊͬͪΌศརʂNRQLͱ͔ʂ • Ͱ΋·ɺϝϯυΠ͠ɺͦΕ͸ࠓ౓ͳʂ • (ਖ਼௚ࣗ෼΋͋Μ·ۦ࢖Ͱ͖ͯͳ͍ͱ͍͏࿩͸͋Δ)

  67. ༨ஊɿ࠷ۙͷʮͻ͍͘ਓʯͷࠔΓ͝ͱ • E_NOTICE΋र͍͍ͨʢE_WARN͸र͑Δ) • ࠷ۙɺ5.4͕੾ΒΕͨ… • Aarch64ʢM1 MacͷDockerʣͩͱPHP>=8͔Β… • ͍͖͔͍ͨ͠…