Windows_安装整合Prometheus + Grafana监控主机和Flink作业
迪丽瓦拉
2025-05-29 07:28:32
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 即可(下拉选项)

相关内容

热门资讯

linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
C++ 机房预约系统(六):学... 8、 学生模块 8.1 学生子菜单、登录和注销 实现步骤: 在Student.cpp的...
A.机器学习入门算法(三):基... 机器学习算法(三):K近邻(k-nearest neigh...
数字温湿度传感器DHT11模块... 模块实例https://blog.csdn.net/qq_38393591/article/deta...
有限元三角形单元的等效节点力 文章目录前言一、重新复习一下有限元三角形单元的理论1、三角形单元的形函数(Nÿ...
Redis 所有支持的数据结构... Redis 是一种开源的基于键值对存储的 NoSQL 数据库,支持多种数据结构。以下是...
win下pytorch安装—c... 安装目录一、cuda安装1.1、cuda版本选择1.2、下载安装二、cudnn安装三、pytorch...
MySQL基础-多表查询 文章目录MySQL基础-多表查询一、案例及引入1、基础概念2、笛卡尔积的理解二、多表查询的分类1、等...
keil调试专题篇 调试的前提是需要连接调试器比如STLINK。 然后点击菜单或者快捷图标均可进入调试模式。 如果前面...
MATLAB | 全网最详细网... 一篇超超超长,超超超全面网络图绘制教程,本篇基本能讲清楚所有绘制要点&#...
IHome主页 - 让你的浏览... 随着互联网的发展,人们越来越离不开浏览器了。每天上班、学习、娱乐,浏览器...
TCP 协议 一、TCP 协议概念 TCP即传输控制协议(Transmission Control ...
营业执照的经营范围有哪些 营业执照的经营范围有哪些 经营范围是指企业可以从事的生产经营与服务项目,是进行公司注册...
C++ 可变体(variant... 一、可变体(variant) 基础用法 Union的问题: 无法知道当前使用的类型是什...
血压计语音芯片,电子医疗设备声... 语音电子血压计是带有语音提示功能的电子血压计,测量前至测量结果全程语音播报࿰...
MySQL OCP888题解0... 文章目录1、原题1.1、英文原题1.2、答案2、题目解析2.1、题干解析2.2、选项解析3、知识点3...
【2023-Pytorch-检... (肆十二想说的一些话)Yolo这个系列我们已经更新了大概一年的时间,现在基本的流程也走走通了,包含数...
实战项目:保险行业用户分类 这里写目录标题1、项目介绍1.1 行业背景1.2 数据介绍2、代码实现导入数据探索数据处理列标签名异...
记录--我在前端干工地(thr... 这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 前段时间接触了Th...
43 openEuler搭建A... 文章目录43 openEuler搭建Apache服务器-配置文件说明和管理模块43.1 配置文件说明...