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

What are the three steps to integrate Actuator and implement application monitoring for your Springboot application

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Which three steps for your Springboot application to integrate Actuator and implement application monitoring, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Preface

Sometimes we want to monitor the running status of our applications in real time, such as displaying some metric data in real time, observing the traffic accessed all the time, or the access status of our database, and so on. That's when you need Actuator.

The advantage of using Actuator is that we can use this production-level tool directly without having to implement these things ourselves. Actuator can automatically help us expose this information automatically, using HTTP or JMX beans. The most important thing is that we can configure it directly in the properties file.

Let's see how to do this:

Code implementation

To create a springboot project, I used the version of Springboot2.4.

Step 1: add dependencies

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

Dependence is as simple as that.

Step 2: configure

# change the application port server.port=8081 # 1, actuator only enables info and health endpoints by default # all endpoints can be enabled in the following configuration: management.endpoints.web.exposure.include= * # 2, enable health monitoring data management.endpoint.health.show-details=always # 3, enable httptrace endpoint management.endpoint.httptrace.enabled=true # 4, add an actuator prefix every time is too troublesome, change the endpoint prefix path management.endpoints.web.base-path= /

So several configurations have been added.

Now we can just visit directly.

Step 3: direct access

Because we configured our own base-path earlier. So there is no need to add the prefix of actuator. Visit now:

Http://localhost:8081/mappings

Such a picture will appear when we visit, which looks a bit ugly, but with this information, it can also be formatted to show that there are many open source projects that can be implemented automatically.

The other ports are as follows: you can change the mappings of the address above.

EndPoints 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. Show-details needs to turn on k switch httptrace to display HTTP tracking information in the configuration after 2.0. after 2.0, you need to manually open info to display any application information, which is an integrationgraph display Spring Integration diagram defined by yourself in the configuration file. 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, such as memory usage and HTTP request count, and then / {name} to see the specific value mappings displays 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. Shutdown allows the application to shut down normally. Threaddump performs a thread dump.

OK . Basically.

Add security authentication for Actuator

For example, the port of our Actuator does not want to be seen by unrelated people, so we can configure Spring security to add login. The way is as follows:

Step 1: add dependencies

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

Step 2: add the configuration to the properties file

# 5. What if the port information is seen by others, you can add a security spring.security.user.name= fdd spring.security.user.password= 123456 spring.security.user.roles= ADMIN

The user face set here is fdd, the password is 123456, and the role is ADMIN.

Step 3: revisit the port address above

Revisit the relevant port address and it will be redirected to the login page. Log in with the configured username and password.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Network Security

Wechat

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

12
Report