nrdb

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Overview

Package nrdb provides a programmatic API for interacting with the New Relic Database. It can be used to run freeform NRQL queries. Details on how to use the New Relic Query Language are available here:

https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql

Authentication

You will need a valid Personal API key to communicate with the backend New Relic API that provides this functionality. 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

Package nrdb provides a programmatic API for interacting with NRDB, New Relic's Datastore

Package nrdb provides a programmatic API for interacting with NRDB, New Relic's Datastore

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

accountID, err := strconv.Atoi(os.Getenv("NEW_RELIC_ACCOUNT_ID"))
if err != nil {
	log.Fatal("example requires NEW_RELIC_ACCONT_ID to be set, got error: ", err)
}

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

// Execute a NRQL query to retrieve the average duration of transactions for
// the "Example application" app.
query := Nrql("SELECT average(duration) FROM Transaction TIMESERIES WHERE appName = 'Example application'")

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

var durations []float64
for _, r := range resp.Results {
	durations = append(durations, r["average.duration"].(float64))
}

// Output the raw time series values for transaction duration.
fmt.Printf("durations: %v\n", durations)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EpochMilliseconds

type EpochMilliseconds serialization.EpochTime

EpochMilliseconds - The `EpochMilliseconds` scalar represents the number of milliseconds since the Unix epoch

func (EpochMilliseconds) MarshalJSON added in v0.30.0

func (t EpochMilliseconds) MarshalJSON() ([]byte, error)

MarshalJSON wrapper for EpochMilliseconds

func (*EpochMilliseconds) UnmarshalJSON added in v0.30.0

func (t *EpochMilliseconds) UnmarshalJSON(s []byte) error

UnmarshalJSON wrapper for EpochMilliseconds

type EpochSeconds added in v0.30.0

type EpochSeconds serialization.EpochTime

EpochSeconds - The `EpochSeconds` scalar represents the number of seconds since the Unix epoch

func (EpochSeconds) MarshalJSON added in v0.30.0

func (t EpochSeconds) MarshalJSON() ([]byte, error)

MarshalJSON wrapper for EpochSeconds

func (*EpochSeconds) UnmarshalJSON added in v0.30.0

func (t *EpochSeconds) UnmarshalJSON(s []byte) error

UnmarshalJSON wrapper for EpochSeconds

type EventAttributeDefinition

type EventAttributeDefinition struct {
	/* Category - This attribute's category */
	Category string `json:"category"`
	/* Definition - A short description of this attribute */
	Definition string `json:"definition"`
	/* DocumentationUrl - The New Relic docs page for this attribute */
	DocumentationUrl string `json:"documentationUrl"`
	/* Label - The human-friendly formatted name of the attribute */
	Label string `json:"label"`
	/* Name - The name of the attribute */
	Name string `json:"name"`
}

EventAttributeDefinition - A human-readable definition of an NRDB Event Type Attribute

type EventDefinition

type EventDefinition struct {
	/* Attributes - A list of attribute definitions for this event type */
	Attributes []EventAttributeDefinition `json:"attributes"`
	/* Definition - A short description of this event */
	Definition string `json:"definition"`
	/* Label - The human-friendly formatted name of the event */
	Label string `json:"label"`
	/* Name - The name of the event */
	Name string `json:"name"`
}

EventDefinition - A human-readable definition of an NRDB Event Type

type Nrdb

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

Nrdb is used to communicate with the New Relic's Datastore, NRDB.

func New

func New(config config.Config) Nrdb

New returns a new GraphQL client for interacting with New Relic's Datastore

func (*Nrdb) Query

func (n *Nrdb) Query(accountID int, query Nrql) (*NrdbResultContainer, error)

Query facilitates making a NRQL query.

func (*Nrdb) QueryHistory added in v0.30.0

func (n *Nrdb) QueryHistory() (*[]NrqlHistoricalQuery, error)

type NrdbMetadata

type NrdbMetadata struct {
	/* EventTypes - A list of the event types that were queried. */
	EventTypes []string `json:"eventTypes"`
	/* Facets - A list of facets that were queried. */
	Facets []string `json:"facets"`
	/* Messages - Messages from NRDB included with the result. */
	Messages []string `json:"messages"`
	/* TimeWindow - Details about the query time window. */
	TimeWindow NrdbMetadataTimeWindow `json:"timeWindow"`
}

NrdbMetadata - An object containing metadata about the query and result.

type NrdbMetadataTimeWindow

type NrdbMetadataTimeWindow struct {
	/* Begin - Timestamp marking the query begin time. */
	Begin EpochMilliseconds `json:"begin"`
	/* CompareWith - A clause representing the comparison time window. */
	CompareWith string `json:"compareWith"`
	/* End - Timestamp marking the query end time. */
	End EpochMilliseconds `json:"end"`
	/* Since - SINCE clause resulting from the query */
	Since string `json:"since"`
	/* Until - UNTIL clause resulting from the query */
	Until string `json:"until"`
}

NrdbMetadataTimeWindow - An object representing details about a query's time window.

type NrdbResult

