Skip to content

Instantly share code, notes, and snippets.

@chriswessells
Created May 27, 2016 14:47
Show Gist options
  • Save chriswessells/a502166cde6533d7f976df977b92b43b to your computer and use it in GitHub Desktop.
Save chriswessells/a502166cde6533d7f976df977b92b43b to your computer and use it in GitHub Desktop.
Querying NewRelic Insights with R
#
# Load the library to access the data
#
library(jsonlite)
library(httr)
# Header values required for accessing NewRelic
# ['X-Query-Key'] = 'NewRelicApi key'
#
# Sample URL
# The example works to collect data from NewRelic Insights
#
# The NewRelic Insights query needs to be sanitized before it is added to the URL
# This is a builtin R library to perform the sanitizing
#
# testUrl <- URLencode("test of the url encoding")
# testUrl
# The URL for querying insights. Replace <Insights Query in> with the sanatized query
#
uri<-as.character("https://insights-api.newrelic.com/v1/accounts/328110/query?nrql=<Insights Query in >")
# Make the http request
#
req <- httr::GET(uri, httr::add_headers("X-Query-Key" = "<NewRelic API Key>"))
# extract the json object from the request
#
json <- httr::content(req, as = "text")
#
# format the json in a more user friendly format
insightsData <- fromJSON(json)
# copy the data to the clipboard
#
writeClipboard(json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment