【问题标题】:Query InfluxDB 2.0 from R从 R 查询 InfluxDB 2.0
【发布时间】:2021-01-08 21:14:17
【问题描述】:

我可以使用 Node-RED 使用此查询检索数据,但需要使用 R 检索它。

这是我所知道的。

post.1 <- httr::POST(url=paste0("http://", influx.ip, ":8086/api/v2/signin"),
                     authenticate(influx.user, influx.passwd))
# Authentication seems to work.

influx.query <- 'from(bucket: "nr_meas")
|> range(start: -12h)'

post.2 <- httr::POST(url=paste0("http://", influx.ip, ":8086/api/v2/query"),
                   query=list(org=influx.org),
                   add_headers("Content-Type: application/json",
                               'Accept: application/csv'),
                   body=list(q=influx.query)
                   )
content(post.2)
# $code
# [1] "invalid"
#
# $message
# [1] "failed to decode request body: invalid character '-' in numeric literal"

不能从 Node-RED 中保存(在不同的计算机上)。

从 InfluxDB 获取数据到 R 的正确方法是什么?

【问题讨论】:

  • 我不是 influx 用户,但我希望在第二个查询中需要使用在 post.1 中完成的相同身份验证。对POST 的两次调用之间没有共享“会话”。尝试将您的 authenticate(..) 添加到您的第二次通话中,或查看 docs.influxdata.com/influxdb/v2.0/reference/api 以了解身份验证令牌的使用情况。
  • 感谢您的提示。我刚刚尝试过,还有 add_headers(paste0("Authorization: Token", influx.token)),但产生了同样的错误。

标签: r influxdb httr


【解决方案1】:

你可以试试 InfluxDB 2.0 R client:

library(influxdbclient)

client <- InfluxDBClient$new(
    url = paste0("http://", influx.ip, ":8086"),
    token = "my-token",
    org = influx.org)
                        
data <- client$query('from(bucket: "nr_meas") |> range(start: -12h) |> drop(columns: ["_start", "_stop"])')

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2021-08-15
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    相关资源
    最近更新 更多