Spring boot actuator Endpoint Enabling and Exposing Operations

  • 2021-11-02 00:48:46
  • OfStack

Enable endpoint

By default, everything except the shutdown endpoint is turned off. Configure the enabling of 1 endpoint, using the management. endpoint... enabled property,

The following example is to enable the shutdown endpoint:


management.endpoint.shutdown.enabled=true

If you personally prefer to enable and turn off custom endpoints, you can use the following properties


management.endpoints.enabled-by-default=false

The above attribute will turn off all endpoint enabling situations, and you can enable endpoints by setting the enabled attribute alone;

The following example shows closing all endpoints and enabling the info endpoint:


management.endpoints.enabled-by-default = false
management.endpoint.info.enabled = true

A disabled endpoint is removed from the ApplicationContext context, and if you simply want to change the exposure of the endpoint technically, you can use the include and exclude attributes instead.

Open endpoint

Because endpoints may contain sensitive information, you should carefully consider when to expose them.

The following table shows the exposure of built-in endpoints:

ID JMX Web
auditevents 没有
beans 没有
caches 没有
conditions 没有
configprops 没有
env 没有
flyway 没有
health
heapdump N / A 没有
httptrace 没有
info
integrationgraph 没有
jolokia N / A 没有
logfile N / A 没有
loggers 没有
liquibase 没有
metrics 没有
mappings 没有
prometheus N / A 没有
scheduledtasks 没有
sessions 没有
shutdown 没有
threaddump 没有

To change endpoint exposure, use the following specific technology include and exclude features:

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

The include property lists the ID that exposes the endpoint, and the exclude property lists the ID that should not expose the endpoint; The exclude property takes precedence over the include property, and both include and exclude properties can configure ID using endpoint lists.

For example

To stop exposing all endpoints through JMX and display only endpoints health and info endpoints, use the following properties:


management.endpoints.jmx.exposure.include=health,info

* Can be used to select all endpoints. For example, to expose everything except the env and beans endpoints through HTTP, use the following properties:


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

It has a special meaning in YAML, so if you want to use include or exclude to include all endpoints, put double quotation marks, as in the following example:


management:
  endpoints:
    web:
      exposure:
        include: "*"

Related articles: