使用influxQL 查询influxDB 2.0以上版本

 使用grafana 9.0 连接influxdb 2.0 时候,只能用FLux语言连接,就没有SQL编辑面板,通过研究搞定了,先看效果。

influxQL 格式连接 influxdb2.0   无法连接,总数报错 bad  request.

那就用FLux格式连接,连接成功后,查询的地方没有可视化面板,只有编写脚本的地方,很不方便:

对mysql,就用支持,可以选择。

 经过查询,是因为2.0以上的influxdb,默认不支持influxQL,所以连接不上,但是官网说了,可以通过设置使其支持:

Manage database and retention policy mappings | InfluxDB OSS 2.7 DocumentationCreate and manage database and retention policy (DBRP) mappings to use InfluxQL to query InfluxDB buckets.icon-default.png?t=N7T8https://docs.influxdata.com/influxdb/v2.7/query-data/influxql/dbrp/#a-dbrp-combination-can-only-be-mapped-to-a-single-bucket

Use the influx v1 dbrp create command to map an unmapped bucket to a database and retention policy. Include the following:

* Required

  • org and token to authenticate. We recommend setting your organization and token to your active InfluxDB connection configuration in the influx CLI, so you don’t have to add these parameters to each command. To set up your active InfluxDB configuration, see influx config set.
  • database name to map
  • retention policy name to map
  • Bucket ID to map to
  • Default flag to set the provided retention policy as the default retention policy for the database
influx v1 dbrp create \
  --db example-db \
  --rp example-rp \
  --bucket-id 00oxo0oXx000x0Xo \
  --default

参考视频:

https://www.youtube.com/watch?v=gEIgg5zHuIU&ab_channel=CsongorVarga

Grafana and InfluxDB - How to configure a Query without Flux - #3 by zkor - openHAB Community

说明文档:InfluxDB and Grafana · nygma2004/km Wiki · GitHub

需要通过命令进行设置,官方给了2中方法,

一种通过CLI运行,需要先安装工具:https://docs.influxdata.com/influxdb/v2.7/tools/influx-cli/?t=Windows

一种是curl执行,我用curl,

说明:要在win cmd上执行,需要修改命令的结尾换行符 \  改成 ^

并注意JSON中的 ” 的转义。

获取 orgID:

执行查询:

在CMD运行,先查看有没有已经映射的:官方以 \ 结尾,但是在 win 上要用 ^ 结尾,cmd才识别。

curl --request GET ^
http://localhost:8086/api/v2/dbrps?orgID=f498c13c545d2da9 ^
--header "Authorization: Token 5a1z9bDA5V_AXRONyaTSA1DX5vLibucwxa2DFH5mlMaBgV39-fkn_q8SlWOb6yiaKK0_lkGfKFtAO6ikCNz3uw=="

注意里面的空格,不然报错。最后一次才成功:

进行映射:下面是官方的语句,把里面的内容修改成自己的

curl --request POST http://localhost:8086/api/v2/dbrps \
  --header "Authorization: Token YourAuthToken" \
  --header 'Content-type: application/json' \
  --data '{
        "bucketID": "00oxo0oXx000x0Xo",
        "database": "example-db",
        "default": true,
        "orgID": "00oxo0oXx000x0Xo",
        "retention_policy": "example-rp"
      }'

 活动 org id :

 修改后的:database 给映射后的新的数据库名字。 orgid  bucketid 都是原来库里的id。

curl --request POST http://localhost:8086/api/v2/dbrps ^
--header "Authorization: Token 5a1z9bDA5V_AXRONyaTSA1DX5vLibucwxa2DFH5mlMaBgV39-fkn_q8SlWOb6yiaKK0_lkGfKFtAO6ikCNz3uw==" ^
--header "Content-type: application/json" ^
--data "{ \"bucketID\": \"f498c13c545d2da9\", \"database\": \"level2\", \"retention_policy\": \"autogen\", \"default\": true, \"orgID\": \"58e8e7ffc8beeb55\" }"

运行效果:

查看某个org下所有的库:

curl --request GET ^
  http://localhost:8086/api/v2/dbrps?orgID=58e8e7ffc8beeb55 ^
  --header "Authorization: Token 5a1z9bDA5V_AXRONyaTSA1DX5vLibucwxa2DFH5mlMaBgV39-fkn_q8SlWOb6yiaKK0_lkGfKFtAO6ikCNz3uw=="

在grafana中开始连接:

必须开启 basic auth  ,设置token  , Token 5a1z9bDA5V_AXRONyaTSA1DX5vLibucwxa2DFH5mlMaBgV39-fkn_q8SlWOb6yiaKK0_lkGfKFtAO6ikCNz3uw==

继续配置,写账号密码,database,我没弄明白,感觉写映射前后的库名都可以。

 

  

搞定了,有面板了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
InfluxDB 2.0是一个由Go语言开发的数据库系统,它有两个版本InfluxDB 1.x系列和InfluxDB 2.0系列。InfluxDB 2.0引入了全新的查询语言Flux,并支持TICK架构。它提供了一种类似SQL查询语言InfluxQL,用于数据交互。InfluxDB 2.0还分为InfluxDB Cloud和InfluxDB OSS两个系列。如果你想安装InfluxDB 2.0,你可以通过以下步骤进行操作: 1. 下载InfluxDB 2.0的安装包: ``` wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.7-amd64.deb ``` 2. 安装InfluxDB 2.0: ``` sudo dpkg -i influxdb2-2.0.7-amd64.deb ``` 如果你想在Java项目中使用InfluxDB 2.0,你需要在项目的pom.xml文件中添加以下Maven依赖包: ```xml <dependency> <groupId>com.influxdb</groupId> <artifactId>influxdb-client-java</artifactId> <version>2.0.0</version> </dependency> ``` 这样你就可以在Java项目中使用InfluxDB 2.0了。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [InfluxDB 2.0 原理与应用实践](https://blog.csdn.net/hogwarts_ziqi/article/details/126000472)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [InfluxDb2.0使用与集成](https://blog.csdn.net/Calm_D/article/details/120646931)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值