Windows_安装整合Prometheus + Grafana监控主机和Flink作业
创始人
2025-05-29 06:55:51
0

安装包下载

prometheus

windows_exporter

pushgateway

grafana

除了prometheus和flink的main函数代码需要修改外,其余直接bin/对应启动exe运行即可,注意默认端口即可(下文有)。

在这里插入图片描述

需要修改的配置

只需要修改:prometheus.yml(增加两个静态地址):

scrape_configs:# The job name is added as a label `job=` to any timeseries scraped from this config.- job_name: "prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ["localhost:9090"]#win- job_name: "node_exporter"scrape_interval: 5smetrics_path: "/metrics"  static_configs:- targets: ["localhost:9182"]# 添加 PushGateway 监控配置- job_name: 'pushgateway'honor_labels: truestatic_configs:- targets: ['localhost:9091']labels:instance: 'pushgateway'

作业代码

本地启动作业:

引入对应的pom依赖,如果在linux下通过Flink客户端编译,则将其放入对应的lib下:

Maven地址:Flink的prometheus整合依赖

完整依赖参考:分区文章:略。 本地IDEA开发,修改代码核心注意几个对应Flink客户端flink-conf.yaml的参数:

public class JobMonitorDemo {public static void main(String[] args) throws Exception {/** 创建flink流处理环境 */Configuration configuration = new Configuration();configuration.setString("rest.port","18081");//flink-prometheusconfiguration.setString("metrics.reporter.promgateway.class","org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter");configuration.setString("metrics.reporter.promgateway.host","localhost");configuration.setString("metrics.reporter.promgateway.port","9091");configuration.setString("metrics.reporter.promgateway.jobName","flink-metrics");configuration.setString("metrics.reporter.promgateway.randomJobNameSuffix","true");configuration.setString("metrics.reporter.promgateway.deleteOnShutdown","false");configuration.setString("metrics.reporter.promgateway.interval","30s");// 执行环境StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);sEnv.disableOperatorChaining();Properties propertiesC = new Properties();propertiesC.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");FlinkKafkaConsumer consumer = new FlinkKafkaConsumer("test" , new SimpleStringSchema(),propertiesC);//添加模拟数据源DataStreamSource outStream = sEnv.addSource(consumer);Properties properties = new Properties();properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");//properties.setProperty(ProducerConfig., "100000");properties.setProperty("akka.ask.timeout" , "120s");properties.setProperty("web.timeout" , "120000");outStream.print();FlinkKafkaProducer producer = new FlinkKafkaProducer("partitionTest", new SimpleStringSchema(),properties , Optional.of(new FlinkRoundRobinPartitioner<>()));//, new FlinkRoundRobinPartitioner<>(),  FlinkKafkaProducer.Semantic.AT_LEAST_ONCE, 5);/** 输出数据流绑定到生产者 */outStream.addSink(producer);outStream.print();sEnv.execute("partitionTest");}
}

实现样例

启动windows-Exporter(默认端口9182,http://localhost:9182/metrics,作用主要为监听到主机的CPU 使用率, 这里在对应上Grafana里面的metrics就是windows_xxx) ,

在这里插入图片描述

启动pushgateway(默认端口9091,http://localhost:9091/metrics,作用主要与flink内嵌的flink-metrics-prometheus呼应连接)

在这里插入图片描述

启动普罗米修斯(默认端口9090,http://localhost:9090/targets?search=),查看targets:

在这里插入图片描述

启动运行grafana,默认账户admin/admin ,先在setting里面关联上Prometheus作为数据源,再新增dashboard,在qurey里面的metrics中选择:

配置好普罗米修斯数据源:

http://localhost:9090/

在这里插入图片描述

在这里插入图片描述

如果只启动了windows_exploer则只有:

在这里插入图片描述

要想获得对应的flink监控图,idea运行本地flink作业,该作业以k2f为例,本地生产若干条数据对应指标变化:

在这里插入图片描述

对以上grafana中选择的指标是,对应Consumer算子【四个并行度(暴露cpu核数了)】:

在这里插入图片描述

使用进阶

手动一个个添加 Dashboard 比较繁琐,Grafana 社区鼓励用户分享 Dashboard,通过https://grafana.com/dashboards 网站,可以找到大量可直接使用的 Dashboard 模板。

在这里插入图片描述

导入(新建)dashboard:

在这里插入图片描述

引入Json模板的数据面板:

在这里插入图片描述

告警

Grafana告警这里有三个概念组成:

  • Alerting | Contact points
  • Alerting | Notification policies
  • Alerting | Alert rules

参考blog:Prometheus系列之Grafana 版本9.0.0 设置Email邮件报警实战

​ 彻底搞懂监控系统,使用Prometheus和Grafana 如何实现运维告警

首先配置开启smtp邮件服务,类似参考spring-admin,修改Grafana/conf/default.ini:

#################################### SMTP / Emailing #####################
[smtp]
enabled = true
host = smtp.qq.com:25		#邮件类型
user = yourEmail@qq.com	#邮件地址
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = xxx	#授权码
cert_file =
key_file =
skip_verify = true
from_address = yourEmail@qq.com
from_name = Grafana
ehlo_identity = dashboard.example.com
startTLS_policy =[emails]
welcome_email_on_sign_up = false
templates_pattern = emails/*.html, emails/*.txt
content_types = text/html

配置Contact points

新建一个new Contact points:

在这里插入图片描述

点击Test进行邮件测试:

在这里插入图片描述

邮箱中收到:

在这里插入图片描述

给对应的panel设置alert rule告警规则:

在这里插入图片描述

分为四步骤:一、针对query查询条件进行告警规则配置:

在这里插入图片描述

比如这里针对CPU本机测试告警实例的数据进行 一个固定值的阈值,当超过 IS ABOVE的时候进行告警:

在这里插入图片描述

二、配置扫描时间和存在告警策略: 如下,每30秒扫描一次,如果存在告警问题延迟1分钟进行告警;

三、告警信息内容;

在这里插入图片描述

收到的内容是:

在这里插入图片描述

四、Notifications 关联,即关联 alert rule和 之前配置的 contact points, 通过 notification policy来关联:

在这里插入图片描述

因为Alert Rule是通过label来匹配Contact point。所以需要定义一个Notification policy,给Contact point定义label

Grafana的所有Alert Rule报警都会发送给Root policy,但是Root policy的Contact point是无法接收邮件的。所以需要修改Root policy的Contact point

如果Specific routing和Root policy是同一个Contact point,则只会收到一封报警邮件,而不是两封

在这里插入图片描述

短信接口:可以选择contact point的类型为webhook:

在这里插入图片描述

指标的内容

在这里插入图片描述

Grafana的监控指标来源于Flink官方提供的指标:

https://nightlies.apache.org/flink/flink-docs-release-1.16/docs/ops/metrics/#system-metrics

Flink提供了四种类型的指标: Counter、Gauge、Histogram、Meter;

即:计数、Gauge瞬时值Meter 平均值Histogram 直方图

可参考blog:一口气搞懂Flink Metrics监控指标和性能优化,全靠这33张图和7千字

监控举例

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

自定义指标

Flink metrics的官网文档链接

外部关系存储

好像支持PostgreSql

使用

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

对应的:

在这里插入图片描述

flink_taskmanager_job_task_numRecordsIn
flink_taskmanager_job_task_records_consumed_total / rate

筛选条件:operator_name = Source:_Custom_Source 即可(下拉选项)

相关内容

热门资讯

电视安卓系统哪个品牌好,哪家品... 你有没有想过,家里的电视是不是该升级换代了呢?现在市面上电视品牌琳琅满目,各种操作系统也是让人眼花缭...
安卓会员管理系统怎么用,提升服... 你有没有想过,手机里那些你爱不释手的APP,背后其实有个强大的会员管理系统在默默支持呢?没错,就是那...
安卓系统软件使用技巧,解锁软件... 你有没有发现,用安卓手机的时候,总有一些小技巧能让你玩得更溜?别小看了这些小细节,它们可是能让你的手...
安卓系统提示音替换 你知道吗?手机里那个时不时响起的提示音,有时候真的能让人心情大好,有时候又让人抓狂不已。今天,就让我...
安卓开机不了系统更新 手机突然开不了机,系统更新还卡在那里,这可真是让人头疼的问题啊!你是不是也遇到了这种情况?别急,今天...
安卓系统中微信视频,安卓系统下... 你有没有发现,现在用手机聊天,视频通话简直成了标配!尤其是咱们安卓系统的小伙伴们,微信视频功能更是用...
安卓系统是服务器,服务器端的智... 你知道吗?在科技的世界里,安卓系统可是个超级明星呢!它不仅仅是个手机操作系统,竟然还能成为服务器的得...
pc电脑安卓系统下载软件,轻松... 你有没有想过,你的PC电脑上安装了安卓系统,是不是瞬间觉得世界都大不一样了呢?没错,就是那种“一机在...
电影院购票系统安卓,便捷观影新... 你有没有想过,在繁忙的生活中,一部好电影就像是一剂强心针,能瞬间让你放松心情?而我今天要和你分享的,...
安卓系统可以写程序? 你有没有想过,安卓系统竟然也能写程序呢?没错,你没听错!这个我们日常使用的智能手机操作系统,竟然有着...
安卓系统架构书籍推荐,权威书籍... 你有没有想过,想要深入了解安卓系统架构,却不知道从何下手?别急,今天我就要给你推荐几本超级实用的书籍...
安卓系统看到的炸弹,技术解析与... 安卓系统看到的炸弹——揭秘手机中的隐形威胁在数字化时代,智能手机已经成为我们生活中不可或缺的一部分。...
鸿蒙系统有安卓文件,畅享多平台... 你知道吗?最近在科技圈里,有个大新闻可是闹得沸沸扬扬的,那就是鸿蒙系统竟然有了安卓文件!是不是觉得有...
宝马安卓车机系统切换,驾驭未来... 你有没有发现,现在的汽车越来越智能了?尤其是那些豪华品牌,比如宝马,它们的内饰里那个大屏幕,简直就像...
p30退回安卓系统 你有没有听说最近P30的用户们都在忙活一件大事?没错,就是他们的手机要退回安卓系统啦!这可不是一个简...
oppoa57安卓原生系统,原... 你有没有发现,最近OPPO A57这款手机在安卓原生系统上的表现真是让人眼前一亮呢?今天,就让我带你...
安卓系统输入法联想,安卓系统输... 你有没有发现,手机上的输入法真的是个神奇的小助手呢?尤其是安卓系统的输入法,简直就是智能生活的点睛之...
怎么进入安卓刷机系统,安卓刷机... 亲爱的手机控们,你是否曾对安卓手机的刷机系统充满好奇?想要解锁手机潜能,体验全新的系统魅力?别急,今...
安卓系统程序有病毒 你知道吗?在这个数字化时代,手机已经成了我们生活中不可或缺的好伙伴。但是,你知道吗?即使是安卓系统,...
奥迪中控安卓系统下载,畅享智能... 你有没有发现,现在汽车的中控系统越来越智能了?尤其是奥迪这种豪华品牌,他们的中控系统简直就是科技与艺...