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
920
即、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
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
150
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
96
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
1.8k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
840
PHPerが ISUCONでやるべき事
uzulla
1
650
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
190
test is not a job
uzulla
1
460
あなたのPHPアプリ、ログはでてますか?あるいはログをだしてますか? / Are you writing a log? Or just out a log?
uzulla
17
7.2k
有名FWを採用する?しない? 令和5年におけるオレオレフレームの立ち位置 / To make with own framework or not do, that is the question
uzulla
2
1k
Other Decks in Programming
See All in Programming
利用者視点で考える、イテレータとの上手な付き合い方
syumai
4
220
Infrastructure as Code でセキュリティを楽にしよう!
konokenj
6
1.4k
"noncopyable types" の使いどころについて考えてみた
andpad
0
140
Go製CLIツールGatling Commanderによる負荷試験実施の自動化
okmtz
3
690
Real-time message handling and notifications with API Platform and Symfony
alli83
1
100
dbt-ga4パッケージを実業務に導入してみた話
t_tokumaru_feedcorp
0
120
ECS向けのドリフト検知機構を実装してみた
tkikuc
0
280
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
110
推しの夫に恋のGPS「ときメーター」#M5Stack #IoT #M5JPTour2024
riyu
0
230
自分だけの世界を創るクリエイティブコーディング / Creative Coding: Creating Your Own World
chobishiba
2
810
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
170
Cohesion in Modeling and Design
mploed
3
200
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
7
290
Being A Developer After 40
akosma
84
590k
Testing 201, or: Great Expectations
jmmastey
38
7k
A better future with KSS
kneath
237
17k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
110
6.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Building Your Own Lightsaber
phodgson
102
6k
How to Think Like a Performance Engineer
csswizardry
16
1k
GraphQLとの向き合い方2022年版
quramy
43
13k
Optimising Largest Contentful Paint
csswizardry
31
2.8k
Music & Morning Musume
bryan
46
6.1k
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͔Β… • ͍͖͔͍ͨ͠…