Spring-boot Express (3) Actuator

Source: Internet
Author: User

By exposing a series of endpoints, actuator allows developers to quickly understand the various running metrics of spring boot, such as the number of threads, the rest of the JVM's memory, and so on.

The Enable method is simple, see below:

dependencies {    compile (' org.springframework.boot:spring-boot-starter-thymeleaf ')    compile (' Org.springframework.boot:spring-boot-devtools ')    compile (' Org.springframework.boot: Spring-boot-starter-actuator ')    compile (' org.springframework.boot:spring-boot-starter-test ')    Compileonly (' Org.projectlombok:lombok ')}

The key is to add spring-boot-starter-actuator dependencies, and the following table is a list of endpoints provided by actuator (copied from the official documents)

ID Description Sensitive Default

actuator

Provides a hypermedia-based "Discovery page" for the other endpoints. Requires Spring HATEOAS to is on the classpath.

True

auditevents

Exposes audit events information for the current application.

True

autoconfig

Displays an auto-configuration to showing all auto-configuration candidates and the reason why they ' were ' or ' were no T ' applied.

True

beans

Displays a complete list of all the Spring beans in your application.

True

configprops

Displays a collated list of all @ConfigurationProperties .

True

dump

Performs a thread dump.

True

env

Exposes properties from Spring ' s ConfigurableEnvironment .

True

flyway

Shows any Flyway database migrations that has been applied.

True

health

Shows application health information (when the application is secure,

A simple ' status ' when accessed over an unauthenticated connection or

Full message details when authenticated).

False

info

Displays arbitrary application info.

False

loggers

Shows and modifies the configuration of loggers in the application.

True

liquibase

Shows any Liquibase database migrations that has been applied.

True

metrics

Shows ' metrics ' information for the current application.

True

mappings

Displays a collated list of all @RequestMapping paths.

True

shutdown

Allows the application to is gracefully shutdown (not enabled by default).

True

trace

Displays trace information (by default, the last HTTP requests).

True

In this table, a lot of information is actually sensitive information, not suitable for anonymous access (especially in the public network environment), so by default, if you want to access similar http://localhost:8081/metrics you will see the following error:

It is good practice to separate these endpoints ports, including the access path, from the ports of the regular application, APPLICATION.YML can refer to the following configuration:

Server:  port:8081spring:  main:    banner-mode: "Off"  devtools:    restart:      trigger-file:. Trigger  thymeleaf:    cache:falsemanagement:  security:    enabled:false #关掉安全认证  port:1101 # Management port adjusted to 1101  Context-path:/admin #actuator的访问路径

If in the public network environment, it is recommended to make the next limit on the firewall, only allow 8081 to come in, 1101 for intranet access, so relatively safe, and do not have to enter the cumbersome password.

Under Http://localhost:1101/admin/metrics, you can see output similar to the following:

{mem:466881,mem.free:289887,processors:4,instance.uptime:10947,uptime:18135,systemload.average:3.12646484375, heap.committed:411648,heap.init:131072,heap.used:121760,heap:1864192,nonheap.committed:56192,nonheap.init:2496 , nonheap.used:55234,nonheap:0,threads.peak:27,threads.daemon:19,threads.totalstarted:32,threads:22,classes: 6755,classes.loaded:6755,classes.unloaded:0,gc.ps_scavenge.count:8,gc.ps_scavenge.time:136,gc.ps_ Marksweep.count:2,gc.ps_marksweep.time:193,httpsessions.max: -1,httpsessions.active:0}

JVM memory, CPU cores, number of threads, GC situation at a glance, combined with some other tools to collect this information into the Grafana, there is a series of useful monitoring chart data, such as:

Other endpoint, do not show each one, we are interested in self-study, the last to mention is shutdown this endpoint, it can achieve graceful shutdown, this online deployment is very useful, call this URL before release, let the application gracefully stop, and then deploy new code, This will not cause the request being processed to be interrupted, but by default the feature is turned off, which can be enabled by the following settings:

Endpoints:  shutdown:    enabled:true

And for security reasons, the URL can only be accessed by post, which is the effect of using postman to simulate post access to Http://locahost:1101/admin/shutdown:

Also in the log you can see that the application is actually closed:

Reference article:

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready

Spring-boot Express (3) Actuator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.