newrelic

package
v0.23.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2020 License: Apache-2.0 Imports: 16 Imported by: 19

Documentation

Overview

Package newrelic is a convenience package that provides a programmatic API surface area for interacting with all the New Relic One products encompassed by this project. Refer to each package's documentation to learn more about its capabilities.

Authentication

You will need a valid Personal API key and/or Admin's API key to communicate with the backend New Relic APIs that this client communicates with. See the API key documentation below for more information on how to locate this key:

https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

Example (Basic)
// Initialize the client.
client, err := New(
	ConfigAdminAPIKey(os.Getenv("NEW_RELIC_ADMIN_API_KEY")),
	ConfigPersonalAPIKey(os.Getenv("NEW_RELIC_API_KEY")),
	ConfigRegion(region.US),
	ConfigLogLevel("DEBUG"),
)
if err != nil {
	log.Fatal("error initializing client:", err)
}

// Interact with the New Relic Alerts product.
policies, err := client.Alerts.ListPolicies(&alerts.ListPoliciesParams{
	Name: "Example policy",
})
if err != nil {
	log.Fatal("error listing alert policies:", err)
}

fmt.Printf("Policies: %v+\n", policies)

// Interact with the New Relic APM product.
apps, err := client.APM.ListApplications(&apm.ListApplicationsParams{
	Name: "Example application",
})
if err != nil {
	log.Fatal("error listing APM applications:", err)
}

fmt.Printf("Applications: %v+\n", apps)

// Interact with New Relic Insights dashboards.
dashboards, err := client.Dashboards.ListDashboards(&dashboards.ListDashboardsParams{
	Title: "Example dashboard",
})
if err != nil {
	log.Fatal("error listing dashboards:", err)
}

fmt.Printf("Dashboards: %v+\n", dashboards)

// Interact with New Relic One entities.
entities, err := client.Entities.SearchEntities(entities.SearchEntitiesParams{
	Name: "Example entity",
})
if err != nil {
	log.Fatal("error listing entities:", err)
}

fmt.Printf("Entities: %v+\n", entities)

// Interact with the New Relic One NerdGraph API.
query := "{ actor { user { email } } }"

resp, err := client.NerdGraph.Query(query, nil)
if err != nil {
	log.Fatal("error executing query:", err)
}

fmt.Printf("Query response: %v+\n", resp)

// Interact with the New Relic Plugins product.
plugins, err := client.Plugins.ListPlugins(&plugins.ListPluginsParams{
	IDs: []int{1234, 5678},
})
if err != nil {
	log.Fatal("error listing plugins:", err)
}

fmt.Printf("Plugins: %v+\n", plugins)

// Interact with the New Relic Synthetics product.
monitors, err := client.Synthetics.ListMonitors()
if err != nil {
	log.Fatal("error listing monitors:", err)
}

fmt.Printf("Synthetics monitors: %v+\n", monitors)

// Interact with the New Relic One Workloads product.
workloads, err := client.Workloads.ListWorkloads(12345678)
if err != nil {
	log.Fatal("error listing workloads:", err)
}

fmt.Printf("Synthetics monitors: %v+\n", workloads)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigOption added in v0.3.0

type ConfigOption func(*config.Config) error

ConfigOption configures the Config when provided to NewApplication. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigAdminAPIKey added in v0.12.0

func ConfigAdminAPIKey(adminAPIKey string) ConfigOption

ConfigAdminAPIKey sets the New Relic Admin API key this client will use. One of ConfigAPIKey or ConfigAdminAPIKey must be used to create a client. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigBaseURL added in v0.3.0

func ConfigBaseURL(url string) ConfigOption

ConfigBaseURL sets the base URL used to make requests to the REST API V2.

func ConfigHTTPTimeout added in v0.3.0

func ConfigHTTPTimeout(t time.Duration) ConfigOption

ConfigHTTPTimeout sets the timeout for HTTP requests.

func ConfigHTTPTransport added in v0.3.0

func ConfigHTTPTransport(transport http.RoundTripper) ConfigOption

ConfigHTTPTransport sets the HTTP Transporter.

func ConfigInfrastructureBaseURL added in v0.7.0

func ConfigInfrastructureBaseURL(url string) ConfigOption

ConfigInfrastructureBaseURL sets the base URL used to make requests to the Infrastructure API.

func ConfigLogJSON added in v0.7.0

func ConfigLogJSON(logJSON bool) ConfigOption

ConfigLogJSON toggles JSON formatting on for the logger if set to true.

func ConfigLogLevel added in v0.7.0

func ConfigLogLevel(logLevel string) ConfigOption

ConfigLogLevel sets the log level for the client.

func ConfigLogger added in v0.7.0

func ConfigLogger(logger logging.Logger) ConfigOption

ConfigLogger can be used to customize the client's logger. Custom loggers must conform to the logging.Logger interface.

func ConfigNerdGraphBaseURL added in v0.7.0

func ConfigNerdGraphBaseURL(url string) ConfigOption

ConfigNerdGraphBaseURL sets the base URL used to make requests to the NerdGraph API.

func ConfigPersonalAPIKey added in v0.5.0

func ConfigPersonalAPIKey(apiKey string) ConfigOption

ConfigPersonalAPIKey sets the New Relic Admin API key this client will use. One of ConfigPersonalAPIKey or ConfigAdminAPIKey must be used to create a client. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigRegion added in v0.3.0

func ConfigRegion(r region.Name) ConfigOption

ConfigRegion sets the New Relic Region this client will use.

func ConfigServiceName added in v0.10.1

func ConfigServiceName(name string) ConfigOption

ConfigServiceName sets the service name logged

func ConfigSyntheticsBaseURL added in v0.7.0

func ConfigSyntheticsBaseURL(url string) ConfigOption

ConfigSyntheticsBaseURL sets the base URL used to make requests to the Synthetics API.

func ConfigUserAgent added in v0.3.0

func ConfigUserAgent(ua string) ConfigOption

ConfigUserAgent sets the HTTP UserAgent for API requests.

type NewRelic

type NewRelic struct {
	Alerts      alerts.Alerts
	APM         apm.APM
	Dashboards  dashboards.Dashboards
	Entities    entities.Entities
	Plugins     plugins.Plugins
	Synthetics  synthetics.Synthetics
	NerdGraph   nerdgraph.NerdGraph
	NerdStorage nerdstorage.NerdStorage
	Workloads   workloads.Workloads
}

NewRelic is a collection of New Relic APIs.

func New

func New(opts ...ConfigOption) (*NewRelic, error)

New returns a collection of New Relic APIs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL