nrdb

package
v0.63.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 7 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

Code generated by tutone: DO NOT EDIT

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

View Source
var ChartFormatTypeTypes = struct {
	PDF ChartFormatType
	PNG ChartFormatType
}{
	PDF: "PDF",
	PNG: "PNG",
}
View Source
var ChartImageTypeTypes = struct {
	APDEX                  ChartImageType
	AREA                   ChartImageType
	BAR                    ChartImageType
	BASELINE               ChartImageType
	BILLBOARD              ChartImageType
	BULLET                 ChartImageType
	EVENT_FEED             ChartImageType
	FUNNEL                 ChartImageType
	HEATMAP                ChartImageType
	HISTOGRAM              ChartImageType
	LINE                   ChartImageType
	PIE                    ChartImageType
	SCATTER                ChartImageType
	STACKED_HORIZONTAL_BAR ChartImageType
	TABLE                  ChartImageType
	VERTICAL_BAR           ChartImageType
}{
	APDEX:                  "APDEX",
	AREA:                   "AREA",
	BAR:                    "BAR",
	BASELINE:               "BASELINE",
	BILLBOARD:              "BILLBOARD",
	BULLET:                 "BULLET",
	EVENT_FEED:             "EVENT_FEED",
	FUNNEL:                 "FUNNEL",
	HEATMAP:                "HEATMAP",
	HISTOGRAM:              "HISTOGRAM",
	LINE:                   "LINE",
	PIE:                    "PIE",
	SCATTER:                "SCATTER",
	STACKED_HORIZONTAL_BAR: "STACKED_HORIZONTAL_BAR",
	TABLE:                  "TABLE",
	VERTICAL_BAR:           "VERTICAL_BAR",
}
View Source
var EmbeddedChartTypeTypes = struct {
	APDEX                  EmbeddedChartType
	AREA                   EmbeddedChartType
	BAR                    EmbeddedChartType
	BASELINE               EmbeddedChartType
	BILLBOARD              EmbeddedChartType
	BULLET                 EmbeddedChartType
	EMPTY                  EmbeddedChartType
	EVENT_FEED             EmbeddedChartType
	FUNNEL                 EmbeddedChartType
	HEATMAP                EmbeddedChartType
	HISTOGRAM              EmbeddedChartType
	JSON                   EmbeddedChartType
	LINE                   EmbeddedChartType
	MARKDOWN               EmbeddedChartType
	PIE                    EmbeddedChartType
	SCATTER                EmbeddedChartType
	STACKED_HORIZONTAL_BAR EmbeddedChartType
	TABLE                  EmbeddedChartType
	TRAFFIC_LIGHT          EmbeddedChartType
	VERTICAL_BAR           EmbeddedChartType
}{
	APDEX:                  "APDEX",
	AREA:                   "AREA",
	BAR:                    "BAR",
	BASELINE:               "BASELINE",
	BILLBOARD:              "BILLBOARD",
	BULLET:                 "BULLET",
	EMPTY:                  "EMPTY",
	EVENT_FEED:             "EVENT_FEED",
	FUNNEL:                 "FUNNEL",
	HEATMAP:                "HEATMAP",
	HISTOGRAM:              "HISTOGRAM",
	JSON:                   "JSON",
	LINE:                   "LINE",
	MARKDOWN:               "MARKDOWN",
	PIE:                    "PIE",
	SCATTER:                "SCATTER",
	STACKED_HORIZONTAL_BAR: "STACKED_HORIZONTAL_BAR",
	TABLE:                  "TABLE",
	TRAFFIC_LIGHT:          "TRAFFIC_LIGHT",
	VERTICAL_BAR:           "VERTICAL_BAR",
}

Functions

This section is empty.

Types

type ChartFormatType added in v0.52.0

type ChartFormatType string

ChartFormatType - Represents all the format types available for static charts.

type ChartImageType added in v0.52.0

type ChartImageType string

ChartImageType - Represents all the visualization types available for static charts.

type EmbeddedChartType added in v0.52.0

type EmbeddedChartType string

EmbeddedChartType - Represents all the visualization types available for embedded charts.

type EventAttributeDefinition

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

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

type EventDefinition

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

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

type NRDBMetadata added in v0.52.0

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

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

type NRDBMetadataTimeWindow added in v0.52.0

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

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

type NRDBResult added in v0.52.0

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 added in v0.52.0

