我正在使用Beego(https://beego.me)在Go中创建Web应用程序。
我需要捕获Newrelic中的应用程序监视和计量指标,并能够查看Newrelic中的所有事务。
我遵循了this文档,并正在使用Beego GoRelic在我的代码中初始化Newrelic代理。
这是我的router.go类-

import (
    "github.com/astaxie/beego"
    "github.com/yvasiyarov/beego_gorelic"
)

func init() {
    beego_gorelic.InitNewrelicAgent()
    beego.Router("path", &controller{}, "functionName") // code broken intentionally
}
在我的app.conf中,我提供了newrelic许可证 key 和应用名称,如下所示:
NewrelicLicense = "key"
newrelicAppname = "App Name"
当我以dev模式运行该应用程序时,我能够看到正在打印的指标,如下所示:
Send data:{
    "agent": {
        "host": "localhost",
        "version": "0.0.6",
        "pid": 13942
    },
    "components": [
        {
            "name": "Name",
            "guid": "com.github.yvasiyarov.GoRelic",
            "duration": 60,
            "metrics": {
                "Component/Runtime/GC/GCTime/Max[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Mean[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Min[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Percentile95[nanoseconds]": 0,
                "Component/Runtime/GC/NumberOfGCCalls[calls]": 0,
                "Component/Runtime/GC/PauseTotalTime[nanoseconds]": 0,
                "Component/Runtime/General/NOCgoCalls[calls]": 1,
                "Component/Runtime/General/NOGoroutines[goroutines]": 6,
                "Component/Runtime/Memory/InUse/Heap[bytes]": 538368,
                "Component/Runtime/Memory/InUse/MCacheInuse[bytes]": 13888,
                "Component/Runtime/Memory/InUse/MSpanInuse[bytes]": 13192,
                "Component/Runtime/Memory/InUse/Stack[bytes]": 360448,
                "Component/Runtime/Memory/InUse/Total[bytes]": 538368,
                "Component/Runtime/Memory/Operations/NoFrees[frees]": 128,
                "Component/Runtime/Memory/Operations/NoMallocs[mallocs]": 2903,
                "Component/Runtime/Memory/Operations/NoPointerLookups[lookups]": 0,
                "Component/Runtime/Memory/SysMem/BuckHash[bytes]": 3078,
                "Component/Runtime/Memory/SysMem/Heap[bytes]": 66748416,
                "Component/Runtime/Memory/SysMem/MCache[bytes]": 16384,
                "Component/Runtime/Memory/SysMem/MSpan[bytes]": 16384,
                "Component/Runtime/Memory/SysMem/Stack[bytes]": 360448,
                "Component/Runtime/Memory/SysMem/Total[bytes]": 69928960,
                "Component/http/responseTime/max[ms]": 0,
                "Component/http/responseTime/mean[ms]": 0,
                "Component/http/responseTime/min[ms]": 0,
                "Component/http/responseTime/percentile75[ms]": 0,
                "Component/http/responseTime/percentile90[ms]": 0,
                "Component/http/responseTime/percentile95[ms]": 0,
                "Component/http/throughput/1minute[rps]": 0,
                "Component/http/throughput/rateMean[rps]": 0
            }
        }
    ],
    "URL": "https://platform-api.newrelic.com/platform/v1/metrics"
}
这告诉我新的遗物代理已启动并正在捕获数据。
除此以外,我没有编写任何其他代码来将Newrelic集成到我的代码中。
这些设置和设置未将度量标准报告给Newrelic,而且Im无法找到更好的文档来解决此问题。
我想念什么?
另外,还有另一种将newrelic集成到Beego应用程序中的方法吗?
附言我没有将Beego筛选器用作预处理器,而是在 Controller 中使用了prepare方法来预处理请求。但是,该库似乎在Beego框架中添加了2个过滤器,如下所示:
    beego.InsertFilter("*", beego.BeforeRouter, InitNewRelicTimer, false)
    beego.InsertFilter("*", beego.FinishRouter, ReportMetricsToNewrelic, false)
其他日志:
2020/01/09 20:13:29 Init GC metrics collection. Poll interval 10 seconds.
2020/01/09 20:13:29 Init memory allocator metrics collection. Poll interval 60 seconds.
2020/01/09 20:13:29 Init HTTP metrics collection.
2020/01/09 20:13:29 [I] [gorelic.go:71] NewRelic agent started
2020/01/09 20:13:29 Can not get metrica: Runtime/System/Threads, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Can not get metrica: Runtime/System/FDSize, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Can not get metrica: Runtime/System/Memory/VmPeakSize, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Can not get metrica: Runtime/System/Memory/VmCurrent, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Can not get metrica: Runtime/System/Memory/RssPeak, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Can not get metrica: Runtime/System/Memory/RssCurrent, got error:this metrica was not implemented yet for darwin
2020/01/09 20:13:29 Send data:{
    "agent": {
        "host": "localhost",
        "version": "0.0.6",
        "pid": 14931
    },
    "components": [
        {
            "name": "App Name",
            "guid": "com.github.yvasiyarov.GoRelic",
            "duration": 60,
            "metrics": {
                "Component/Runtime/GC/GCTime/Max[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Mean[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Min[nanoseconds]": 0,
                "Component/Runtime/GC/GCTime/Percentile95[nanoseconds]": 0,
                "Component/Runtime/GC/NumberOfGCCalls[calls]": 0,
                "Component/Runtime/GC/PauseTotalTime[nanoseconds]": 0,
                "Component/Runtime/General/NOCgoCalls[calls]": 1,
                "Component/Runtime/General/NOGoroutines[goroutines]": 8,
                "Component/Runtime/Memory/InUse/Heap[bytes]": 591616,
                "Component/Runtime/Memory/InUse/MCacheInuse[bytes]": 13888,
                "Component/Runtime/Memory/InUse/MSpanInuse[bytes]": 16592,
                "Component/Runtime/Memory/InUse/Stack[bytes]": 393216,
                "Component/Runtime/Memory/InUse/Total[bytes]": 591616,
                "Component/Runtime/Memory/Operations/NoFrees[frees]": 132,
                "Component/Runtime/Memory/Operations/NoMallocs[mallocs]": 2988,
                "Component/Runtime/Memory/Operations/NoPointerLookups[lookups]": 0,
                "Component/Runtime/Memory/SysMem/BuckHash[bytes]": 3078,
                "Component/Runtime/Memory/SysMem/Heap[bytes]": 66715648,
                "Component/Runtime/Memory/SysMem/MCache[bytes]": 16384,
                "Component/Runtime/Memory/SysMem/MSpan[bytes]": 32768,
                "Component/Runtime/Memory/SysMem/Stack[bytes]": 393216,
                "Component/Runtime/Memory/SysMem/Total[bytes]": 69928960,
                "Component/http/responseTime/max[ms]": 0,
                "Component/http/responseTime/mean[ms]": 0,
                "Component/http/responseTime/min[ms]": 0,
                "Component/http/responseTime/percentile75[ms]": 0,
                "Component/http/responseTime/percentile90[ms]": 0,
                "Component/http/responseTime/percentile95[ms]": 0,
                "Component/http/throughput/1minute[rps]": 0,
                "Component/http/throughput/rateMean[rps]": 0
            }
        }
    ],
    "URL": "https://platform-api.newrelic.com/platform/v1/metrics"
}
这可能是问题吗?我该如何解决?

最佳答案

我回答自己的问题,因为我相信我已经找到了一种方法,它可能也会对其他人有所帮助-显然,这只是为现有插件加倍努力的问题。我发现这个插件:https://github.com/sergeylanzman/newrelic_beego确实满足我的需求。

如果我们观察代码,那么作者创建了3种方法-

  • StartTransaction
  • 名称交易
  • EndTransaction

  • 并将它们作为过滤器插入Beego环境中。在幕后,作者使用了官方的Newrelic Go Agent(https://github.com/newrelic/go-agent),并正在使用Transactions报告APM数据。

    这是来自注册了3个过滤器的插件的示例代码-
        beego.InsertFilter("*", beego.BeforeRouter, StartTransaction, false)
        beego.InsertFilter("*", beego.AfterExec, NameTransaction, false)
        beego.InsertFilter("*", beego.FinishRouter, EndTransaction, false)
        beego.Info("NewRelic agent start")
    

    它使用Beego的Context结构来跟踪跨函数的事务数据(如Context文档中所规定)

    我将继续对此进行更多探索,并在进行时添加对外部调用,数据库调用和分布式跟踪的跟踪,但这解决了我的问题。

    附言我已经停止使用较早使用的插件,因为此软件包还向NewRelic报告了Go Runtime统计信息,使其他插件过时了(个人观点:))

    关于go - Beego和Newrelic集成的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59663347/

    10-12 19:08