Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
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
|
|
}
|