Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of spring boot actuator Monitoring

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the example analysis of spring boot actuator monitoring, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

Spring boot actuator introduction

Spring Boot includes many other features to help you monitor and manage applications as you push them to a production environment.

You can choose to use HTTP endpoints or JMX to manage and monitor applications.

Auditing, health, and metrics collection can also be automatically applied to your application.

In short, Spring Boot Actuator is a framework that can help you monitor system data, it can monitor a lot of system data, it has the integration of self-examination and monitoring of the application system, and you can view the details of the application configuration, such as:

Display Health health information for application programmers

Display Info application information

Display HTTP Request trace information

Displays the "Metrics" information for the current application

Show path information for all @ RequestMapping

Display various configuration information for the application

Display all kinds of information such as the number of requests from your program, time and so on.

Wait, wait... In short, it is very mature and powerful.

Introduction to use:

1. First add dependencies to pom.xml:

Org.springframework.boot spring-boot-starter-actuator

For Gradle, use the following declaration:

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

two。 All monitoring endpoints are described by endpoints:

ID describes that auditevents exposes audit event information for the current application. Beans displays a complete list of all the Spring bean in the application. Caches exposes available caches. Conditions displays the conditions evaluated on the configuration and automatic configuration classes and the reasons for their match or mismatch. Configprops displays all the collated lists @ ConfigurationProperties, and looks at the configuration properties, including various environment variables that the default configuration env exposes the properties of Spring, followed by / {name} to see the specific value flyway to show any Flyway database migrations that have been applied. Health displays application health information. After spring boot2.0, you need to open all health information in the configuration show-details to display HTTP tracking information (by default, the last 100 HTTP request-response exchanges). After 2.0, you need to manually open info to display any application information. The integrationgraph is defined in the configuration file to display the Spring Integration diagram. Loggers displays and modifies the configuration of loggers in the application. Liquibase displays any Liquibase database migrations that have been applied. Metrics displays "metrics" information about the current application, such as memory usage and HTTP request count, and then / {name} to see the specific value mappings shows a collated list of all @ RequestMapping paths. Scheduledtasks displays the scheduled tasks in the application. Sessions allows you to retrieve and delete user sessions from the session store supported by Spring Session. Not available when using Spring Session support for responsive Web applications shutdown allows the application to shut down normally. Threaddump performs a thread dump.

If your application is a Web application (Spring MVC,Spring WebFlux or Jersey), you can use the following additional endpoints:

ID describes that heapdump returns a hprof heap dump file. Jolokia exposes JMX bean through HTTP (not applicable to WebFlux when Jolokia is on the classpath). Logfile returns the contents of the log file if the logging.file or logging.path property is set. Support the use of HTTP Range headers to retrieve the contents of some log files. Prometheus exposes metrics in a format that can be crawled by the Prometheus server. Note:

1. After spring boot 2.0, actuator only enables info and health endpoints by default. To use other endpoints, you need to open them in application.yml:

Management: endpoints: web: exposure: include: "*"

Note:

Here include: "*", this "" double quotation mark is required, and there is no need for "" double quotation mark in application.properties. It goes like this in application.properties: management.endpoints.web.exposure.include=*.

3. And all endpoints start with the default path http://localhost:8080/actuator

If we look at the information of info endpoints, we can visit: http://localhost:8080/actuator/info

4.Timestamps timestamps: all timestamps consumed by the endpoint (as query parameters or in the request body) must be formatted as the offset date and time specified in ISO 8601. The default timestamp is inconsistent with our Chinese time zone.

Most of 5.actuator 's monitoring requests are made with get. Only a few are post requests.

6. If you want to change the default actuator startup path, you can change it in application.yml, for example, we change it to http://localhost:8080/

# adjust the prefix path of the endpoint to / management: endpoints: web: base-path: /

And the information of the health endpoint is not specific by default. Please see what the default health shows:

"UP" is safe and healthy, "DOWN" is a problem.

7. Enable all Heanth monitoring data in application.yml:

Management: endpoint: health: show-details:always # displays health details but does not display details by default

My application.yml goes like this:

Now you can turn on the service and try the monitoring data of these endpoints, because I have changed the monitoring path to http://localhost:8088. So you can follow the name of the endpoint directly. If you do not change the path, the default startup path is http://localhost:8088/actuator/, followed by the name of the endpoint you want to monitor:

Http://localhost:8088/metrics

Http://localhost:8088/mappings

The data monitored by the endpoint Metrics is as follows

These data can be monitored, "disk utilization", this is my custom metrics endpoint information, in the following article I will teach you how to customize the endpoint you want. If you want to see more specific, please add the data you want to see after the path, / {name}, such as:

Http://localhost:8088/metrics/jvm.memory.used

Custom info information:

By adding dependencies to pom.xml, you can access the information of pom.xml. Without this, the info information you define in application.yml will not be obtained:

Org.apache.maven.plugins maven-resources-plugin 2.6 @ false

Configure in application.yml as follows:

# Custom info endpoints to view application-related information info: encoding: @ project.build.sourceEncoding@ traget: @ java.version@ name: @ project.name@ description: @ project.description@

Access http://localhost:8088/info and run the result as follows:

But if you just want to open an endpoint, here's how we configure it, the same style in application.yml:

Management: endpoint: endpoint name: enabled: true

Use Spring Security to secure Actuator Endpoints:

Add dependencies in pom.xml:

Org.springframework.boot spring-boot-starter-security

Configure it like this in application.yml: this is in later versions of spring boot2.0, but not before 2.0, with a slight difference:

# http security mechanism security: user: name: li password: 123 roles: ADMIN

Then start your service and you will find a login page that requires you to enter the account password we configured:

It should be noted that the configuration of Security after spring boot2.0 is different from that before, which I mentioned in an article!

Custom endpoints:

First, customize the endpoint Health for health monitoring:

There are two ways to customize the endpoints of health monitoring:

1. Inherit AbstractHealthIndicator class 2. Implement the HealthIndicator interface.

Thank you for reading this article carefully. I hope the article "sample Analysis of spring boot actuator Monitoring" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report