type NRDBResultContainer struct {
	// In a `COMPARE WITH` query, the `currentResults` contain the results for the current comparison time window.
	CurrentResults []NRDBResult `json:"currentResults,omitempty"`
	// 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,omitempty"`
	// 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,omitempty"`
	// Metadata about the query and result.
	Metadata NRDBMetadata `json:"metadata,omitempty"`
	// 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,omitempty"`
	// In a `FACET` query, the `otherResult` contains the aggregates representing the events _not_
	// contained in an individual `results` facet
	OtherResult NRDBResult `json:"otherResult,omitempty"`
	// In a `COMPARE WITH` query, the `previousResults` contain the results for the previous comparison time window.
	PreviousResults []NRDBResult `json:"previousResults,omitempty"`
	// The query results. This is a flat list of objects who's structure matches the query submitted.
	Results []NRDBResult `json:"results,omitempty"`
	// Generate a publicly sharable static chart URL for the NRQL query.
	StaticChartURL string `json:"staticChartUrl,omitempty"`
	// 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,omitempty"`
	// 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,omitempty"`
	// 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,omitempty"`
}

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 added in v0.52.0

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 added in v0.52.0

type NRQLFacetSuggestion struct {
	// 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,omitempty"`
	// 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,omitempty"`
}

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.52.0

type NRQLHistoricalQuery struct {
	// The Account ID queried.
	AccountID int `json:"accountId,omitempty"`
	// The NRQL query executed.
	NRQL NRQL `json:"nrql,omitempty"`
	// The time the query was executed.
	Timestamp nrtime.EpochSeconds `json:"timestamp,omitempty"`
}

NRQLHistoricalQuery - An NRQL query executed in the past.

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)

func (*Nrdb) QueryHistory added in v0.30.0

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

func (*Nrdb) QueryHistoryWithContext added in v0.51.0

func (n *Nrdb) QueryHistoryWithContext(ctx context.Context) (*[]NRQLHistoricalQuery, error)

func (*Nrdb) QueryWithContext added in v0.51.0

func (n *Nrdb) QueryWithContext(ctx context.Context, accountID int, query NRQL) (*NRDBResultContainer, error)

QueryWithContext facilitates making a NRQL query.

type SuggestedAnomalyBasedNRQLQuery added in v0.52.0

type SuggestedAnomalyBasedNRQLQuery struct {
	// Information about the anomaly upon which this suggestion is based
	Anomaly SuggestedNRQLQueryAnomaly `json:"anomaly"`
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedAnomalyBasedNRQLQuery - A query suggestion based on analysis of events within a specific anomalous time range vs. nearby events outside of that time range.

func (*SuggestedAnomalyBasedNRQLQuery) ImplementsSuggestedNRQLQuery added in v0.52.0

func (x *SuggestedAnomalyBasedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedHistoryBasedNRQLQuery added in v0.52.0

type SuggestedHistoryBasedNRQLQuery struct {
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedHistoryBasedNRQLQuery - A query suggestion based on historical query patterns.

func (*SuggestedHistoryBasedNRQLQuery) ImplementsSuggestedNRQLQuery added in v0.52.0

func (x *SuggestedHistoryBasedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedNRQLQuery added in v0.52.0

type SuggestedNRQLQuery struct {
	// The NRQL string to run for the suggested query
	NRQL string `json:"nrql"`
	// A human-readable title describing what the query shows
	Title string `json:"title"`
}

SuggestedNRQLQuery - Interface type representing a query suggestion.

func (*SuggestedNRQLQuery) ImplementsSuggestedNRQLQuery added in v0.52.0

func (x *SuggestedNRQLQuery) ImplementsSuggestedNRQLQuery()

type SuggestedNRQLQueryAnomaly added in v0.52.0

type SuggestedNRQLQueryAnomaly struct {
	// The approximate time window of the anomalous region
	TimeWindow TimeWindow `json:"timeWindow"`
}

SuggestedNRQLQueryAnomaly - Information about the anomaly upon which this analysis was based.

type SuggestedNRQLQueryInterface added in v0.52.0

type SuggestedNRQLQueryInterface interface {
	ImplementsSuggestedNRQLQuery()
}

SuggestedNRQLQuery - Interface type representing a query suggestion.

func UnmarshalSuggestedNRQLQueryInterface added in v0.52.0

func UnmarshalSuggestedNRQLQueryInterface(b []byte) (*SuggestedNRQLQueryInterface, error)

UnmarshalSuggestedNRQLQueryInterface unmarshals the interface into the correct type based on __typename provided by GraphQL

type SuggestedNRQLQueryResponse added in v0.52.0

type SuggestedNRQLQueryResponse struct {
	// List of suggested queries.
	Suggestions []SuggestedNRQLQueryInterface `json:"suggestions"`
}

SuggestedNRQLQueryResponse - A result type encapsulating suggested queries

func (*SuggestedNRQLQueryResponse) UnmarshalJSON added in v0.52.0

func (x *SuggestedNRQLQueryResponse) UnmarshalJSON(b []byte) error

special

type TimeWindow added in v0.52.0

type TimeWindow struct {
	// The end time of the time window the number of milliseconds since the Unix epoch.
	EndTime nrtime.EpochMilliseconds `json:"endTime,omitempty"`
	// The start time of the time window the number of milliseconds since the Unix epoch.
	StartTime nrtime.EpochMilliseconds `json:"startTime,omitempty"`
}

TimeWindow - Represents a time window.

Jump to

Keyboard shortcuts

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