环境准备

安装Flink

参考:《Docker-Compose安装Flink

安装Prometheus

参考:《Docker-Standalone安装Prometheus

安装Grafana

参考:《Docker-Standalone安装Grafana

Flink集成Prometheus

image.png

添加依赖jar包

依赖包 下载站点
flink-metrics-prometheus-1.10.0.jar Flink安装包/opt目录下

依赖jar包准备,将jar包直接复制到$FLINK_HOME/lib目录下:

  1. sudo docker cp /share/flink/flink-metrics-prometheus-1.10.0.jar flink_jobmanager_1:/opt/flink/lib/
  2. sudo docker cp /share/flink/flink-metrics-prometheus-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. # 配置prometheus
  2. metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter
  3. metrics.reporter.promgateway.host: 192.168.0.99
  4. metrics.reporter.promgateway.port: 9091
  5. # jobName直接指定,不需要事先在prometheus中配置
  6. metrics.reporter.promgateway.jobName: flink_prom
  7. metrics.reporter.promgateway.randomJobNameSuffix: true
  8. metrics.reporter.promgateway.deleteOnShutdown: false

上传配置到容器:

  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. 添加Prometheus数据源;(http://192.168.0.99:9090
  3. 展示Flink Metric;(https://grafana.com/grafana/dashboards,搜索flink模板并下载,推荐:Docker主机监控模板:193;Linux主机监控模板:9276;Flink集群监控模板:11049、8966、10369)

    参考

    简书:使用Flink Metric Reporter对flink任务指标进行监控
    https://www.jianshu.com/p/d09bf7d540e9