Last active
August 29, 2015 14:25
-
-
Save arthur-flam/863af728f67206e7c558 to your computer and use it in GitHub Desktop.
Get data from influxdb 0.9+ into R. Might be turned into a package since influxdb-R is obselete.
This file contains hidden or 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
# MIT licence - https://tldrlegal.com/license/mit-license | |
# Arthur Flam - Lookies - 2015 | |
library(httr) | |
library(rjson) | |
HOST = "ip.ip.ip.ip" | |
PORT = "8086" | |
PROTOCOL = "http" | |
DATABASE = "test_db" | |
PASSWORD = "password" | |
USER = "user" | |
query = "SELECT * FROM measurement WHERE time > now() - 12h GROUP BY tag ORDER BY asc" | |
query = URLencode(gsub(pattern=" ", replacement="+", x=query)) | |
url = paste0(PROTOCOL, "://",HOST,":",PORT,"/query?db=",DATABASE,"&p=",PASSWORD,"&q=",query,"&u=",USER,"&time_precision=s") | |
r = GET(url) | |
data <- fromJSON(rawToChar(r$content)) | |
series = response_data$results[[1]]$series | |
data = sapply(series, function(serie){ | |
name = serie$name # "measurement" | |
tags = serie$tags # "client", "country", ... | |
columns = serie$columns # "time", "ask", "bid", "etc" | |
values = serie$values[[1]] # time, values | |
out = c(tags$client, values) | |
names(out) = c("client", columns) | |
return(out) | |
}) | |
df = as.data.frame(t(data)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment