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
940
即、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
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
99
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
170
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
110
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
1.9k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
890
PHPerが ISUCONでやるべき事
uzulla
1
830
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
220
test is not a job
uzulla
1
480
あなたのPHPアプリ、ログはでてますか?あるいはログをだしてますか? / Are you writing a log? Or just out a log?
uzulla
17
7.4k
Other Decks in Programming
See All in Programming
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
CSC509 Lecture 12
javiergs
PRO
0
160
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.4k
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
870
Jakarta EE meets AI
ivargrimstad
0
510
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Amazon Qを使ってIaCを触ろう!
maruto
0
400
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
What's in a price? How to price your products and services
michaelherold
243
12k
A Tale of Four Properties
chriscoyier
156
23k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Building Your Own Lightsaber
phodgson
103
6.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Happy Clients
brianwarren
98
6.7k
Gamification - CAS2011
davidbonilla
80
5k
Agile that works and the tools we love
rasmusluckow
327
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Building Flexible Design Systems
yeseniaperezcruz
327
38k
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͔Β… • ͍͖͔͍ͨ͠…