diff --git a/etc/service.example.yaml b/etc/service.example.yaml index 7a1edeb..ed0b4dc 100644 --- a/etc/service.example.yaml +++ b/etc/service.example.yaml @@ -32,3 +32,13 @@ MitakeSMSSender: User: xxxxxx Password : xxxxxx +DevServer: + Enabled: false + Port: 6470 + MetricsPath: /metrics + EnableMetrics: true + +PyroScope: + Enable: false + URL: http://10.0.0.13:4040 + Token: "xxx" \ No newline at end of file diff --git a/go.mod b/go.mod index e6ffa8d..8a6e7ef 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.36.3 github.com/aws/aws-sdk-go-v2/credentials v1.17.61 github.com/aws/aws-sdk-go-v2/service/ses v1.30.0 + github.com/grafana/pyroscope-go v1.2.0 github.com/matcornic/hermes/v2 v2.1.0 github.com/minchao/go-mitake v1.0.0 github.com/zeromicro/go-zero v1.7.0 @@ -47,12 +48,14 @@ require ( github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/css v1.0.0 // indirect + github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect github.com/huandu/xstrings v1.2.0 // indirect github.com/imdario/mergo v0.3.6 // indirect github.com/jaytaylor/html2text v0.0.0-20180606194806-57d518f124b0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/internal/config/config.go b/internal/config/config.go index 65212ac..30a0a40 100755 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -36,4 +36,11 @@ type Config struct { User string Password string } + + // PyroScope 監控 + PyroScope struct { + Enable bool + URL string + Token string + } } diff --git a/internal/svc/pyroscope.go b/internal/svc/pyroscope.go new file mode 100644 index 0000000..8300053 --- /dev/null +++ b/internal/svc/pyroscope.go @@ -0,0 +1,46 @@ +package svc + +import ( + "code.30cm.net/digimon/app-cloudep-notification-service/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())) + } + } +} diff --git a/internal/svc/service_context.go b/internal/svc/service_context.go index 24021c6..8e0f617 100644 --- a/internal/svc/service_context.go +++ b/internal/svc/service_context.go @@ -20,6 +20,8 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { errs.Scope = code.CloudEPNotification + InitPyroScope(c) + param := usecase.DeliveryUseCaseParam{} if c.AmazonSesSettings.Enable { sesRepo := repository.MustAwsSesMailRepository(repository.AwsEmailDeliveryParam{