环境准备
安装Flink
安装InfluxDB
参考:《Docker-Standalone安装InfluxDB》
安装Grafana
参考:《Docker-Standalone安装Grafana》
Flink集成InfluxDB
添加依赖jar包
依赖包 | 下载站点 |
---|---|
flink-metrics-influxdb-1.10.0.jar | Flink安装包/opt目录下 |
依赖jar包准备,将jar包直接复制到$FLINK_HOME/lib目录下:
sudo docker cp /share/flink/flink-metrics-influxdb-1.10.0.jar flink_jobmanager_1:/opt/flink/lib/
sudo docker cp /share/flink/flink-metrics-influxdb-1.10.0.jar flink_taskmanager_1:/opt/flink/lib/
修改Flink配置
下载jobmanager/taskmanager容器的配置文件(相同,来自同一镜像),并更新相关配置。
sudo docker cp flink_jobmanager_1:/opt/flink/conf/flink-conf.yaml /share/flink/flink-conf.yaml
vi /share/flink/flink-conf.yaml
内容如下:
# 配置influxdb
metrics.reporter.influxdb.class: org.apache.flink.metrics.influxdb.InfluxdbReporter
metrics.reporter.influxdb.host: 192.168.0.99
metrics.reporter.influxdb.port: 8086
# db,username,password需要跟配置influxdb一致
metrics.reporter.influxdb.db: flink
metrics.reporter.influxdb.username: flink
metrics.reporter.influxdb.password: flink
上传配置到容器:
sudo docker cp /share/flink/flink-conf.yaml flink_jobmanager_1:/opt/flink/conf/flink-conf.yaml
sudo docker cp /share/flink/flink-conf.yaml flink_taskmanager_1:/opt/flink/conf/flink-conf.yaml
重启容器:
cd /share/flink
sudo docker-compose -f docker-compose.yml restart
验证
- 登录Grafana;(http://192.168.0.99:3000)
- 添加Influxdb数据源;(http://192.168.0.99:8086,flink/flink/flink)
- 展示Flink Metric;(https://grafana.com/grafana/dashboards,搜索flink metrics模板并下载)