Home

Awesome

GoRelic is deprecated in favour of https://github.com/newrelic/go-agent

New Relic agent for Go runtime. It collect a lot of metrics about scheduler, garbage collector and memory allocator and send them to NewRelic.

Requirements

You have to install manually only first two dependencies. All other dependencies will be installed automatically by Go toolchain.

Installation

go get github.com/yvasiyarov/gorelic

and add to the initialization part of your application following code:

import (
    "github.com/yvasiyarov/gorelic"
)
....

agent := gorelic.NewAgent()
agent.Verbose = true
agent.NewrelicLicense = "YOUR NEWRELIC LICENSE KEY THERE"
agent.Run()

Middleware

If you using Beego, Martini, Revel, Kami or Gin framework you can hook up gorelic with your application by using the following middleware:

Configuration

Metrics reported by plugin

This agent use functions exposed by runtime or runtime/debug packages to collect most important information about Go runtime.

General metrics

Garbage collector metrics

All this metrics are measured in nanoseconds. Last 4 of them can be inaccurate if GC called more often then once in GCPollInterval. If in your workload GC is called more often - you can consider decreasing value of GCPollInterval. But be careful, ReadGCStats() blocks mheap, so its not good idea to set GCPollInterval to very low values.

Memory allocator

Process metrics

All this metrics collected once in MemoryAllocatorPollInterval. In order to collect this statistic agent use ReadMemStats() routine. This routine calls stoptheworld() internally and it block everything. So, please, consider this when you change MemoryAllocatorPollInterval value.

HTTP metrics

In order to collect HTTP metrics, handler functions must be wrapped using WrapHTTPHandlerFunc:

http.HandleFunc("/", agent.WrapHTTPHandlerFunc(handler))

Tracing Metrics

You can collect metrics for blocks of code or methods.

func anyMethod() {
  // Trace the whole method.
  t := agent.Tracer.BeginTrace("My traced method")
  defer t.EndTrace()
  
  ...Code here
  
  // Trace a block of code
  agent.Tracer.Trace("block trace", func() {
     .. Code here
  })
}

TODO