我试图捕获http处理程序,Latency等使用的系统资源。因为go lang没有newrelic代理。所以,我找到了这个goRelic代理人 其中说使用以下方式我可以捕获http指标:
agent.CollectHTTPStat = true
http.HandleFunc("/", agent.WrapHTTPHandlerFunc(handler))
但问题是我使用link中给出的自定义http处理程序,如下所示:
type appHandler struct {
*appContext
H func(*appContext, http.ResponseWriter, *http.Request) (int, error)
}
func (ah appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Updated to pass ah.appContext as a parameter to our handler type.
status, err := ah.H(ah.appContext, w, r)
if err != nil {
log.Printf("HTTP %d: %q", status, err)
switch status {
case http.StatusNotFound:
http.NotFound(w, r)
// And if we wanted a friendlier error page, we can
// now leverage our context instance - e.g.
// err := ah.renderTemplate(w, "http_404.tmpl", nil)
case http.StatusInternalServerError:
http.Error(w, http.StatusText(status), status)
default:
http.Error(w, http.StatusText(status), status)
}
}
}
func main() {
r := web.New()
// We pass an instance to our context pointer, and our handler.
r.Get("/", appHandler{context, IndexHandler})
graceful.ListenAndServe(":8086", r)
}
那么,我如何捕获此句柄的http指标,还是有其他工具可以捕获相似的指标?
答案 0 :(得分:0)
我只需要使用WrapHandler
。致suggestion的elithrar。
agent.CollectHTTPStat = true
http.HandleFunc("/", agent.WrapHandler(handler)