8000 feat: implement autopprof pkg by mingrammer · Pull Request #1 · daangn/autopprof · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: implement autopprof pkg #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 25, 2022
Merged

feat: implement autopprof pkg #1

merged 9 commits into from
Oct 25, 2022

Conversation

mingrammer
Copy link
Contributor
@mingrammer mingrammer commented Oct 25, 2022

메모리 사용률 (CPU는 곧 지원 예정)이 지정된 threshold 값을 넘을 경우 알람을 리포트 해주는 라이브러리를 만들었어요.

동작 방식은 단순하게 일정 주기마다 cgroups stat으로부터 limit, usage를 읽어와 rate를 계산해서 threshold 값과 비교한 뒤 높으면 알람을 보내는 방식이에요. 추가로 고려했던건, 보통 mem leak 등으로 메모리 사용률이 높아지면 높아진 상태에서 유지되는 경우가 많기 때문에 threshold를 넘길때마다 보내지는 않고 연속적으로 threshold를 넘는 최소 수치를 카운팅하면서 최소 카운트를 넘어가면 다시 보내는 로직을 구현했습니다. (스팸성 리포트 방지)

기본 동작: threshold를 처음 넘긴 이후 threshold를 연속적으로 초과하는 경우에는 바로 리포트를 보내지 않고 최소 12번까지 카운트 한 뒤 프로파일링 및 리포팅을 다시 수행해요. (high가 계속 유지될 경우 5초마다 12번 카운팅해서 5초가 아니라 1분마다 오도록)

package main

import (
	"errors"
	"log"

	"github.com/daangn/autopprof"
	"github.com/daangn/autopprof/report"
)

func main() {
	err := autopprof.Start(autopprof.Option{
		App:          "YOUR_APP_NAME",
		MemThreshold: 0.8, // Default: 0.75.
		Reporter: report.ReporterOption{
			Type: report.SLACK,
			SlackReporterOption: &report.SlackReporterOption{
				Token:   "YOUR_TOKEN_HERE",
				Channel: "#REPORT_CHANNEL",
			},
		},
	})
	if errors.Is(err, autopprof.ErrUnsupportedPlatform) {
		// You can just skip the autopprof.
		log.Println(err)
	} else if err != nil {
		log.Fatalln(err)
	}
	defer autopprof.Stop()

	// Your code here.
}

profiling_example

Copy link
@proost proost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mingrammer
Copy link
Contributor Author

두구두구 가보겠읍니다

@mingrammer mingrammer merged commit a676d2f into main Oct 25, 2022
@mingrammer mingrammer deleted the initial branch October 25, 2022 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0