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
950
即、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
930
PHPerが ISUCONでやるべき事
uzulla
1
1k
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
240
test is not a job
uzulla
1
500
Other Decks in Programming
See All in Programming
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
130
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
350
Haze - Real time background blurring
chrisbanes
1
500
快速入門可觀測性
blueswen
0
310
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Security_for_introducing_eBPF
kentatada
0
110
CSC305 Lecture 26
javiergs
PRO
0
140
Full stack testing :: basic to basic
up1
1
930
From Translations to Multi Dimension Entities
alexanderschranz
2
130
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
7k
Documentation Writing (for coders)
carmenintech
66
4.5k
How GitHub (no longer) Works
holman
311
140k
Unsuck your backbone
ammeep
669
57k
For a Future-Friendly Web
brad_frost
175
9.4k
Optimizing for Happiness
mojombo
376
70k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
BBQ
matthewcrist
85
9.4k
A better future with KSS
kneath
238
17k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
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͔Β… • ͍͖͔͍ͨ͠…