【spring系列】Actuator服务监控与管理

Spring Boot Actuator 服务监控与管理

参考地址:https://docs.spring.io/spring-boot/docs/2.2.0.M6/reference/html/production-ready-features.html#production-ready-enabling

https://docs.spring.io/spring-boot/docs/current/actuator-api/html/

Spring Boot版本:2.2.0.M6

Actuator作用

SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等。

添加actuator模块

基于Maven

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

基于Gradle

dependencies {
    compile("org.springframework.boot:spring-boot-starter-actuator")
}

引用成功之后,即可启动spring boot工程,启动成功如下:

在这里插入图片描述
可看到有health,info 等映射信息。

端点

端点说明详解:

ID描述默认启用
auditevents公开当前应用程序的审核事件信息。
beans显示应用程序中所有Spring Bean的完整列表。
caches公开可用的缓存。
conditions显示在配置和自动配置类上评估的条件以及它们匹配或不匹配的原因。
configprops显示所有的整理列表@ConfigurationProperties
env公开Spring的属性ConfigurableEnvironment
flyway显示已应用的所有Flyway数据库迁移。
health显示应用程序运行状况信息。
httptrace显示HTTP跟踪信息(默认情况下,最近100个HTTP请求-响应交换)。
info显示任意应用程序信息。
integrationgraph显示Spring Integration图。
loggers显示和修改应用程序中记录器的配置。
liquibase显示已应用的所有Liquibase数据库迁移。
metrics显示当前应用程序的“指标”信息。
mappings显示所有@RequestMapping路径的整理列表。
scheduledtasks显示应用程序中的计划任务。
sessions允许从Spring Session支持的会话存储中检索和删除用户会话。使用Spring Session对反应式Web应用程序的支持时不可用。
shutdown使应用程序正常关闭。没有
threaddump执行线程转储。

如果您的应用程序是Web应用程序(Spring MVC,Spring WebFlux或Jersey),则可以使用以下附加端点:

ID描述默认启用
heapdump返回hprof堆转储文件。
jolokia通过HTTP公开JMX bean(当Jolokia在类路径上时,不适用于WebFlux)。
logfile返回日志文件的内容(如果已设置logging.file.namelogging.file.path属性)。支持使用HTTP Range标头来检索部分日志文件的内容。
prometheus以Prometheus服务器可以抓取的格式公开指标。

启动端点

默认情况下,除了shutdown 之外都是开启状态。如果想配置端点状态,可以根management.endpoint.<id>.enabled进行配置端点状态,例如:

#启动shudtown端点
management.endpoint.shutdown.enabled=true

当然也可以默认吧所有端点关闭,然后开启自己想开启的端点。

#修改所有端点开启状态
management.endpoints.enabled-by-default=false
#打开info端点
management.endpoint.info.enabled=true

注意:即使在这里启动了端点,也无法通过web进行访问,需要端点暴露

暴露端点

由于端点可能包含敏感信息,因此应谨慎考虑何时公开它们。下表显示了内置端点的默认暴露:

IDJMXWeb
auditevents没有
beans没有
caches没有
conditions没有
configprops没有
env没有
flyway没有
health
heapdumpN / A没有
httptrace没有
info
integrationgraph没有
jolokiaN / A没有
logfileN / A没有
loggers没有
liquibase没有
metrics没有
mappings没有
prometheusN / A没有
scheduledtasks没有
sessions没有
shutdown没有
threaddump没有

要更改端点暴露,使用下面的特定技术includeexclude特性:

属性默认
management.endpoints.jmx.exposure.exclude
management.endpoints.jmx.exposure.include*
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.includeinfo, health

include属性列出了公开的端点的ID。该exclude属性列出了不应公开的端点的ID。

exclude属性优先于该include属性

例如,要通过HTTP公开除envbeans端点之外的所有内容

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans

Auto-configured HealthIndicators

我们可以根据以下进行自定义配置

名称描述
CassandraHealthIndicator检查Cassandra数据库是否已启动。
CouchbaseHealthIndicator检查Couchbase群集是否已启动。
DiskSpaceHealthIndicator检查磁盘空间不足。
ElasticSearchRestHealthContributorAutoConfiguration检查Elasticsearch集群是否已启动。
HazelcastHealthIndicator检查Hazelcast服务器是否已启动。
InfluxDbHealthIndicator检查InfluxDB服务器是否已启动。
InfluxDbHealthIndicator检查InfluxDB服务器是否已启动。
JmsHealthIndicator检查JMS代理是否启动。
MailHealthIndicator检查邮件服务器是否已启动。
MongoHealthIndicator检查Mongo数据库是否已启动。
PingHealthIndicator一律以回应UP
RabbitHealthIndicator检查Rabbit服务器是否已启动。
RabbitHealthIndicator检查Rabbit服务器是否已启动。
RedisHealthIndicator检查Redis服务器是否启动。
SolrHealthIndicator检查Solr服务器是否已启动。

通过设置management.health.defaults.enabled属性来全部禁用它们

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叁滴水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值