apm

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package apm provides a programmatic API for interacting with the New Relic APM product.

Package apm provides a programmatic API for interacting with the New Relic APM product. It can be used for a variety of operations, including:

- Reading, updating, and deleting APM applications

- Creating, reading, and deleting APM deployment markers

- Reading APM key transactions

- Creating, reading, and deleting APM labels

Authentication

You will need a valid API key to communicate with the backend New Relic APIs that provide this functionality. Using a Personal API key is the preferred method but an Admin's API key will also work. See the API key documentation below for more information on how to locate these keys:

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

Labels

New Relic One entity tags are currently the preferred method for organizing your New Relic resources. Consider using entity tags via the `entities` package if you are just getting started. More information about entity tags and APM labels can be found at the following URL:

https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/core-concepts/tagging-use-tags-organize-group-what-you-monitor#labels

Example (Application)
// Initialize the client configuration.  A Personal API key or Admin API key
// is required to communicate with the backend API.
cfg := config.New()
cfg.AdminAPIKey = os.Getenv("NEW_RELIC_ADMIN_API_KEY")
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

// Initialize the client.
client := New(cfg)

// Search the applications for the current account by name.
listParams := &ListApplicationsParams{
	Name: "Example application",
}

apps, err := client.ListApplications(listParams)
if err != nil {
	log.Fatal("error listing applications:", err)
}

// Get an application by ID.  This example assumes that at least one application
// has been returned by the list endpoint, but in practice it is possible
// that an empty slice is returned.
app, err := client.GetApplication(apps[0].ID)
if err != nil {
	log.Fatal("error getting application:", err)
}

// Update an application's settings.  The following example updates the
// application's Apdex threshold.
updateParams := UpdateApplicationParams{
	Name: app.Name,
	Settings: ApplicationSettings{
		AppApdexThreshold: 0.6,
	},
}

app, err = client.UpdateApplication(app.ID, updateParams)
if err != nil {
	log.Fatal("error updating application settings:", err)
}

// Delete an application that is no longer reporting data.
if !app.Reporting {
	_, err = client.DeleteApplication(app.ID)
	if err != nil {
		log.Fatal("error deleting application:", err)
	}
}
Output:

Example (KeyTransaction)
// Initialize the client configuration.  A Personal API key or Admin API key
// is required to communicate with the backend API.
cfg := config.New()
cfg.AdminAPIKey = os.Getenv("NEW_RELIC_ADMIN_API_KEY")
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

// Initialize the client.
client := New(cfg)

// Search the key transactions for the current account by name.
listParams := &ListKeyTransactionsParams{
	Name: "Example key transaction",
}

transactions, err := client.ListKeyTransactions(listParams)
if err != nil {
	log.Fatal("error listing key transactions:", err)
}

// Get a key transaction by ID.  This example assumes that at least one key
// transaction has been returned by the list endpoint, but in practice it is
// possible that an empty slice is returned.
transaction, err := client.GetKeyTransaction(transactions[0].ID)
if err != nil {
	log.Fatal("error getting key transaction:", err)
}

// Output the key transaction's health status.
fmt.Printf("Key transaction status: %s\n", transaction.HealthStatus)
Output:

Example (Labels)
// Initialize the client configuration.  A Personal API key or Admin API key
// is required to communicate with the backend API.
cfg := config.New()
cfg.AdminAPIKey = os.Getenv("NEW_RELIC_ADMIN_API_KEY")
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

// Initialize the client.
client := New(cfg)

// Get an APM application by ID.
app, err := client.GetApplication(12345678)
if err != nil {
	log.Fatal("error getting application:", err)
}

// List the existing labels for this account.
labels, err := client.ListLabels()
if err != nil {
	log.Fatal("error listing labels:", err)
}

// Output the concatenated label key and associated application IDs for each.
for _, l := range labels {
	fmt.Printf("Label key: %s, Application IDs: %v\n", l.Key, l.Links.Applications)
}

// Add a label to the application that describes its data center's location.
label := Label{
	Category: "Datacenter",
	Name:     "East",
	Links: LabelLinks{
		Applications: []int{app.ID},
	},
}

l, err := client.CreateLabel(label)
if err != nil {
	log.Fatal("error creating label:", err)
}

