跳至主要內容

...大约 4 分钟

Grafana 连接器

Grafana 是开源的指标量监测和可视化工具,可用于展示时序数据和应用程序运行分析。Grafana 支持 Graphite,InfluxDB 等国际主流时序数据库作为数据源。在 IoTDB 项目中,我们开发了 Grafana 展现 IoTDB 中时序数据的连接器 IoTDB-Grafana-Connector,为您提供使用 Grafana 展示 IoTDB 数据库中的时序数据的可视化方法。

Grafana 的安装与部署

安装

simple-json-datasource 数据源插件安装

windows系统

具体下载方法是:到Grafana的插件目录中:{Grafana文件目录}\data\plugins\(Windows系统,启动Grafana后会自动创建data\plugins目录)或/var/lib/grafana/plugins (Linux系统,plugins目录需要手动创建)或/usr/local/var/lib/grafana/plugins(MacOS系统,具体位置参看使用brew install安装Grafana后命令行给出的位置提示。

执行下面的命令:

Shell > git clone https://github.com/grafana/simple-json-datasource.git
linux系统

建议使用grafana-cli安装该插件,具体安装命令如下

sudo grafana-cli plugins install grafana-simple-json-datasource
sudo service grafana-server restart
后续操作

然后重启Grafana服务器,在浏览器中登录Grafana,在“Add data source”页面中“Type”选项出现“SimpleJson”即为安装成功。

如果出现如下报错

Unsigned plugins were found during plugin initialization. Grafana Labs cannot guarantee the integrity of these plugins. We recommend only using signed plugins.
The following plugins are disabled and not shown in the list below:

请找到相关的grafana的配置文件(例如windows下的customer.ini,linux下rpm安装后为/etc/grafana/grafana.ini),并进行如下的配置

allow_loading_unsigned_plugins = "grafana-simple-json-datasource"

启动 Grafana

进入 Grafana 的安装目录,使用以下命令启动 Grafana:

  • Windows 系统:
Shell > bin\grafana-server.exe
  • Linux 系统:
Shell > sudo service grafana-server start
  • MacOS 系统:
Shell > grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins

更多安装详情,请点 这里open in new window

IoTDB 安装

参见 https://github.com/apache/iotdbopen in new window

Grafana-IoTDB-Connector 连接器安装

git clone https://github.com/apache/iotdb.git

启动 Grafana-IoTDB-Connector

  • 方案一(适合开发者)

导入整个项目,maven 依赖安装完后,直接运行iotdb/grafana-connector/rc/main/java/org/apache/iotdb/web/grafana目录下TsfileWebDemoApplication.java,这个 grafana 连接器采用 springboot 开发

  • 方案二(适合使用者)
cd iotdb
mvn clean package -pl grafana-connector -am -Dmaven.test.skip=true
cd grafana/target
java -jar iotdb-grafana-connector-{version}.war
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.4.RELEASE)
...

如果您需要配置属性,将grafana/src/main/resources/application.properties移动到 war 包同级目录下(grafana/target

使用 Grafana

Grafana 以网页的 dashboard 形式为您展示数据,在使用时请您打开浏览器,访问 http://<ip>:<port>

默认地址为 http://localhost:3000/open in new window

注:IP 为您的 Grafana 所在的服务器 IP,Port 为 Grafana 的运行端口(默认 3000)。默认登录的用户名和密码都是“admin”。

添加 IoTDB 数据源

点击左上角的“Grafana”图标,选择Data Source选项,然后再点击Add data source

在编辑数据源的时候,Type一栏选择SimplejsonURL一栏填写 http://<ip>:<port>,IP 为您的 IoTDB-Grafana-Connector 连接器所在的服务器 IP,Port 为运行端口(默认 8888)。之后确保 IoTDB 已经启动,点击“Save & Test”,出现“Data Source is working”提示表示配置成功。

操作 Grafana

进入 Grafana 可视化页面后,可以选择添加时间序列,如下图。您也可以按照 Grafana 官方文档进行相应的操作,详情可参看 Grafana 官方文档:http://docs.grafana.org/guides/getting_started/。open in new window

配置 grafana

# IoTDB 的 IP 和端口
spring.datasource.url=jdbc:iotdb://127.0.0.1:6667/
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=org.apache.iotdb.jdbc.IoTDBDriver
server.port=8888
# Use this value to set timestamp precision as "ms", "us" or "ns", which must to be same with the timestamp
# precision of Apache IoTDB engine.
timestamp_precision=ms

# 是否开启降采样
isDownSampling=true
# 默认采样 interval
interval=1m
# 用于对连续数据 (int, long, float, double) 进行降采样的聚合函数
# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM
continuous_data_function=AVG
# 用于对离散数据 (boolean, string) 进行降采样的聚合函数
# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MIN_TIME, NOW
discrete_data_function=LAST_VALUE

其中 interval 具体配置信息如下

<1h: no sampling

1h~1d : intervals = 1m

1d~30d:intervals = 1h

>30d:intervals = 1d

配置完后,请重新运行 war 包

java -jar iotdb-grafana-connector-{version}.war

Copyright © 2024 The Apache Software Foundation.
Apache and the Apache feather logo are trademarks of The Apache Software Foundation

Have a question? Connect with us on QQ, WeChat, or Slack. Join the community now.