doupa1883 2016-04-11 13:46
浏览 44

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

I was trying to capture the system resources used by http handler, Latency etc. Since there is no newrelic agent for go lang. So, I found this goRelic agent.
Which says using the folowing way i can capture the http metric:

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

But the problem is i am using custom http handler given in the link as follows:

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?

  • 写回答

1条回答 默认 最新

  • douguo7431 2016-04-12 07:51
    关注

    I just need to use WrapHandler. Credits to elithrar for the suggestion.

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了