环境准备
安装Flink
安装Prometheus
参考:《Docker-Standalone安装Prometheus》
安装Grafana
参考:《Docker-Standalone安装Grafana》
Flink集成Prometheus
添加依赖jar包
依赖包 | 下载站点 |
---|---|
flink-metrics-prometheus-1.10.0.jar | Flink安装包/opt目录下 |
依赖jar包准备,将jar包直接复制到$FLINK_HOME/lib目录下:
sudo docker cp /share/flink/flink-metrics-prometheus-1.10.0.jar flink_jobmanager_1:/opt/flink/lib/
sudo docker cp /share/flink/flink-metrics-prometheus-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
内容如下:
# 配置prometheus
metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter
metrics.reporter.promgateway.host: 192.168.0.99
metrics.reporter.promgateway.port: 9091
# jobName直接指定,不需要事先在prometheus中配置
metrics.reporter.promgateway.jobName: flink_prom
metrics.reporter.promgateway.randomJobNameSuffix: true
metrics.reporter.promgateway.deleteOnShutdown: false
上传配置到容器:
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)
- 添加Prometheus数据源;(http://192.168.0.99:9090)
- 展示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