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 即可(下拉选项)

相关内容

热门资讯

mac 系统安装 安卓系统安装... 亲爱的电脑小白们,是不是最近对电脑系统安装跃跃欲试,但又觉得无从下手?别担心,今天我就要来给你详细讲...
提醒安卓系统升级,体验流畅新篇... 亲爱的安卓用户们,是不是觉得手机越来越卡,应用更新总是跟不上潮流?别急,今天我要给你来点干货,告诉你...
安卓系统outlook会议提醒... 你有没有发现,手机上的安卓系统越来越智能了?这不,最近我发现了一个超实用的功能——Outlook会议...
安卓系统专业软件剪辑,打造高效... 你有没有想过,手机里的视频剪辑功能竟然也能如此专业?没错,就是那个我们每天不离手的安卓系统,它竟然能...
模拟安卓系统软件,软件功能与体... 你有没有想过,手机里的世界可以变得更加丰富多彩?没错,就是那种可以像安卓系统一样自由自在地玩耍的世界...
安卓换系统会卡吗,换系统会卡吗... 你有没有想过,你的安卓手机用久了,是不是也会像人一样,反应变得迟钝了呢?没错,这就是我们今天要探讨的...
平板安卓系统自动重启,安卓平板... 你是不是也遇到过这种情况?平板电脑突然间就自动重启了,是不是瞬间感觉心里一紧,心想这可怎么办呢?别急...
findx3安卓系统,安卓系统... 你有没有发现,最近手机圈里又掀起了一股热潮?没错,就是OPPO Find X3系列的安卓系统。这款系...
安卓系统删除的软件,那些曾陪伴... 手机里的软件越来越多,是不是有时候觉得内存不够用,想清理一下呢?别急,今天就来聊聊安卓系统删除软件的...
白色的手机安卓系统,安卓系统下... 你有没有发现,最近市面上那些白色的手机简直让人眼前一亮呢?尤其是搭载安卓系统的那些,简直就像是一块块...
vico是不是安卓系统,揭秘安... 最近是不是有很多小伙伴在问:“Vico手机,它是不是运行安卓系统呢?”这个问题可真是让人好奇啊!今天...
安卓10系统省电不,安卓10系... 你有没有发现,自从升级到安卓10系统,手机续航能力好像大不如前了?别急,今天就来给你揭秘安卓10系统...
cm14安卓系统,深度定制与极... 你有没有发现,你的安卓手机最近是不是有点不一样了?是不是觉得系统运行得更加流畅,界面也更加美观了呢?...
平板安卓系统咋样升级,轻松实现... 你那平板安卓系统是不是有点儿卡,想给它来个升级大变身?别急,让我来给你详细说说平板安卓系统咋样升级,...
安卓原系统在哪下载,探索纯净体... 你有没有想过,为什么安卓手机那么受欢迎?那是因为它的系统——安卓原系统,它就像是一个充满活力的魔法师...
安卓系统procreate绘图... 你有没有发现,现在手机上画画变得越来越流行了?尤其是用安卓系统的手机,搭配上那个神奇的Procrea...
电视的安卓系统吗,探索安卓电视... 你有没有想过,家里的电视是不是也在悄悄地使用安卓系统呢?没错,就是那个我们手机上常用的安卓系统。今天...
苹果手机系统操作安卓,苹果iO... 你有没有发现,身边的朋友换手机的时候,总是对苹果和安卓两大阵营争论不休?今天,咱们就来聊聊这个话题,...
安卓系统换成苹果键盘,键盘切换... 你知道吗?最近我在想,要是把安卓系统的手机换成苹果的键盘,那会是怎样的体验呢?想象那是不是就像是在安...
小米操作系统跟安卓系统,深度解... 亲爱的读者们,你是否曾在手机上看到过“小米操作系统”和“安卓系统”这两个词,然后好奇它们之间有什么区...