Grafana是开源的指标量监测和可视化工具,可用于展示时序数据和应用程序运行分析。Grafana支持Graphite,InfluxDB等国际主流时序时序数据库作为数据源。在IoTDB项目中,我们开发了Grafana展现IoTDB中时序数据的连接器IoTDB-Grafana-Connector,为您提供使用Grafana展示IoTDB数据库中的时序数据的可视化方法。
具体下载方法是:到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
建议使用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:
Shell > bin\grafana-server.exe
Shell > sudo service grafana-server start
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
参见https://github.com/apache/iotdb
git clone https://github.com/apache/iotdb.git
导入整个项目,maven依赖安装完后,直接运行iotdb/grafana/rc/main/java/org/apache/iotdb/web/grafana
目录下TsfileWebDemoApplication.java
,这个grafana连接器采用springboot开发
cd iotdb mvn clean package -pl grafana -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以网页的dashboard形式为您展示数据,在使用时请您打开浏览器,访问http://<ip>:<port>
注:IP为您的Grafana所在的服务器IP,Port为Grafana的运行端口(默认3000)。默认登录的用户名和密码都是“admin”。
点击左上角的“Grafana”图标,选择Data Source
选项,然后再点击Add data source
。
在编辑数据源的时候,Type
一栏选择Simplejson
,URL
一栏填写http://<ip>:<port>,IP为您的IoTDB-Grafana-Connector连接器所在的服务器IP,Port为运行端口(默认8888)。之后确保IoTDB已经启动,点击“Save & Test”,出现“Data Source is working”提示表示配置成功。
进入Grafana可视化页面后,可以选择添加时间序列,如图 6.9。您也可以按照Grafana官方文档进行相应的操作,详情可参看Grafana官方文档:http://docs.grafana.org/guides/getting_started/。
# 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 # 用于对数据进行降采样的聚合函数 # COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM function=avg
其中interval具体配置信息如下
<1h: no sampling
1h~1d : intervals = 1m
1d~30d:intervals = 1h
>30d:intervals = 1d
配置完后,请重新运行war包
java -jar iotdb-grafana-connector-{version}.war