47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package svc
|
|
|
|
import (
|
|
"biz-member-gateway/internal/config"
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/grafana/pyroscope-go"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
func InitPyroScope(c config.Config) {
|
|
if c.PyroScope.Enable {
|
|
podName := os.Getenv("POD_NAME")
|
|
|
|
_, err := pyroscope.Start(pyroscope.Config{
|
|
ApplicationName: fmt.Sprintf("biz-%s-%s", c.Name, podName),
|
|
ServerAddress: c.PyroScope.URL,
|
|
Logger: logx.WithContext(context.Background()),
|
|
ProfileTypes: []pyroscope.ProfileType{
|
|
pyroscope.ProfileCPU,
|
|
|
|
pyroscope.ProfileInuseObjects,
|
|
pyroscope.ProfileAllocObjects,
|
|
pyroscope.ProfileInuseSpace,
|
|
pyroscope.ProfileAllocSpace,
|
|
|
|
pyroscope.ProfileGoroutines,
|
|
|
|
pyroscope.ProfileMutexCount,
|
|
pyroscope.ProfileMutexDuration,
|
|
|
|
pyroscope.ProfileBlockCount,
|
|
pyroscope.ProfileBlockDuration,
|
|
},
|
|
})
|
|
if err != nil {
|
|
logx.WithCallerSkip(1).WithFields(logx.LogField{
|
|
Key: "error", Value: err.Error(),
|
|
}).Error("failed to init pyroscope")
|
|
|
|
panic(fmt.Sprintf("Pyroscope start err: %s", err.Error()))
|
|
}
|
|
}
|
|
}
|