Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
即、New Relic / New Relic NOW!
Search
uzulla
June 15, 2022
Programming
0
960
即、New Relic / New Relic NOW!
at: NRUG (New Relic User Group) Vol.3
https://nrug.connpass.com/event/247057/
uzulla
June 15, 2022
Tweet
Share
More Decks by uzulla
See All by uzulla
似たもの同士のPerlとPHP
uzulla
1
130
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
110
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
180
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
120
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
2k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
940
PHPerが ISUCONでやるべき事
uzulla
1
1k
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
250
test is not a job
uzulla
1
500
Other Decks in Programming
See All in Programming
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
200
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
200
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
180
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
950
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
180
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
140
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
Online-Dokumentation, die hilft: Strukturen, Prozesse, Tools
ahus1
0
100
Spatial Rendering for Apple Vision Pro
warrenm
0
150
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.8k
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Making Projects Easy
brettharned
116
6k
Visualization
eitanlees
146
15k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Done Done
chrislema
182
16k
Automating Front-end Workflow
addyosmani
1366
200k
Six Lessons from altMBA
skipperchong
27
3.5k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Code Reviewing Like a Champion
maltzj
521
39k
Transcript
ଈɺNew Relic ʙPHPer͕ҙ͍ࣝͬͯ͘͘ʙ at: NRUG (New Relic User Group) Vol.3
https://nrug.connpass.com/event/247057/ date: 2022/06/15 speaker: uzulla
uzulla • ͔Βߴ·ͰରԠPHPer • όʔδϣϯ • ن • ɾෳࡶ •
ۀൣғ • ͍͖͠
ҙࣝ • ߴ͍Ͱ͔͢ʁࢲ͍Ͱ͢ • ʮNRUG͵Δ͙Ͱψϧ͍τʔΫ͋ΓͰ͠ΐʯ • ͜ͷεϥΠυҙ͕͍ࣝ • ʹ༏͍͠…͍New RelicͳͷͰ
·ͣɺNew Relicศར • օ͞Μͬͯͦ͠͏ • ͋Δ͍ʮศརͦ͏ʯͱࢥͬͯͦ͏ • Ͱɺͬͨ͜ͱͳ͍ਓ͍ͦ͏ • ͦ͏͍͏ਓʹ͚ͯͷτʔΫͰ͢
• ʮͦΕਖ਼͍͍͠ํ͡Όͳ͍Ͱ͢ʂʯͬͯޙͰౖΒΕͦ͏
ʮҙࣝߴ͍ʯ • (͜͜ͷΑ͏ͳҙࣝߴ͍ձ) • ʮśŲƄšƄŖŰƄűƄžũŎʯ ʮͳʹͦΕා͍ʯ • αΠτ͕ӳޠͰා͍ https://newrelic.com/ ਓΑ͘Θ͔Βͳ͍ࣄΛΓͨ͘ͳ͍
ʮΘ͔ͬͯͳ͍ͷʹ͏ʯͷμϝʁ
ͦΜͳࣄͳ͍ • Α͘ΈΕɺ͍͏΄Ͳҙࣝߴ͘ͳ͍ • ʮϑϦʔΞΧϯτΛήοτͩͥʂʯ ͬͯ͋ΔɺΫϨΧෆཁ ("Work Email"͕ѹ͕͋Δ͕ɺ ՚ྷʹεϧʔ) (نಡ͏ͳʂʂʢ͍ͬͺΜΖΜʣ)
ۦ͚ͰαΠϯΞοϓ
None
None
None
None
͜͜EUډॅऀɾձࣾҎ֎ United StatesʢGDPRͷΞϨʣ
͜͜Ͱޭͨ͠ͳ…ͱͳͬͨΒ…
ଈɺΟβʔυ͕࢝·ΔͷͰɺ
ଈϩάΞτͰνϡʔτϦΞϧΛग़ɺRTAͰ͋Δ (νϡʔτϦΞϧλΠϜϩε)
࠶ϩάΠϯ͢Δͱ͜ͷΑ͏ʹͳΔ
ӈ্PullDown͔ΒAPI Keys
Ingest LicenseΛίϐʔ
None
͍
͜͜·ͰʹήοτͰ͖ͨͷ • New RelicͷΞΧϯτ • INGESTͷAPIΩʔʢLicense Key)
ʮΑͬ͠ΌɺσʔλૹΖ͏͔ʂʯ • ʮ͡Ό͋ɺαʔόʔΛ༻ҙͯ͠…ʯ • ʮ͔͔ۚΔ͡ΌΜʯʮҙࣝߴਿʯʮࠓʹ͠Α͏ʯ • ͦ͏͡Όͳ͍ɺखݩͷPCͰ͍͍ͬ͠ΐʂʂʂ • DockerͰ͍͍ʂdocker-compose ͍ΒͶ͑ʂ
• (ૉdocker Ұपճͬͯҙࣝߴ͍Մೳੑ͋Δ)
docker-compose ʹॻ͖͑ͨαϯϓϧ ͬͪ͜ʹ͓͍͓͖ͯ·͢ • https://github.com/uzulla/unconscious-new-relic-sample.php • ʮLicense keyΛ.envʹ͍ΕͯɺίϯςφͲ͜ʹϋʔυίʔ υͯ͠ͳ͍ͷҙ͔ࣝͨ͘Ͷ͑ʁʯʮΘ͔Δ͕GitHubʹ্͍͛ͨ ͠…ʯ
$ 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Λ͓͚ΑΖ͍͠ʣ ʢhtmldockerىಈ࣌ʹࣗಈ࡞͞ΕΔҙࣝͷ͞ʣ
http://localhost:8080Λ։͘ ΈͳΕͨ෩ܠɺͱΓ͋͑ͣApache+mod_phpͰ͖ͨʂ
ҰԠɺىಈɾఀࢭɾফ͠ํ # ఀࢭ $ 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 มΘΔͷͰɺదٓஔ͖͍͑ͯͩ͘͞ɻ ଞίϯςφͰͬͯΔͱফͤ·ͤΜ͠ɺআඞਢͰͳ͍Ͱ͢ɻ
Αͬ͠ΌʂNR͍ΕΔͧʂ $ docker exec -it unconscious-app bash # γΣϧʹೖΔ root@5b8ea9bb3d5a:/var/www/html#
<= DockerͷதɺҎԼ͜ͷதͰ࣮ߦ
# ҎԼɺ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
ରܗࣜΠϯετʔϥ͕͘ΔͷͰ ૉʹINGESTͷAPIΩʔΛ͍Ε·͢
ͳΜ͔ޭ͠·͢(ޙΖແࢹ)
Ωʔ͕ೖ͔ͬͨνΣοΫ $ php -i |grep newrelic |grep license newrelic.license =>
b7...AL => b7...AL Φοέʔʂʂʂ ʢ͜ΕͰnewrelic.soͷϩʔυνΣοΫಉ࣌ʹ͍ͯ͠·͢ʣ
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
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͕ىಈͯ͘͠Ε·͢ʣ
ҰԠ 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
ϫΫϫΫ͠ͳ͕Βͭ • phpinfoͷϖʔδͰF5࿈ଧ͓͖ͯ͠·͢ • 10͘Β͍ͪ·͢ʢׂͱͭͷͰɺযΒͣʣ • New RelicͷϖʔδΛϦϩʔυͯ͠ΈΔͱ…
དྷ·ͨ͠ʂ PHP ApplicationΛΫϦοΫ͠·͠ΐ͏ ʢͳ͓ɺAPMҎ֎Ͱ͖ͯ·ͤΜɺ͍Εͯͳ͍ͷͰʣ
APM ΈΕ·ͨ͠ʂউརʂʂ (APMͱɺΞϓϦέʔγϣϯͷϞχλϦϯάͰ͢(ࡶ))
!!
Ͱͳ͍ • ͱΓ͋͑ͣࠨଆͷ • Transactionsͱ͔Έ·͠ΐ͏ • ࣮ࡍࣗͰݟͯΈͯ΄͍͠ͷͰɺུ
Errorൃੜͤ͞·͠ΐ͏ • html/index.php ʹ asdf(); ͱ͔͍Εͯյ͠·͠ΐ͏ • ͪΐͬͱ͢ΔͱɺError inboxʹ͜ͷΤϥʔ͕ݱΕ·͢
ग़·ͨ͠ʂ
None
·͋σϓϩΠ࣌ͷࢹʹศར ʢനʣ
༨ஊɿPR TIMESʹ͓͚ΔվળใࠂʢࠨɿҰࡢɺӈɿࡢʣ ʮ͖Ε͍ͳը໘ͩΖ…ຊ൪ͳΜͩͥ…ʯʮѹతվળ…ʯ
!!
Ͱͳ͍ • ʮҙͷϩάసૹ͘Β͍ͯ͠ΈΔ͔…ʯ • ҙͷϩά(ϑΝΠϧ)ΛɺϦΞϧλΠϜʹNRʹసૹͰ͖·͢ • ෳͷϗετʢVMʣ͔Βແਚʹૹ৴Ͱ͖·͢
͜͜Ͱ • ϩάసૹެࣜͷ newrelic-infra agent ͕ఆ൪ • ࣮ɺ݁ߏ Installཁ͕݅͋ΔɺDockerͰ໘ •
ࢲʮ໘…ҙࣝߴ͍…͋ɺsyslogରԠͯ͠Δ͡ΌΜʂʯ • https://docs.newrelic.com/jp/docs/logs/log-api/use-tcp- endpoint-forward-logs-new-relic
ͱΓ͋͑ͣɺϩάϑΝΠϧΛͭ͘Δ index.phpʹҎԼͱ͔ॻ͘ɻ ͜ΕదͰ͋Γɺผʹmonologͷग़ྗͱ͔Ͱྑ͍ɻ error_log( "MyApp: this is log! can you
hear me??.".PHP_EOL, 3, "/var/www/my.log" );
Ϧϩʔυͯ͠ɺϑΝΠϧ͕Ͱ͖͍ͯΔ͜ͱΛݟΔ # 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??.
syslog-ngΛ͍ΕΔ $ docker exec -it unconscious-app bash root@27f0166df71b:/var/www/html# apt install
-y syslog-ng
ConfigΛॻ͘ $ apt install -y vim # Ͱ͍͍͠ɺnanoͰྑ͍͕ $ vi
/etc/syslog-ng/syslog-ng.conf (NRͷϩάసૹʹ͔͠Θͳ͍ͷͰɺ தΛશ෦ফͯ͠ɺ࣍ͷϖʔδͷ༰ΛೖΕΔ)
@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ྫɺΩʔॻ͖͍͑ͯͩ͘͞ʣ
ىಈͱ֬ೝ # 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
• ʮsyslogͱ͔ҙ͔ࣝͨ͘Ͷ͑ʁʯʮ·͋σϞͳΜͰ…ʯ • ʮ͑ͬࣗಈىಈʁʯʮ·͋ɺσϞͳΜͰ…ɺ͠Βͯ͘Εʯ • (ࡶͳྫͳͷͰɺຖճdocker execͰىಈ͢Δඞཁ͕͋Γ·͢) • (͜ͷ͋ͨΓ৭ʑదʹͯ͠΄͍͠)
510ͬͯΔͱ… ͔͜͜Β͍͚ΔLogsʹͰͯ͘Δ
Find Log where͔Βݕࡧͱ͔Ͱ͖Δͧʂʂ
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 # ͜ͷޙͰɺԿ͔Ϧϩʔυͯ͠ϩάΛ࠶ه͢Δ
͕͢͞ʹ͏10ͨͬͨΖ • ऴΘΓऴΘΓʂʂ • ҙࣝͬͯ͘Έͨͧʂʂ
ʁʮNRʓʓͰͳ͍ͱ͑ͳ͍ʯ • ͕ۚͳ͍ͱ • ͕ࣝͳ͍ͱ • ΫϥυΠϯϑϥ͕ͳ͍ͱ
NO!!
ศརʂʂʂ • ԿೖΕΒΕ·͢ • ͔͠ɺجຊແྉͰ͢ • ʮجຊͱ͍͏͜ͱŗŕʯʮŲŰŰʯ (·͋Ͱ͍͏ͯϩά100GBͩͧɺͤΑ) • SUGOI!!!!
• ࢼ͞ͳ͍ཧ༝ɺͳ͍ͷͰʁ
φʂ͑ΔʂNew Relicʂ
ʮ͜ͷτʔΫେৎͳͷ͔…ʁʯ • NRͷਓʮҙࣝͷ͍τʔΫ͓ئ͍͠·͢ʯ • ࢲʮ͓̺ʯ • ͳͷͰେৎͩͱࢥ͏ɺଟɻ • NRೖΕ͚ͨͩͰ͔͍͍͔ͬ͜Β·ͣຬ͠Α͏
Incident Driven New Relic • ൃੜͨ͠Τϥʔྫ֎͕ͲΜͲΜೖͬͯศར • ϩάΛసૹ͢Δͱݕࡧ͠์ͩ͠ɺΞϥʔτՄೳ • ʮΞϥʔτઃఆͱ͔ͪΐͬͱҙ͕ࣝߴ͍ͳʁʯ
• ͱΓ͍͋͑ͣΕͱ͘ɺ͕Ͱͯ͘Δ·Ͱ์ஔ • ࢲ͕NRΛΈΔͷେମ͕ى͖ͨ࣌ • ·͋ɺౖΒΕ͔ͯΒݟ͍͍ͨͬͯ͡Όͳ͍
৮͓ͬͯ΅͑ΖNew Relic • NR͕ͳͯ͘ੈքճΔ͕ศར • खݩͷDockerͱ͔Ͱ׳ΕΔ => ʮͱΓ͍͋͑ͣΕͱ͔͘ʯ • ʮࣗͷNRʯ͕ͳ͍ͱɺؾܰʹࢼͤͳ͍ΑͶɺΘ͔Δ
• ͱΓ·ɺαΠϯΞοϓͯ͠ςϨϝτϦͱ͔ϩάͱ͔ૹΓ͚ͭͯ ͓͚͍ʔΜ͡ΌͶʔͷʁ • ා͘ͳ͘ͳͬͨʁͦͨ͠ΒstgʹͰͿͬ͜ΜͰΈ·͠ΐ͏ʙʙ
Ͳ͏ͩɺҙ͍ࣝͩΒ͏ʁ • ͓ࢼ͍ͩ͘͠͞ʙʙ • ࣮ଞͷػೳΊͬͪΌศརʂNRQLͱ͔ʂ • Ͱ·ɺϝϯυΠ͠ɺͦΕࠓͳʂ • (ਖ਼ࣗ͋Μ·ۦͰ͖ͯͳ͍ͱ͍͏͋Δ)
༨ஊɿ࠷ۙͷʮͻ͍͘ਓʯͷࠔΓ͝ͱ • E_NOTICEर͍͍ͨʢE_WARNर͑Δ) • ࠷ۙɺ5.4͕ΒΕͨ… • Aarch64ʢM1 MacͷDockerʣͩͱPHP>=8͔Β… • ͍͖͔͍ͨ͠…