-
Notifications
You must be signed in to change notification settings - Fork 701
/
init.go
35 lines (30 loc) · 929 Bytes
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package mongox
import (
"net/http"
"github.com/douyu/jupiter/pkg/application"
"github.com/douyu/jupiter/pkg/xlog"
jsoniter "github.com/json-iterator/go"
"go.mongodb.org/mongo-driver/mongo"
)
func init() {
// govern.RegisterStatSnapper("mongo", Stats)
// govern.RegisterConfSnapper("mongo", Configs)
http.HandleFunc("/debug/mongo/stats", func(w http.ResponseWriter, r *http.Request) {
type mongoStatus struct {
application.RuntimeStats
Mongos map[string]interface{} `json:"mongos"`
}
var rets = mongoStatus{
RuntimeStats: application.NewRuntimeStats(),
Mongos: make(map[string]interface{}),
}
Range(func(name string, cc *mongo.Client) bool {
rets.Mongos[name] = map[string]interface{}{
"numberSessionsInProgress": cc.NumberSessionsInProgress(),
}
return true
})
_ = jsoniter.NewEncoder(w).Encode(rets)
})
}
var _logger = xlog.JupiterLogger.With(xlog.FieldMod("mongodb"))