为了账号安全,请及时绑定邮箱和手机立即绑定

使用Actuator监控

标签:
SpringBoot

Actuator可能大家非常熟悉,它是springboot提供对应用自身监控,以及对应用系统配置查看等功能。

springboot使用actuator的方式非常简单,只需要在项目中加入依赖spring-boot-starter-actuator,完整pom文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.dalaoyang</groupId>
	<artifactId>springboot_actuator</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>springboot_actuator</name>
	<description>springboot_actuator</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

其余没有任何修改,没有新建任何类,在配置文件中加入了几条属性,配置文件如下:

##端口号
server.port=8888


##项目信息
info.name=dalaoyang
info.server.port=${server.port}

然后启动项目可以看到:

介绍一下红框内的Actuator暴露的功能:

HTTP方法路径描述鉴权
GET/autoconfig查看自动配置的使用情况true
GET/configprops查看配置属性,包括默认配置true
GET/beans查看bean及其关系列表true
GET/dump打印线程栈true
GET/env查看所有环境变量true
GET/env/{name}查看具体变量值true
GET/health查看应用健康指标false
GET/info查看应用信息false
GET/mappings查看所有url映射true
GET/metrics查看应用基本指标true
GET/metrics/{name}查看具体指标true
POST/shutdown关闭应用true
GET/trace查看基本追踪信息true

通过上面表格,我们可以在浏览器上访问http://localhost:8888/health可以看到如下图:

访问http://localhost:8888/info,可以看到

源码下载 :大老杨码云

个人网站:https://dalaoyang.cn


点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
全栈工程师
手记
粉丝
1.6万
获赞与收藏
1139

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消