uclient添加网址不了_Springboot添加应用jvm监控 ,实现数据可视化

本文介绍了如何使用Springboot Actuator和Micrometer集成Prometheus进行应用监控,以及如何通过Grafana实现数据可视化。在Springboot项目中添加监控依赖并配置相关端点,然后配置Prometheus抓取监控数据,最后在Grafana中导入模板展示监控图表。文章还提及了Shiro过滤器配置和解决Broken pipe异常的方法。
摘要由CSDN通过智能技术生成

5ce6b0342187ef1b27849dc806d0ef84.png

1.简介
最近越发觉得,任何一个系统上线,运维监控都太重要了。本文介绍Prometheus + Grafana的方法监控Springboot 2.X,实现美观漂亮的数据可视化。
2.添加监控
Spring-boot-actuator module 可帮助您在将应用程序投入生产时监视和管理应用程序。您可以选择使用 HTTP 端点或 JMX 来管理和监控您的应用程序。Auditing, health, and metrics gathering 也可以自动应用于您的应用程序。引入依赖如下:
<!--监控报警--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
对于Springboot,要开启Actuator,并打开对应的Endpoint:
#prometheus配置 info:alen:alenmanagement:endpoints:web:base-path:/actuatorexposure:include:"*"
启动Springboot后,可以通过下面URL看能不能正确获取到监控数据:localhost/actuator/prometheus 获取数据成功,说明Springboot能正常提供监控数据。

ac1bb83079b0082a4df1d6864e9d4abe.png


主要的端点

5acc432aa75ad6b92b6440fca9ba0980.png


3.配置Prometheus
Prometheus 是 Cloud Native Computing Foundation 项目之一,是一个系统和服务监控系统。它按给定的时间间隔从配置的目标收集指标,评估规则表达式,显示结果,并且如果观察到某些条件为真,则可触发警报。
特性
• 多维度 数据模型(由度量名称和键/值维度集定义的时间序列) • 灵活的查询语言 来利用这种维度 • 不依赖分布式存储;单个服务器节点是自治的 • 时间序列采集通过HTTP上的 pull model 发生 • 推送时间序列 通过中间网关得到支持 • 通过 服务发现 或 静态配置 来发现目标 • 多种模式的 图形和仪表盘支持 • 支持分级和水平 federation复制代码
通过 Prometheus 来抓取数据 Prometheus 会按照配置的时间周期去 pull 暴露的端点(/actuator/prometheus)中的指标数据 prometheus.yml 配置
- job_name: 'actuator-ruoyi' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. metrics_path: '/actuator/prometheus' static_configs: - targets: ['10.42.95.4']
重然后再启动prometheus,访问prometheus网址,查看targets启动是否正常如下图

e5fb7477e4c72d8fee138274f3f8eb32.png


4.Grafana添加监控模版
默认启动后Grafana地址为:http://localhost:3000/,登录用户名和密码是admin/admin,import配置grafana id = 4701

bfcd7ed40beb1ee8e730728b107e91cd.png


最终的效果是这样子的,如下图

3d621ee4116cf3cc169ae5e113f3904f.png


5.备注
问题:添加上访问不了Endpoint?解决方案:原因是项目用的shiro,需要添加过滤
filterChainDefinitionMap.put("/actuator/**","anon");
问题二:
/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Broken pipe
解决方法:导致这个错误的原因是 project.artifactId 可能包含了大写。改成小写就行

a3e5799ac9745d01fbe76dee17c5cdc5.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值