Prometheus 监控flink

提要

本文主要介绍将flink任务运行的metric发送到Prometheus

监控的意义

flink流式任务在实时性稳定性方面都有一定的要求,通过Prometheus 采集flink集群的metric,指定一些指标就可以对其进行监控告警。从而能够让开发人员快速反应,及时处理线上问题。

1.Prometheus 简介

Prometheus是一个开源的监控和报警系统。https://prometheus.io/docs/introduction/overview/

2.1特性

  • 多维度的数据模型(通过指标名称和标签键值对标识)
  • 灵活的查询语言
  • 单机工作模式,不依赖于分布式存储
  • 通过pull模式(HTTP)收集监控数据
  • 通过使用中间件可以支持push监控数据到prometheus
  • 通过服务发现或者静态配置发现目标(监控数据源)
  • 支持多模式的画图和仪表盘

2.2组件

Prometheus生态系统包含很多组件(大多是都是可选择的)

  • Prometheus server(抓取、存储时间序列数据)
  • client libraries(帮助应用支持prometheus数据采集)
  • a push gateway(支持短生命周期的jobs,接收push的监控数据)(prometheus原生支持pull工作模式,为了兼容push工作模式)
  • exporters(用于支持开源服务的监控数据采集,比如:HAProxy、StatsD、Graphite等)(也就是agent)
  • alertmanager(处理警报)

2.3架构

下面这张图展示了prometheus的建构和prometheus系统可能需要到的组件:


6076209-f4a98b997204c9b1.png
image.png

3 flink集成prometheus

3.1 flink配置

详细配置参考
https://ci.apache.org/projects/flink/flink-docs-stable/monitoring/metrics.html#cpu
进入flink目录

6076209-c84c88efca0d4161.png
image.png

拷贝 opt目录下的flink-metrics-prometheus-1.7.2.jar 到lib目录。

编辑conf/flink-conf.yml

metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter
metrics.reporter.promgateway.host: test01.cdh6.local
metrics.reporter.promgateway.port: 9091
metrics.reporter.promgateway.jobName: myJob
metrics.reporter.promgateway.randomJobNameSuffix: true
metrics.reporter.promgateway.deleteOnShutdown: false

3.2 pushgateway安装

参考 https://github.com/prometheus/pushgateway
访问 http://test01.cdh6.local:9091/#

6076209-029b13d0826922e8.png
image.png

3.3 prometheus安装

参考 https://www.jianshu.com/p/3a9ede07d963
本例prometheus和pushgateway安装到同一机器上
编写 prometheus.yml

scrape_configs:
  - job_name: 'pushgateway'
    static_configs:
      - targets: ['localhost:9091']
        labels:
          instance: 'pushgateway'

启动
./prometheus --config.file=prometheus.ym l
这个9091端口就是flink-conf.yml 对应的metrics.reporter.promgateway.port: 9091
flink会把一些metric push到9091端口上,然后prometheus采集。

4效果

启动flink集群 .bin/start-cluster.sh
访问 http://test01.cdh6.local:9090

6076209-e14c443932ba5b26.png
image.png

总结

flink metric数据流转的流程是 flink metric -> pushgateway -> prometheus

todo 配置告警策略

转载于:https://www.jianshu.com/p/fc9af91e6b07

猜你喜欢

转载自blog.csdn.net/weixin_33834679/article/details/91165796