SpringBoot可视化监控的具体应用
作者:你照亮了我的世界 时间:2023-07-28 20:32:02
本文主要介绍了Spring Boot 应用可视化监控,分享给大家,具体如下:
1、Spring Boot 应用暴露监控指标【版本 1.5.7.RELEASE】
首先,添加依赖如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
/*采集应用的指标信息,我们使用的是prometheus,相应的我们引入包:*/
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId> <version>0.0.26</version>
</dependency>
然后,在启动类 Application.java
添加如 * 解:
@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {
public static void main(String[] args) { SpringApplication.run(Application.class, args);
}
}
最后,配置默认的登录账号和密码,在 application.yml
中:
security:
user:
name:user
password: pwd
启动应用程序后,会看到如下一系列的 Mappings
利用账号密码访问 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指标数据
2、Prometheus 采集 Spring Boot 指标数据
首先,获取 Prometheus 的 Docker 镜像:
$ docker pull prom/prometheus
然后,编写配置文件 prometheus.yml
:
global:
scrape_interval: 10s
scrape_timeout: 10s
evaluation_interval: 10m
scrape_configs:
- job_name: spring-boot
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /application/prometheus
scheme: http
basic_auth:
username: admin
password: 123456
static_configs:
- targets:
- 192.168.11.54:8099 #此处填写 Spring Boot 应用的 IP + 端口号
接着,启动 Prometheus :
docker run -d --name prometheus -p 9090:9090
-v D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
请注意,
D:\test\actuator\prometheus\prometheus.yml
,是我的配置文件存放地址,我们需要将它放到容器里面去,所以用了-v
来做文件映射。/etc/prometheus/prometheus.yml
这个是容器启动的时候去取的默认配置,这里我是直接覆盖掉了它。prom/prometheus
这是镜像,如果本地没有,就回去你设置好的镜像仓库去取。
启动完成后用**docker ps
**看下是否已经启动成功,之后打开浏览器输入:http://localhost:9090/targets
,检查 Spring Boot 采集状态是否正常,如果看到下图就是成功了。
3、Grafana 可视化监控数据
首先,获取 Grafana 的 Docker 镜像:
$ docker pull grafana/grafana
然后,启动 Grafana:
$ docker run --name grafana -d -p 3000:3000 grafana/grafana
接着,访问 http://localhost:3000/ 配置 Prometheus 数据源:
Grafana 登录账号 admin 密码 admin
先配置数据源.
2.配置单个指标的可视化监控面板:
prometh
采集的数据
来源:https://blog.csdn.net/weixin_44196699/article/details/105010045
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android系统进程间通信Binder机制在应用程序框架层的Java接口源代码分析
![](https://img.aspxhome.com/file/2023/7/125437_0s.jpg)
C#去除字符串中的反斜杠实例(推荐)
![](https://img.aspxhome.com/file/2023/3/119513_0s.jpg)
java实现文件上传下载功能
![](https://img.aspxhome.com/file/2023/7/85887_0s.jpg)
如何实现Java中一个简单的LinkedList
Java实现五子棋游戏
Unity登录注册时限制发送验证码次数功能的解决方法
C#实现自动生成电子印章
![](https://img.aspxhome.com/file/2023/6/91276_0s.png)
java实现多线程之定时器任务
SpringBoot整合rockerMQ消息队列详解
![](https://img.aspxhome.com/file/2023/0/68530_0s.png)
Java Git Commit Message使用规范
![](https://img.aspxhome.com/file/2023/4/94354_0s.webp)
C++类中的六大默认成员函数详解
![](https://img.aspxhome.com/file/2023/1/129531_0s.png)
完美解决springboot中使用mybatis字段不能进行自动映射的问题
![](https://img.aspxhome.com/file/2023/7/61157_0s.png)
判断List和Map是否相等并合并List中相同的Map
实战SpringBoot集成JWT实现token验证
![](https://img.aspxhome.com/file/2023/8/62138_0s.jpg)
Android通过Socket与服务器之间进行通信的示例
Java 随机生成验证码(支持大小写字母、数字、随机字体)的实例
java实现文件夹解压和压缩
基于Spring中各个jar包的作用及依赖(详解)
![](https://img.aspxhome.com/file/2023/0/116240_0s.png)
详解Android 7.0 Settings 加载选项
![](https://img.aspxhome.com/file/2023/5/137445_0s.png)
Maven插件的安装及使用
![](https://img.aspxhome.com/file/2023/5/64155_0s.jpg)