type NrdbResult map[string]interface{}
NrdbResult - This scalar represents a NRDB Result. It is a `Map` of `String` keys to values.

The shape of these objects reflect the query used to generate them, the contents of the objects is not part of the GraphQL schema.

type NrdbResultContainer

type NrdbResultContainer struct {
	/* CurrentResults - In a `COMPARE WITH` query, the `currentResults` contain the results for the current comparison time window. */
	CurrentResults []NrdbResult `json:"currentResults"`
	/* EmbeddedChartUrl - Generate a publicly sharable Embedded Chart URL for the NRQL query.

	For more details, see [our docs](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/query-nrql-through-new-relic-graphql-api#embeddable-charts). */
	EmbeddedChartUrl string `json:"embeddedChartUrl"`
	/* EventDefinitions - Retrieve a list of event type definitions, providing descriptions
	of the event types returned by this query, as well as details
	of their attributes. */
	EventDefinitions []EventDefinition `json:"eventDefinitions"`
	/* Metadata - Metadata about the query and result. */
	Metadata NrdbMetadata `json:"metadata"`
	/* Nrql - The [NRQL](https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-resources/nrql-syntax-components-functions) query that was executed to yield these results. */
	Nrql Nrql `json:"nrql"`
	/* OtherResult - In a `FACET` query, the `otherResult` contains the aggregates representing the events _not_
	contained in an individual `results` facet */
	OtherResult NrdbResult `json:"otherResult"`
	/* PreviousResults - In a `COMPARE WITH` query, the `previousResults` contain the results for the previous comparison time window. */
	PreviousResults []NrdbResult `json:"previousResults"`
	/* Results - The query results. This is a flat list of objects who's structure matches the query submitted. */
	Results []NrdbResult `json:"results"`
	/* StaticChartUrl - Generate a publicly sharable static chart URL for the NRQL query. */
	StaticChartUrl string `json:"staticChartUrl"`
	/* SuggestedFacets - Retrieve a list of suggested NRQL facets for this NRDB query, to be used with
	the `FACET` keyword in NRQL.

	Results are based on historical query behaviors.

	If the query already has a `FACET` clause, it will be ignored for the purposes
	of suggesting facets.

	For more details, see [our docs](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/nerdgraph-graphiql-nrql-tutorial#suggest-facets). */
	SuggestedFacets []NrqlFacetSuggestion `json:"suggestedFacets"`
	/* SuggestedQueries - Suggested queries that could help explain an anomaly in your timeseries based on either statistical differences in the data or historical usage.

	If no `anomalyTimeWindow` is supplied, we will attempt to detect a spike in the NRQL results. If no spike is found, the suggested query results will be empty.

	Input NRQL must be a TIMESERIES query and must have exactly one result. */
	SuggestedQueries SuggestedNrqlQueryResponse `json:"suggestedQueries"`
	/* TotalResult - In a `FACET` query, the `totalResult` contains the aggregates representing _all_ the events,
	whether or not they are contained in an individual `results` facet */
	TotalResult NrdbResult `json:"totalResult"`
}
NrdbResultContainer - A data structure that contains the results of the NRDB query along

with other capabilities that enhance those results.

Direct query results are available through `results`, `totalResult` and `otherResult`. The query you made is accessible through `nrql`, along with `metadata` about the query itself. Enhanced capabilities include `eventDefinitions`, `suggestedFacets` and more.

type Nrql

type Nrql string
Nrql - This scalar represents a NRQL query string.

See the [NRQL Docs](https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-resources/nrql-syntax-components-functions) for more information about NRQL syntax.

type NrqlFacetSuggestion

type NrqlFacetSuggestion struct {
	/* Attributes - A list of attribute names comprising the suggested facet.

	Raw attribute names will be returned here. Attribute names may need to be
	backtick-quoted before inclusion in a NRQL query. */
	Attributes []string `json:"attributes"`
	/* Nrql - A modified version of the input NRQL, with a `FACET ...` clause appended.
	If the original NRQL had a `FACET` clause already, it will be replaced. */
	Nrql Nrql `json:"nrql"`
}
NrqlFacetSuggestion - A suggested NRQL facet. Facet suggestions may be either a single attribute, or

a list of attributes in the case of multi-attribute facet suggestions.

type NrqlHistoricalQuery added in v0.30.0

type NrqlHistoricalQuery struct {
	/* AccountID - The Account ID queried. */
	AccountID int `json:"accountId"`
	/* Nrql - The NRQL query executed. */
	Nrql Nrql `json:"nrql"`
	/* Timestamp - The time the query was executed. */
	Timestamp EpochSeconds `json:"timestamp"`
}

NrqlHistoricalQuery - An NRQL query executed in the past.

type SuggestedNrqlQuery

type SuggestedNrqlQuery interface{}

SuggestedNrqlQuery - Interface type representing a query suggestion.

type SuggestedNrqlQueryResponse

type SuggestedNrqlQueryResponse struct {
	/* Suggestions - List of suggested queries. */
	Suggestions []SuggestedNrqlQuery `json:"suggestions"`
}

SuggestedNrqlQueryResponse - result type encapsulating suggested queries

Jump to

Keyboard shortcuts

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