mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-29 23:10:35 +00:00
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package common
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"github.com/grafana/pyroscope-go"
|
|
)
|
|
|
|
func StartPyroScope() error {
|
|
|
|
pyroscopeUrl := GetEnvOrDefaultString("PYROSCOPE_URL", "")
|
|
if pyroscopeUrl == "" {
|
|
return nil
|
|
}
|
|
|
|
pyroscopeAppName := GetEnvOrDefaultString("PYROSCOPE_APP_NAME", "new-api")
|
|
pyroscopeBasicAuthUser := GetEnvOrDefaultString("PYROSCOPE_BASIC_AUTH_USER", "")
|
|
pyroscopeBasicAuthPassword := GetEnvOrDefaultString("PYROSCOPE_BASIC_AUTH_PASSWORD", "")
|
|
pyroscopeHostname := GetEnvOrDefaultString("HOSTNAME", "new-api")
|
|
|
|
mutexRate := GetEnvOrDefault("PYROSCOPE_MUTEX_RATE", 5)
|
|
blockRate := GetEnvOrDefault("PYROSCOPE_BLOCK_RATE", 5)
|
|
|
|
runtime.SetMutexProfileFraction(mutexRate)
|
|
runtime.SetBlockProfileRate(blockRate)
|
|
|
|
_, err := pyroscope.Start(pyroscope.Config{
|
|
ApplicationName: pyroscopeAppName,
|
|
|
|
ServerAddress: pyroscopeUrl,
|
|
BasicAuthUser: pyroscopeBasicAuthUser,
|
|
BasicAuthPassword: pyroscopeBasicAuthPassword,
|
|
|
|
Logger: nil,
|
|
|
|
Tags: map[string]string{"hostname": pyroscopeHostname},
|
|
|
|
ProfileTypes: []pyroscope.ProfileType{
|
|
pyroscope.ProfileCPU,
|
|
pyroscope.ProfileAllocObjects,
|
|
pyroscope.ProfileAllocSpace,
|
|
pyroscope.ProfileInuseObjects,
|
|
pyroscope.ProfileInuseSpace,
|
|
|
|
pyroscope.ProfileGoroutines,
|
|
pyroscope.ProfileMutexCount,
|
|
pyroscope.ProfileMutexDuration,
|
|
pyroscope.ProfileBlockCount,
|
|
pyroscope.ProfileBlockDuration,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|