Add POM dependencies:
<!-- spring-boot-monitoring--><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>
Specify the monitored HTTP port in application.yml (if not specified, the same port as Server); specify to remove a certain check (such as not monitoring health.mail):
server: port: 8083management: port: 8083 security: enabled: false #
Monitor and manage endpoints
| Endpoint name | describe |
|---|---|
| autoconfig | All automatic configuration information (positiveMatches: running, negativeMatches not running components) |
| auditivets | Audit events |
| beans | All Bean information |
| configprops | All configuration properties |
| dump | Thread status information |
| env | Current environment information |
| health | Apply health status |
| info | Current application information |
| metrics | Various indicators of application |
| mappings | Apply @RequestMapping map path |
| shutdown | Close the current application (closed by default) |
| trace | Tracking information (latest http request) |
| heapdump | Download memory snapshots |
http://localhost:8083/info Read the info.* property of the configuration file application.properties
Read in InfoProperties
application.properties:
info.app.version=v1.2.0info.app.name=abc
Get git.properties information in GitProperties
info.app.version=v1.2.0info.app.name=abc#Remotely close and enable endpoints.shutdown.enabled=true #Access: http://localhost:8083/shutdown Close service
metrics
{mem: 573549, //Memory size mem.free: 388198, //Memory remaining size processors: 4, //Number of processors instance.uptime: 338426,uptime: 345091,systemload.average: -1,heap.committed: 489984,heap.init: 131072,heap.used: 101785,heap: 1842688,nonheap.committed: 85056,nonheap.init: 2496,nonheap.used: 83566,nonheap: 0,threads.peak: 46,threads.daemon: 36,threads.totalStarted: 72,threads: 39, //Thread classes: 12109,classes.loaded: 12109, //Loaded class classes.unloaded: 0, //Unloaded class gc.ps_scavenge.count: 10,gc.ps_scavenge.time: 103,gc.ps_marksweep.count: 3,gc.ps_marksweep.time: 219,httpsessions.max: -1,httpsessions.active: 0,gauge.response.mappings: 3,gauge.response.autoconfig: 4,gauge.response.trace: 167,counter.status.200.mappings: 1,counter.status.200.autoconfig: 2,counter.status.200.trace: 1} Custom configuration instructions:
#Close the metrics function endpoints.metrics.enabled=false#Enable shutdown remote shutdown endpoints.shutdown.enabled=true#Set beansIdendpoints.beans.id=mybean#Set beans path endpoints.beans.path=/bean#Close beans function endpoints.beans.enabled=false#Change all endpoints.enabled=false#Enable single beans function endpoints.beans.enabled=true#All access add root directory management.context-path=/managemanagement.port=8181
The org.springframework.boot.actuate.health package contains all health status checks, such as RedisHealthIndicator, which will be checked when there is a redis starter.
{ status: "DOWN", //Status diskSpace: { status: "UP", total: 395243941888, free: 367246643200, threshold: 10485760 }, rabbit: { status: "DOWN", error: "org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect" }, redis: { status: "UP", version: "4.0.9" }, db: { status: "UP", database: "MySQL", hello: 1 }}Custom health
•Custom health status indicator
•1. Write an indicator to implement the HealthIndicator interface
•2. The name of the indicator xxxxHealthIndicator
•3. Add to container
import org.springframework.boot.actuate.health.Health;import org.springframework.boot.actuate.health.HealthIndicator;import org.springframework.stereotype.Component;@Componentpublic class MyAppHealthIndicator implements HealthIndicator { @Override public Health health() { //Customized check method//Health.up().build() represents health return Health.down().withDetail("msg","Service exception").build(); }}Summarize
The above is the configuration and use tutorial for spring boot starter actuator (health monitoring) introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!