Hi All,
I wonder if anyone is using https://github.com/rcrowley/go-metrics to provide metrics and healthcheck status for their app ? If not, what library are you using to provide custom metrics and healtcheck results ?
Using go-metrics is quite straight forward, but I’m having trouble creating a healthcheck … I’ve tried this :
hc := metrics.NewHealthcheck(func(h metrics.Healthcheck) {
if 0 < rand.Intn(2) {
h.Healthy()
} else {
h.Unhealthy(errors.New("baz"))
}
})
r.Register("baz", hc)
which I took from here : https://github.com/yowenter/http_ngrok/blob/e625ce5980fefc9700aa4cae15e705d668373f03/src/github.com/inconshreveable/go-metrics/cmd/metrics-example/metrics-example.go#L53
but I then get the following when calling /debug/metrics on my app :
2017/05/05 10:53:12 http: panic serving [::1]:61521: unsupported type for 'baz': *metrics.StandardHealthcheck
goroutine 52 [running]:
net/http.(*conn).serve.func1(0xc4201f80a0)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x1450da0, 0xc4201ace60)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/rcrowley/go-metrics/exp.(*exp).syncToExpvar.func1(0x14f410e, 0x3, 0x1493860, 0xc4200e1920)
/Users/ale/projects/go/src/github.com/rcrowley/go-metrics/exp/exp.go:153 +0x501
github.com/rcrowley/go-metrics.(*StandardRegistry).Each(0xc420172260, 0xc4201ace30)
/Users/ale/projects/go/src/github.com/rcrowley/go-metrics/registry.go:65 +0xc0
github.com/rcrowley/go-metrics/exp.(*exp).syncToExpvar(0xc4200e1900)
/Users/ale/projects/go/src/github.com/rcrowley/go-metrics/exp/exp.go:155 +0x75
github.com/rcrowley/go-metrics/exp.(*exp).expHandler(0xc4200e1900, 0x1716160, 0xc4201d8380, 0xc42006ad00)
/Users/ale/projects/go/src/github.com/rcrowley/go-metrics/exp/exp.go:21 +0x35
github.com/rcrowley/go-metrics/exp.(*exp).(github.com/rcrowley/go-metrics/exp.expHandler)-fm(0x1716160, 0xc4201d8380, 0xc42006ad00)
/Users/ale/projects/go/src/github.com/rcrowley/go-metrics/exp/exp.go:50 +0x48
net/http.HandlerFunc.ServeHTTP(0xc4201722e0, 0x1716160, 0xc4201d8380, 0xc42006ad00)
/usr/local/go/src/net/http/server.go:1942 +0x44
net/http.(*ServeMux).ServeHTTP(0x1745e20, 0x1716160, 0xc4201d8380, 0xc42006ad00)
/usr/local/go/src/net/http/server.go:2238 +0x130
net/http.serverHandler.ServeHTTP(0xc42001a0b0, 0x1716160, 0xc4201d8380, 0xc42006ad00)
/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4201f80a0, 0x17168e0, 0xc4201b3a80)
/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2668 +0x2ce
the actual check i want to implement is checking a http endpoint, similar to this :
hc := metrics.NewHealthcheck(func(h metrics.Healthcheck) {
_, err := http.Get("https://www.google.com")
if err != nil {
h.Unhealthy(errors.New("error description or output"))
} else {
h.Healthy()
}
})
r.Register("endpoint-X", hc)
both end up in the same error though …
Any help would be really appreciated!
Thanks
Alex