newrelic: Index | Files | Directories

package newrelic

import ""

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 {


Package Files

doc.go error.go log.go metric.go newrelic.go plugin.go


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 Uses

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

Log a message through the newrelic package

type Client Uses

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 Uses

func New(license string) *Client

New creates a new Client with the given license

func (*Client) AddPlugin Uses

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 Uses

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 Uses

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 Uses

func (ce CompositeError) Accumulate(err error) CompositeError

Accumulate errors into a single CompositeError

func (CompositeError) Error Uses

func (ce CompositeError) Error() string

Error implements the error interface.

type LoggingLevel Uses

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 Uses

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

Metric describes the interface for a metric

func NewMetric Uses

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

NewMetric creates a new metric definition using a closure

type Plugin Uses

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 Uses

func (p *Plugin) AddMetric(metric Metric)

AddMetric adds a new metric definition to the plugin/component



Package newrelic imports 11 packages (graph) and is imported by 2 packages. Updated 2016-07-17. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).