prometheus监控Flink(一)

目前Flink监控常用的手段有基于prometheus或者influxDB,还有就是基于rest api的。这里主要说的是基于prometheus的。附上官网的地址  https://ci.apache.org/projects/flink/flink-docs-release-1.9/monitoring/metrics.html#prometheuspushgateway-orgapacheflinkmetricsprometheusprometheuspushgatewayreporter

这种方式就是基于PushGateway + prometheus的方式。Flink任务先将数据推到pushgateway。然后pushgateway将值推送到prometheus,最后grafana展示prometheus中的值,就如同下图

1.pushgateway安装

pushgateway是prometheus的一个附属组件,所以下载地址都可以在prometheus官网中找到

https://prometheus.io/download/

可以去下载最新的这两个组件的版本

解压pushgateway

tar -zxvf  pushgateway-1.0.0.linux-amd64.tar.gz

然后可以直接启动  nohup ./pushgateway &

如果启动成功,可以访问该机器的9091端口进行验证,下面被我图掉的,是笔者的监控,初次安装的,应该是没有的。 

 2.prometheus安装

解压 tar -zxvf  prometheus-2.13.1.linux-amd64.tar.gz

然后 进入该目录,vim prometheus.yml   在scrape_configs中,修改成下面的样式

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

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

其中node1是安装了pushgateway的机器。注意:该配置文件是yml的格式,用过spring boot的同学应该不会陌生,所以格式一定要注意,前面要有空格。不然格式错误,会导致prometheus无法启动。

启动prometheus :nohup  ./prometheus --config.file=prometheus.yml &

验证:打开访问 该机器的 9090/targets   会得到以下界面,如果state不是up,则耐心等上几秒

3.grafana安装 

grafana安装可以有两种方式

第一种直接下载安装包:去官网 https://grafana.com/grafana/download

第二种:rpm安装 https://grafana.com/docs/installation/rpm/

本人使用的是第一种方式。

解压后  nohup ./bin/grafana-server web & 即可直接启动

启动成功后,访问本机的3000端口。会要求输入账号和密码,初始值为 admin/admin

如果端口被占用可以去conf目录,修改defaults.ini中的端口值即可。

4.flink任务

metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter
metrics.reporter.promgateway.host: node1
metrics.reporter.promgateway.port: 9091
metrics.reporter.promgateway.jobName: myjob
metrics.reporter.promgateway.randomJobNameSuffix: false
metrics.reporter.promgateway.deleteOnShutdown: true

  在flink-conf.yaml中添加上面的内容,然后再启动flinkjob即可。

 

5.grafana展示

在grafana web进去的初始页面里,有以下页面,可以点击Create your first data source,来添加prometheus的监控,由于笔者已经添加过了,所以这里有个划线,将这个名字划去了。

这里只有写上Name 和URL 即可 

然后再创建dashborad,并且添加panel

 

然后选择刚刚添加的prometheus实例,Metrics中的flink,就是传过来的监控数据

 

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值