llinux jconsole监控内存泄漏_Spring Boot之程序性能监控

本文介绍了如何使用Spring Boot的actuator模块进行性能监控,并通过JConsole和Spring Boot Admin展示监控信息。详细讲述了actuator接口的配置,以及JConsole的使用方法,同时展示了Spring Boot Admin如何集成和展示监控数据。
摘要由CSDN通过智能技术生成

作者:zhaoyh

http://zhaoyh.com.cn

Spring Boot特别适合团队构建各种可快速迭代的微服务,同时为了减少程序本身监控系统的开发量,Spring Boot提供了actuator模块,可以很方便的对你的Spring Boot程序做监控。

1. actuator接口说明

Spring Boot应用中加入监控很简单,只需要在pom.xml文件中加入以下依赖:

org.springframework.bootspring-boot-starter-actuator

为了保证actuator接口的敏感性,在配置文件中,开放安全属性配置:

management.security.enabled=false

这样就能允许你查看Spring Boot进程的actuator信息了。

启动Spring Boot程序,在启动日志里看到可访问的actuator接口:

7f6d6d44759faa65bcb51236fb9513a4.png

通过这些,我们可以实时的获取应用的各项监控指标。

actuator的接口分为原生接口和用户自定义接口。原生接口主要有如下几个:

8e9763011ab7b402dd4a254827789b62.png

如果你想关闭某个接口,比如关闭health接口,可以直接设置:

endpoints.health.enabled=false

2. 监控展示

2.1 JConsole

JConsole是一个内置Java性能分析器,如果你本机已经配置了jdk的话,可直接命令行输入jconsole,打开后的页面如下图所示:

3f7026af6eaabf18c4fc75125f1f1f31.png

选择你要监控的进程,点击连接即可进入该Java进程的监控首页,如下图所示:

6a0bdc5c374ec55d6337515db7ca8c7e.png

可以很详细地展示进程的内存、CPU、类信息。

2.2 Spring Boot Admin

Spring Boot Admin是一款监控和管理Spring Boot应用程序的开源软件。Spring Boot Admin读取actuator的接口数据,并通过Spring Boot Admin UI将实时数据展示在前端。

创建一个Spring Boot Admin Server,首先需要创建一个基本的Spring Boot应用程序,这个就不做赘述了,并加入以下依赖:

3328c2ab6c68a24b949569fdc1fce0c1.png

浏览器访问:http://localhost:8090 即可看到如下Spring Boot Admin Server的页面:

07a5a67802e485bfabcfb91a246866a6.png

在任意需要被监控的Spring Boot应用程序上,添加依赖:

de.codecentric    spring-boot-admin-starter-client    1.5.7

启动客户端后,稍等片刻,Spring Boot Admin Server从Eureka上拿到注册信息后,即可在 http://localhost:8090 上看到应用程序的监控信息了:

92cae483e9f10c92990d223307bd8221.png

3. FAQ

  • Spring Boot Admin Server上可以配置邮件告警信息,添加自己的Email即可收到告警信息。
  • Spring Boot Admin Server监控的应用程序服务,需要和Spring Boot Admin Server都注册到Eureka上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值