Back to

Package newrelic

Latest Go to latest

The latest major version is .

Published: Apr 19, 2016 | License: MIT | Module:


package newrelic is an client for NewRelic's plugin API.

Simple usage:

import (


func main() {
	client := newrelic.New("abc123") // license key goes here
	myplugin := &Plugin{
		Name: "My Plugin",
		GUID: "com.example.newrelic.myplugin",

	// the easiest way to add a metric is to use a closure
	metric := newrelic.NewMetric("MyApp/Total CGO Calls",
		func() (float64, error) { return float64(runtime.NumCgoCall()), nil })

	// call run after doing all plugin config

	// main application code here..
	for {



const (
	// DefaultPollInterval is the recommended poll interval for NewRelic plugins
	DefaultPollInterval = time.Minute


var LogLevel = LogError

LogLevel can be set globally to tune logging levels

var Logger = l.New(os.Stderr, "newrelic", l.LstdFlags)

Logger is the logger used by this package. Set to a custom logger if needed.

func Log

func Log(level LoggingLevel, format string, a ...interface{})

Log a message through the newrelic package

type Client

type Client struct {
	License      string
	PollInterval time.Duration
	Plugins      []*Plugin

	// HTTPClient is exposed to allow users to configure proxies, etc.
	HTTPClient *http.Client
	// contains filtered or unexported fields

Client encapsulates a NewRelic plugin client and all the plugins it reports

func New

func New(license string) *Client

New creates a new Client with the given license

func (*Client) AddPlugin

func (c *Client) AddPlugin(p *Plugin)

AddPlugin appends a plugin to a clients list of plugins. A plugin is a "component" in the API call and can be configured (with a unique GUID) in the NewRelic UI.

func (*Client) Run

func (c *Client) Run()

Run starts the NewRelic client asynchronously. Do not alter the configuration of plugins after starting the client, as this creates race conditions.

type CompositeError

type CompositeError []error

CompositeError accumulates errors from calling metric.Poll(). These errors are logged but otherwise ignored so that functioning metrics may still be collected.

func (CompositeError) Accumulate

func (ce CompositeError) Accumulate(err error) CompositeError

Accumulate errors into a single CompositeError

func (CompositeError) Error

func (ce CompositeError) Error() string

Error implements the error interface.

type LoggingLevel

type LoggingLevel int

LoggingLevel enumerates package log levels

const (
	// LogAll logs verbosely
	LogAll LoggingLevel = 0
	// LogDebug logs debug or above
	LogDebug LoggingLevel = 20
	// LogInfo logs informational or above
	LogInfo LoggingLevel = 30
	// LogError only logs errors
	LogError LoggingLevel = 50
	// LogNone makes the package silent
	LogNone LoggingLevel = 100

type Metric

type Metric interface {
	Name() string
	Units() string
	Poll() (float64, error)

Metric describes the interface for a metric

func NewMetric

func NewMetric(name, units string, pollFn func() (float64, error)) Metric

NewMetric creates a new metric definition using a closure

type Plugin

type Plugin struct {
	Name string
	GUID string
	// contains filtered or unexported fields

Plugin encapsulates all data and state for a plug-in (AKA Component)

func (*Plugin) AddMetric

func (p *Plugin) AddMetric(metric Metric)

AddMetric adds a new metric definition to the plugin/component

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier