【问题标题】:Problems with Beego and Newrelic integrationBeego 和 Newrelic 集成的问题
【发布时间】:2020-01-09 11:49:43
【问题描述】:

我正在使用 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 许可证密钥和应用名称,如下所示:

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,我无法找到更好的文档来解决这个问题。

我错过了什么?

另外,还有其他方法可以将 newrelic 集成到 Beego 应用程序中吗?

附:我使用 Beego 过滤器作为预处理器,但我在控制器中使用 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"
} 

这可能是问题吗?我该如何解决这个问题?

【问题讨论】:

  • 日志中应该有更多数据。可以分享一下吗?
  • 您好@DmitryHarnitski,不幸的是,这是在dev 模式下打印的完整日志。
  • 试试这个beego.BConfig.RunMode == "dev"来启用详细模式。
  • @DmitryHarnitski 我在问题中添加了额外的日志。但是,我认为我有一个解决方案。原来,我找错地方了,这个plugin 实际上将数据发布到 NewRelic 的插件部分(我正在查看 APM,因为这是我需要的)。
  • 我将继续花时间连接 NewRelic go 插件以将指标发布到 APM,一旦我运行,我会在这里回答。非常感谢您的帮助:)

标签: go metrics newrelic beego


【解决方案1】:

我正在回答我自己的问题,因为我相信我已经找到了一种方法,并且它也可能对其他人有所帮助 - 显然这只是更努力地寻找现有插件的问题。我发现这个插件:https://github.com/sergeylanzman/newrelic_beego 正是我需要的。

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

  1. 开始交易
  2. NameTransaction
  3. 结束交易

并将这些作为过滤器插入到 Beego 环境中。在后台,作者使用了官方的 Newrelic Go 代理 (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 运行时统计信息,从而使其他插件过时(个人意见:))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    相关资源
    最近更新 更多