[Pyroscope] Client Setup: Go
Go ํ๊ฒฝ์์ Pyroscope Client๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค๋ฃฌ๋ค.
๊ด๋ จ ํฌ์คํธ
https://blog.naver.com/sssang97/223415589139
์ข ์์ฑ ์ค์น
ํ๋๋ง ๊น๋ฉด ๋๋ค.
go get github.com/grafana/pyroscope-go

์ฝ๋ ๊ตฌ์ฑ
๋ค์๊ณผ ๊ฐ์ ํํ๋ก setup ์ฝ๋๋ฅผ ๊ตฌ์ฑํด์ค๋ค.
package profile
import (
"os"
"runtime"
"github.com/grafana/pyroscope-go"
)
func SetupPyroscope() {
// These 2 lines are only required if you're using mutex or block profiling
// Read the explanation below for how to set these rates:
runtime.SetMutexProfileFraction(5)
runtime.SetBlockProfileRate(5)
pyroscope.Start(pyroscope.Config{
ApplicationName: "simple.golang.app",
// replace this with the address of pyroscope server
ServerAddress: "http://pyroscope-server:4040",
// you can disable logging by setting this to nil
Logger: pyroscope.StandardLogger,
// you can provide static tags via a map:
Tags: map[string]string{"hostname": os.Getenv("HOSTNAME")},
ProfileTypes: []pyroscope.ProfileType{
// these profile types are enabled by default:
pyroscope.ProfileCPU,
pyroscope.ProfileAllocObjects,
pyroscope.ProfileAllocSpace,
pyroscope.ProfileInuseObjects,
pyroscope.ProfileInuseSpace,
// these profile types are optional:
pyroscope.ProfileGoroutines,
pyroscope.ProfileMutexCount,
pyroscope.ProfileMutexDuration,
pyroscope.ProfileBlockCount,
pyroscope.ProfileBlockDuration,
},
})
}
ServerAddress๊ฐ pyroscope ์๋ฒ ์ฃผ์.
ApplicationName์ด pyroscope์ ํ์๋ ์ฑ ์ด๋ฆ์ด๋ค.
ProfileTypes์ ์ด๋ค ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ผ์ง๋ฅผ ๊ฒฐ์ ํ๋ค. ํ์ํ ๊ฒ๋ง ๋ฃ์ด๋ ๋๋ค.
๊ทธ๋ ๊ฒ ์ ๋นํ ์ง๊ณ
์ฝ๋ ์์๋ถ๋ถ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค. ์ Start ํจ์ ์์ฒด๋ non block์ผ๋ก ์คํ๋๋ค.
๊ทธ๋ผ ์ด๋ฐ์์ผ๋ก ๊ณ์ ๊ธฐ๋ฅ์ฐจ๊ฒ ์ด์ฌ๋ ๊ฒ์ด๋ค.
ํ์ธ
๊ทธ๋ฌ๋ฉด ์ง์ ํ ์ฑ ์ด๋ฆ์ ๋ง์ถฐ์ ์ ํญ์ด ์ถ๊ฐ๋ ๊ฒ์ด๋ค.

๊ทธ๋ผ ์ ๋ฐ ์งํ๋ค๋ก ์ํ๋ฅผ ํ์ธํ ์ ์๋ค.
ํ๋ฒ ๋ฌด๊ฑฐ์ด ์ฐ์ฐ ์ด๋ณด๊ณ

ํ์ธํด๋ณด๋ฉด
๊ธฐ๋ํ๋๋๋ก CPU ์ฌ์ฉ๋์ด ์ฐํ๋ค.
์คํํธ๋ ์ด์ค๋ ์ ๋นํ๋ ๋์จ๋ค.
๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋๋ ์ถ์ ํ ์ ์๊ณ , ๊ธฐ๋ณธ์ ์ธ๊ฑด ๋์ถฉ ๋ค ๋๋ค.
์ฐธ์กฐ
https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/go_push/