Documentation ¶
Overview ¶
Package nerdgraph provides a programmatic API for interacting with the New Relic NerdGraph GraphQL API. It can be used to run freeform queries and mutations. The GraphiQL API explorer is a useful resource for learning about what is available via the NerdGraph API:
https://api.newrelic.com/graphiql?#
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 nerdgraph provides a programmatic API for interacting with NerdGraph, New Relic One's GraphQL API.
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") // Initialize the client. client := New(cfg) // Execute a NRQL query to retrieve the average duration of transactions for // the "Example application" app. query := ` query($accountId: Int!, $nrqlQuery: Nrql!) { actor { account(id: $accountId) { nrql(query: $nrqlQuery, timeout: 5) { results } } } }` variables := map[string]interface{}{ "accountId": 12345678, "nrqlQuery": "SELECT average(duration) FROM Transaction TIMESERIES WHERE appName = 'Example application'", } resp, err := client.Query(query, variables) if err != nil { log.Fatal("error running NerdGraph query: ", err) } queryResp := resp.(QueryResponse) actor := queryResp.Actor.(map[string]interface{}) account := actor["account"].(map[string]interface{}) nrql := account["nrql"].(map[string]interface{}) results := nrql["results"].([]interface{}) var durations []float64 for _, r := range results { data := r.(map[string]interface{}) durations = append(durations, data["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 AccountReference ¶ added in v0.17.0
type AccountReference struct { ID int `json:"id,omitempty" yaml:"id,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` }
AccountReference represents the NerdGraph schema for a New Relic account.
type NerdGraph ¶
type NerdGraph struct {
// contains filtered or unexported fields
}
NerdGraph is used to communicate with the New Relic's GraphQL API, NerdGraph.
func New ¶
New returns a new GraphQL client for interacting with New Relic's GraphQL API, NerdGraph.
type QueryResponse ¶ added in v0.13.0
type QueryResponse struct { Actor interface{} `json:"actor,omitempty" yaml:"actor,omitempty"` Docs interface{} `json:"docs,omitempty" yaml:"docs,omitempty"` RequestContext interface{} `json:"requestContext,omitempty" yaml:"requestContext,omitempty"` }
QueryResponse represents the top-level GraphQL response object returned from a NerdGraph query request.