fix(metrics): enable prometheus global switch when user enable devsever metrics (#3169)
This commit is contained in:
@@ -21,6 +21,11 @@ func Enabled() bool {
|
|||||||
return enabled.True()
|
return enabled.True()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable enables prometheus.
|
||||||
|
func Enable() {
|
||||||
|
enabled.Set(true)
|
||||||
|
}
|
||||||
|
|
||||||
// StartAgent starts a prometheus agent.
|
// StartAgent starts a prometheus agent.
|
||||||
func StartAgent(c Config) {
|
func StartAgent(c Config) {
|
||||||
if len(c.Host) == 0 {
|
if len(c.Host) == 0 {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/felixge/fgprof"
|
"github.com/felixge/fgprof"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/prometheus"
|
||||||
"github.com/zeromicro/go-zero/core/threading"
|
"github.com/zeromicro/go-zero/core/threading"
|
||||||
"github.com/zeromicro/go-zero/internal/health"
|
"github.com/zeromicro/go-zero/internal/health"
|
||||||
)
|
)
|
||||||
@@ -42,6 +43,8 @@ func (s *Server) addRoutes() {
|
|||||||
|
|
||||||
// metrics
|
// metrics
|
||||||
if s.config.EnableMetrics {
|
if s.config.EnableMetrics {
|
||||||
|
// enable prometheus global switch
|
||||||
|
prometheus.Enable()
|
||||||
s.handleFunc(s.config.MetricsPath, promhttp.Handler().ServeHTTP)
|
s.handleFunc(s.config.MetricsPath, promhttp.Handler().ServeHTTP)
|
||||||
}
|
}
|
||||||
// pprof
|
// pprof
|
||||||
|
|||||||
Reference in New Issue
Block a user