closes #5
This commit is contained in:
parent
5a196dab94
commit
33117cd12b
|
@ -133,6 +133,19 @@ func (s ServerConf) ServeHTTP(z ZooNode, fqdn string) {
|
|||
w.Write(state)
|
||||
})
|
||||
|
||||
// Return JSON mertrics
|
||||
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
|
||||
m, err := GetMetrics(z)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
state, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w.Write(state)
|
||||
})
|
||||
|
||||
wr := wrr{
|
||||
fqdn,
|
||||
z,
|
||||
|
|
48
src/rbmd/metrics.go
Normal file
48
src/rbmd/metrics.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package rbmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//Metrics metrics statistic
|
||||
type Metrics struct {
|
||||
Goroutines int `json:"goroutines"`
|
||||
Nodes int `json:"nodes"`
|
||||
MountsTotal int `json:"mountstotal"`
|
||||
Cgocall int64 `json:"cgocall"`
|
||||
}
|
||||
|
||||
// GetMetrics ...
|
||||
func GetMetrics(z ZooNode) (Metrics, error) {
|
||||
var q Quorum
|
||||
var m Metrics
|
||||
|
||||
curQuorum, _, err := z.Conn.Get(strings.Join([]string{z.Path, "log", "quorum"}, "/"))
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(curQuorum, &q)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
m.Nodes = len(q.Quorum)
|
||||
m.Goroutines = runtime.NumGoroutine()
|
||||
m.Cgocall = runtime.NumCgoCall()
|
||||
m.MountsTotal = GetTotalMounts(q.Quorum)
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetTotalMounts ...
|
||||
func GetTotalMounts(n []Node) int {
|
||||
mounts := 0
|
||||
for _, node := range n {
|
||||
mounts = mounts + len(node.Mounts)
|
||||
}
|
||||
|
||||
return mounts
|
||||
}
|
Loading…
Reference in New Issue
Block a user