环境准备

安装Flink

参考:《Docker-Compose安装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目录下:

  1. sudo docker cp /share/flink/flink-metrics-influxdb-1.10.0.jar flink_jobmanager_1:/opt/flink/lib/
  2. sudo docker cp /share/flink/flink-metrics-influxdb-1.10.0.jar flink_taskmanager_1:/opt/flink/lib/

修改Flink配置

下载jobmanager/taskmanager容器的配置文件(相同,来自同一镜像),并更新相关配置。

  1. sudo docker cp flink_jobmanager_1:/opt/flink/conf/flink-conf.yaml /share/flink/flink-conf.yaml
  2. vi /share/flink/flink-conf.yaml

内容如下:

  1. # 配置influxdb
  2. metrics.reporter.influxdb.class: org.apache.flink.metrics.influxdb.InfluxdbReporter
  3. metrics.reporter.influxdb.host: 192.168.0.99
  4. metrics.reporter.influxdb.port: 8086
  5. # db,username,password需要跟配置influxdb一致
  6. metrics.reporter.influxdb.db: flink
  7. metrics.reporter.influxdb.username: flink
  8. metrics.reporter.influxdb.password: flink

上传配置到容器:

  1. sudo docker cp /share/flink/flink-conf.yaml flink_jobmanager_1:/opt/flink/conf/flink-conf.yaml
  2. sudo docker cp /share/flink/flink-conf.yaml flink_taskmanager_1:/opt/flink/conf/flink-conf.yaml

重启容器:

  1. cd /share/flink
  2. sudo docker-compose -f docker-compose.yml restart

验证

  1. 登录Grafana;(http://192.168.0.99:3000
  2. 添加Influxdb数据源;(http://192.168.0.99:8086,flink/flink/flink)
  3. 展示Flink Metric;(https://grafana.com/grafana/dashboards,搜索flink metrics模板并下载)