簡體   English   中英

使用自定義http處理程序的goRelic代理捕獲HTTP指標

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

我試圖捕獲http處理程序,Latency等使用的系統資源。因為沒有用於go lang的newrelic代理。 因此,我找到了這個goRelic代理。
這表示使用以下方法可以捕獲http指標:

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

但是問題是我正在使用鏈接中給出的自定義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指標,或者是否有其他工具可以捕獲相似的指標?

我只需要使用WrapHandler 歸功於elithrar的建議

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM