前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springboot(20)Actuator使用

springboot(20)Actuator使用

作者头像
IT架构圈
发布2018-06-01 13:07:51
5940
发布2018-06-01 13:07:51
举报
文章被收录于专栏:IT架构圈IT架构圈

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

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

代码语言:javascript
复制
<?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.liming</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>

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

端口号

代码语言:javascript
复制
server.port=8888

项目信息

代码语言:javascript
复制
info.name=liming
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可以看到如下图:

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-04-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 编程坑太多 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档