dongqiangse6623 2016-10-06 08:04
浏览 63
已采纳

最重要的+新的遗物APM

I want use new relic APM in the mattermost application. In order to monitor the performance the application I have added the code (as mentioned in new relic) just above the createpost api request handler in api/post.go file.

func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
    config := newrelic.NewConfig("mylocalstarfp", "####12337")
    app, err1 := newrelic.NewApplication(config)
    fmt.Println("config")
    fmt.Println(config)
    if nil != err1 {
        fmt.Println(err1)
        // os.Exit(1)
    }
    txn := app.StartTransaction("mylocalstar",w, r)
    defer txn.End()
    post := model.PostFromJson(r.Body)
    .....
    .......
}

The application is displayed on new relic dashboard and attributes like CPU and Memory are displayed.But no Response time and Throughput attributes are displayed.

As per new relic documentation (https://github.com/newrelic/go-agent) this code has to be added in main /init block or just at start of function where we need to monitor the performance.

But I am not able to monitor as response time and throughput attributes are not being displayed. May be I am adding the code at wrong place. Also I have tried to add the code at beginning of main() function in mattermost.go file. But no success. Please suggest as to where I have to add the code.

Secondly, they have also mentioned that:

If you are using the standard HTTP library package, you can create transactions by wrapping HTTP requests, as an alternative to instrumenting a function's code.
Here is a before-and-after example of an HTTP handler being wrapped:

Before:

http.HandleFunc("/users", usersHandler)

After:

http.HandleFunc(newrelic.WrapHandleFunc(app, "/users", usersHandler))

This automatically starts and ends a transaction with the request and response writer.

As per this where should I add the code in Mattermost?

  • 写回答

2条回答 默认 最新

  • dsxon40042 2016-10-15 05:25
    关注

    Got the solution, hence posting for others to refer. Solved the issue to track each request by this code in mattermost:

    BaseRoutes.NeedTeam.Handle(newrelic.WrapHandle(app, "/users", ApiAppHandler(usersHandler))).Methods("POST")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题