[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/