简体   繁体   English

使用自定义http处理程序的goRelic代理捕获HTTP指标

[英]Capture HTTP metrics using goRelic agent of custom http handler

I was trying to capture the system resources used by http handler, Latency etc. Since there is no newrelic agent for go lang. 我试图捕获http处理程序,Latency等使用的系统资源。因为没有用于go lang的newrelic代理。 So, I found this goRelic agent. 因此,我找到了这个goRelic代理。
Which says using the folowing way i can capture the http metric: 这表示使用以下方法可以捕获http指标:

agent.CollectHTTPStat  = true
http.HandleFunc("/", agent.WrapHTTPHandlerFunc(handler))

But the problem is i am using custom http handler given in the link as follows: 但是问题是我正在使用链接中给出的自定义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)    

}

So, how do i capture the http metric for this handle or is there any other tool by which i can capture the similar metrics? 那么,如何捕获此句柄的http指标,或者是否有其他工具可以捕获相似的指标?

I just need to use WrapHandler . 我只需要使用WrapHandler Credits to elithrar for the suggestion . 归功于elithrar的建议

agent.CollectHTTPStat  = true
http.HandleFunc("/", agent.WrapHandler(handler)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM