Spring Boot 应用这些可视化监控,一目了然!快来试试吧!
作者:你照亮了我的世界blog.csdn.net/weixin_44196699/article/details/105010045
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@EnableSpringBootMetricsCollectorpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
最后,配置默认的登录账号和密码,在 application.yml
中:
security: user: name:user password: pwd
启动应用程序后,会看到如下一系列的 Mappings
img
利用账号密码访问 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指标数据
2、Prometheus 采集 Spring Boot 指标数据
$ docker pull prom/prometheus
然后,编写配置文件 prometheus.yml
:
global: scrape_interval: 10s scrape_timeout: 10s evaluation_interval: 10mscrape_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 采集状态是否正常,如果看到下图就是成功了。
img
3、Grafana 可视化监控数据
$ docker pull grafana/grafana1
然后,启动 Grafana:
$ docker run --name grafana -d -p 3000:3000 grafana/grafana1
接着,访问 http://localhost:3000/ 配置 Prometheus 数据源:
-
先配置数据源.
img
img
img
img
prometh
采集的数据
img
img
一步步安装Jumpserver堡垒机图文详解(官方教程版),从此爽歪歪!零散的MySQL基础总是记不住?看这一篇如何拯救你相同字符串,但是equals为false?我多年的java白学了吗?华为面试官:为什么 HashMap 的加载因子是0.75?趣头条面试题:ThreadLocal是什么?怎么用?为什么用它?有什么缺点@Autowire和@Resource注解使用的正确姿势,这些年我一直用错了!!强大:MyBatis 流式查询华为面试官:为什么 HashMap 的加载因子是0.75?SpringBoot+OAuth2+JWT实现单点登录SSO完整教程,竟如此简单优雅!Springboot启动扩展点超详细总结,再也不怕面试官问了点击阅读全文前往微服务电商教程
继续阅读

资源分享QQ群
本站是一个IT技术分享社区, 会经常分享资源和教程; 分享的时代, 请别再沉默!
评论