Created
May 27, 2016 14:47
-
-
Save chriswessells/a502166cde6533d7f976df977b92b43b to your computer and use it in GitHub Desktop.
Querying NewRelic Insights with R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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