// Delete a label from all linked applications and servers.
_, err = client.DeleteLabel(l.Key)
if err != nil {
	log.Fatal("error deleting label:", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APM

type APM struct {
	// contains filtered or unexported fields
}

APM is used to communicate with the New Relic APM product.

func New

func New(config config.Config) APM

New is used to create a new APM client instance.

func (*APM) CreateDeployment

func (a *APM) CreateDeployment(applicationID int, deployment Deployment) (*Deployment, error)

CreateDeployment creates a deployment marker for an application.

func (*APM) CreateLabel

func (a *APM) CreateLabel(label Label) (*Label, error)

CreateLabel creates a new label within an account.

func (*APM) DeleteApplication

func (a *APM) DeleteApplication(applicationID int) (*Application, error)

DeleteApplication is used to delete a New Relic application. This process will only succeed if the application is no longer reporting data.

func (*APM) DeleteDeployment

func (a *APM) DeleteDeployment(applicationID int, deploymentID int) (*Deployment, error)

DeleteDeployment deletes a deployment marker for an application.

func (*APM) DeleteLabel

func (a *APM) DeleteLabel(key string) (*Label, error)

DeleteLabel deletes a label by key. A label's key is a string hash formatted as <Category>:<Name>.

func (*APM) GetApplication

func (a *APM) GetApplication(applicationID int) (*Application, error)

GetApplication is used to retrieve a single New Relic application.

func (*APM) GetKeyTransaction

func (a *APM) GetKeyTransaction(id int) (*KeyTransaction, error)

GetKeyTransaction returns a specific key transaction by ID.

func (*APM) GetLabel

func (a *APM) GetLabel(key string) (*Label, error)

GetLabel gets a label by key. A label's key is a string hash formatted as <Category>:<Name>.

func (*APM) GetMetricData added in v0.8.0

func (a *APM) GetMetricData(applicationID int, params MetricDataParams) ([]*MetricData, error)

GetMetricData is used to retrieve a list of values for each of the requested metrics.

https://rpm.newrelic.com/api/explore/applications/metric_data

func (*APM) GetMetricNames added in v0.8.0

func (a *APM) GetMetricNames(applicationID int, params MetricNamesParams) ([]*MetricName, error)

GetMetricNames is used to retrieve a list of known metrics and their value names for the given resource.

https://rpm.newrelic.com/api/explore/applications/metric_names

func (*APM) ListApplications

func (a *APM) ListApplications(params *ListApplicationsParams) ([]*Application, error)

ListApplications is used to retrieve New Relic applications.

func (*APM) ListDeployments

func (a *APM) ListDeployments(applicationID int) ([]*Deployment, error)

ListDeployments returns deployments for an application.

func (*APM) ListKeyTransactions

func (a *APM) ListKeyTransactions(params *ListKeyTransactionsParams) ([]*KeyTransaction, error)

ListKeyTransactions returns all key transactions for an account.

func (*APM) ListLabels

func (a *APM) ListLabels() ([]*Label, error)

ListLabels returns the labels within an account.

func (*APM) UpdateApplication

func (a *APM) UpdateApplication(applicationID int, params UpdateApplicationParams) (*Application, error)

UpdateApplication is used to update a New Relic application's name and/or settings.

type Application

type Application struct {
	ID             int                       `json:"id,omitempty"`
	Name           string                    `json:"name,omitempty"`
	Language       string                    `json:"language,omitempty"`
	HealthStatus   string                    `json:"health_status,omitempty"`
	Reporting      bool                      `json:"reporting"`
	LastReportedAt string                    `json:"last_reported_at,omitempty"`
	Summary        ApplicationSummary        `json:"application_summary,omitempty"`
	EndUserSummary ApplicationEndUserSummary `json:"end_user_summary,omitempty"`
	Settings       ApplicationSettings       `json:"settings,omitempty"`
	Links          ApplicationLinks          `json:"links,omitempty"`
}

Application represents information about a New Relic application.

type ApplicationEndUserSummary

type ApplicationEndUserSummary struct {
	ResponseTime float64 `json:"response_time"`
	Throughput   float64 `json:"throughput"`
	ApdexTarget  float64 `json:"apdex_target"`
	ApdexScore   float64 `json:"apdex_score"`
}

ApplicationEndUserSummary represents performance information about a New Relic application.

type ApplicationLinks struct {
	ServerIDs     []int `json:"servers,omitempty"`
	HostIDs       []int `json:"application_hosts,omitempty"`
	InstanceIDs   []int `json:"application_instances,omitempty"`
	AlertPolicyID int   `json:"alert_policy"`
}

ApplicationLinks represents all the links for a New Relic application.

type ApplicationSettings

type ApplicationSettings struct {
	AppApdexThreshold        float64 `json:"app_apdex_threshold,omitempty"`
	EndUserApdexThreshold    float64 `json:"end_user_apdex_threshold,omitempty"`
	EnableRealUserMonitoring bool    `json:"enable_real_user_monitoring"`
	UseServerSideConfig      bool    `json:"use_server_side_config"`
}

ApplicationSettings represents some of the settings of a New Relic application.

type ApplicationSummary

type ApplicationSummary struct {
	ResponseTime            float64 `json:"response_time"`
	Throughput              float64 `json:"throughput"`
	ErrorRate               float64 `json:"error_rate"`
	ApdexTarget             float64 `json:"apdex_target"`
	ApdexScore              float64 `json:"apdex_score"`
	HostCount               int     `json:"host_count"`
	InstanceCount           int     `json:"instance_count"`
	ConcurrentInstanceCount int     `json:"concurrent_instance_count"`
}

ApplicationSummary represents performance information about a New Relic application.

type ApplicationsInterface added in v0.17.0

type ApplicationsInterface interface {
	// contains filtered or unexported methods
}

ApplicationsInterface interface should be refactored to be a global interface for fetching NR type things

type Deployment

type Deployment struct {
	Links       *DeploymentLinks `json:"links,omitempty"`
	ID          int              `json:"id,omitempty"`
	Revision    string           `json:"revision"`
	Changelog   string           `json:"changelog,omitempty"`
	Description string           `json:"description,omitempty"`
	User        string           `json:"user,omitempty"`
	Timestamp   string           `json:"timestamp,omitempty"`
}

Deployment represents information about a New Relic application deployment.

type DeploymentLinks struct {
	ApplicationID int `json:"application,omitempty"`
}

DeploymentLinks contain the application ID for the deployment.

type KeyTransaction

type KeyTransaction struct {
	ID              int                       `json:"id,omitempty"`
	Name            string                    `json:"name,omitempty"`
	TransactionName string                    `json:"transaction_name,omitempty"`
	HealthStatus    string                    `json:"health_status,omitempty"`
	LastReportedAt  string                    `json:"last_reported_at,omitempty"`
	Reporting       bool                      `json:"reporting"`
	Summary         ApplicationSummary        `json:"application_summary,omitempty"`
	EndUserSummary  ApplicationEndUserSummary `json:"end_user_summary,omitempty"`
	Links           KeyTransactionLinks       `json:"links,omitempty"`
}

KeyTransaction represents information about a New Relic key transaction.

type KeyTransactionLinks struct {
	Application int `json:"application,omitempty"`
}

KeyTransactionLinks represents associations for a key transaction.

type Label

type Label struct {
	Key      string     `json:"key,omitempty"`
	Category string     `json:"category,omitempty"`
	Name     string     `json:"name,omitempty"`
	Links    LabelLinks `json:"links,omitempty"`
}

Label represents a New Relic label.

type LabelLinks struct {
	Applications []int `json:"applications"`
	Servers      []int `json:"servers"`
}

LabelLinks represents external references on the Label.

type ListApplicationsParams

type ListApplicationsParams struct {
	Name     string `url:"filter[name],omitempty"`
	Host     string `url:"filter[host],omitempty"`
	IDs      []int  `url:"filter[ids],omitempty,comma"`
	Language string `url:"filter[language],omitempty"`
}

ListApplicationsParams represents a set of filters to be used when querying New Relic applications.

type ListKeyTransactionsParams

type ListKeyTransactionsParams struct {
	Name string `url:"filter[name],omitempty"`
	IDs  []int  `url:"filter[ids],omitempty,comma"`
}

ListKeyTransactionsParams represents a set of filters to be used when querying New Relic key transactions.

type MetricData added in v0.8.0

type MetricData struct {
	Name       string            `json:"name,omitempty"`
	Timeslices []MetricTimeslice `json:"timeslices,omitempty"`
}

MetricData is the series of time windows and the data therein, for a given metric name.

type MetricDataParams added in v0.8.0

type MetricDataParams struct {
	Names     []string   `url:"names,omitempty"`
	Values    []string   `url:"values,omitempty"`
	From      *time.Time `url:"from,omitempty"`
	To        *time.Time `url:"to,omitempty"`
	Period    int        `url:"period,omitempty"`
	Summarize bool       `url:"summarize,omitempty"`
	Raw       bool       `url:"raw,omitempty"`
}

MetricDataParams are the request parameters for the /metrics/data.json endpoint.

type MetricName added in v0.8.0

type MetricName struct {
	Name   string   `json:"name,omitempty"`
	Values []string `json:"values,omitempty"`
}

MetricName is the name of a metric, and the names of the values that can be retrieved.

type MetricNamesParams added in v0.8.0

type MetricNamesParams struct {
	Name string `url:"name,omitempty"`
}

MetricNamesParams are the request parameters for the /metrics.json endpoint.

type MetricTimeslice added in v0.8.0

type MetricTimeslice struct {
	From   *time.Time            `json:"from"`
	To     *time.Time            `json:"to"`
	Values MetricTimesliceValues `json:"values"`
}

MetricTimeslice is a single window of time for a given metric, with the associated metric data.

type MetricTimesliceValues added in v0.8.0

type MetricTimesliceValues struct {
	AsPercentage           float64 `json:"as_percentage"`
	AverageTime            float64 `json:"average_time"`
	CallsPerMinute         float64 `json:"calls_per_minute"`
	MaxValue               float64 `json:"max_value"`
	TotalCallTimePerMinute float64 `json:"total_call_time_per_minute"`
	Utilization            float64 `json:"utilization"`
}

MetricTimesliceValues is the collection of metric values for a single time slice.

type UpdateApplicationParams

type UpdateApplicationParams struct {
	Name     string
	Settings ApplicationSettings
}

UpdateApplicationParams represents a set of parameters to be used when updating New Relic applications.

Jump to

Keyboard shortcuts

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