Three steps to integrate activator monitoring function into your springboot

Yugong wants to move mountains 2021-01-21 12:18:50
steps integrate activator monitoring function


Preface

Sometimes we want to monitor the running status of our applications in real time , For example, display some index data in real time , Look at the traffic that's being visited all the time , Or the access status of our database and so on . It's time to Actuator 了 .

Use Actuator Are the benefits of , We can use this production level tool directly , You don't have to do it yourself .Actuator It can automatically help us expose this information , Use HTTP Or is it JMX beans The way to achieve . The main thing is that we are directly in properties Configuration in the file .

Let's see how to achieve :

Code implementation

Create a springboot project , I'm using Springboot2.4 Version of .

First step : Add dependency

<!-- Monitoring dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Dependence is so simple .

The second step : To configure

# Change the port of the application
server.port=8081
#1、actuator The default is only on info and health Two endpoints
# The following configuration enables all endpoints :
management.endpoints.web.exposure.include= *
#2、 Turn on health monitoring data
management.endpoint.health.show-details=always
#3、 Enable httptrace Endpoint
management.endpoint.httptrace.enabled=true
#4、 Every time you add actuator Prefixes are too cumbersome , Change the endpoint prefix path
management.endpoints.web.base-path= /

So a few configurations are added .

Now we can visit it directly .

The third step : Direct access

Because we configured our own base-path. So there's no need to add actuator The prefix of . Now access :

http://localhost:8081/mappings

We'll see this picture when we visit , It looks a little ugly , But with this information , You can also format the display , At present, there are many open source projects that can be implemented automatically .

Other ports are as follows : The address above can be mappings Just change it .

EndPoints describe
auditevents Expose audit event information for the current application .
beans Show all of the Spring bean A complete list of .
caches Expose available cache .
conditions Shows the conditions evaluated on the configuration and autoconfiguration classes and why they match or do not match .
configprops Show a list of all the collations @ConfigurationProperties, View configuration properties , Include default configuration
env Reveal Spring Various environment variables for the properties of , Follow me /{name} See the specific values
flyway Show any... That has been applied Flyway Database migration .
health Display app health information ,2.0 In the future, it needs to be in the configuration show-details open k switch
httptrace Show HTTP Tracking information ,2.0 You need to open it manually in the future
info Display any application information , It's defined in the configuration file
integrationgraph Show Spring Integration chart .
loggers Display and modify the configuration of the recorder in the application .
liquibase Show any... That has been applied Liquibase Database migration .
metrics Display indicator information , Such as memory usage and HTTP Request count , You can follow /{name} See the specific values
mappings Show all @RequestMapping A list of paths .
scheduledtasks Show scheduled tasks in the application .
sessions Allow from Spring Session Retrieve and delete user sessions from supported session stores .
shutdown Allow the application to shut down normally .
threaddump Execute thread dump .

OK. It's basically like this .

by Actuator Add security validation

Like our Actuator I don't want to be seen by anyone else , So you can configure Spring security Add login . The way is as follows :

First step : Add dependency

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

The second step : stay properties Add the configuration to the file

#5、 Port information is seen by others how to do , You can add security
spring.security.user.name= fdd
spring.security.user.password= 123456
spring.security.user.roles= ADMIN

The user interface set here is fdd, password 123456, The role is ADMIN.

The third step : Re access the port address above

Re access the relevant port address , Will be redirected to the login page . Log in with the configured user name and password .

OK, This is simpler .

版权声明
本文为[Yugong wants to move mountains]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121121742387b.html

  1. Docker learning - compose
  2. Explain HTTP message in detail
  3. Miscellaneous Linux 2
  4. Self taught Linux 12. Shell advanced
  5. Linux system service control (detailed)
  6. Summary of Linux common commands (continuous update)
  7. Java7 date time API
  8. MySQL日期和时间函数汇总
  9. MySQL date and time function summary
  10. Hive compression and column storage
  11. Constants, variables and data types in Java
  12. Front end interview of HTTP protocol things!
  13. 54 official spring boot starters! Stop making wheels again .
  14. Common linux commands
  15. MYSQL
  16. Linux common command learning
  17. redis设置密码
  18. Redis set password
  19. Basic operation of MySQL
  20. Crawler series | 2, HTTP request and response, write crawler these contents must master
  21. Usage of mysqldump command in Linux
  22. Research and analysis of JVM virtual machine class file
  23. Research and analysis of JVM virtual machine class file
  24. Official spring boot starters
  25. MySQL -- where
  26. Interesting redis: detailed explanation of data structure - ziplist
  27. [unfinished] java basic syntax
  28. Common JVM commands and performance tuning suggestions [could not create the Java virtual machine]
  29. Spring quartz time configuration rules
  30. The use of k8s resource choreography (yaml)
  31. [Linux] learn operation and maintenance step by step - Fundamentals - RPM management
  32. Linux diff command
  33. Spring boot2 series tutorial (15) | one of the server parameter verification
  34. JDBC data type
  35. Kernel data structure migration (list and rbtree)
  36. MySQL must know and must know notes -- basic knowledge of query
  37. [Linux] classic interview questions system management backup strategy
  38. MySQL must know and must know notes -- basic knowledge of query
  39. [Linux] classic interview questions system management backup strategy
  40. Chinese open source a small and full Java tool class library, powerful ah!!
  41. Parameter validation in springboot
  42. Introduction to JavaScript Foundation Series (1)
  43. Java common and useful troubleshooting tools (continuous improvement)
  44. Hutool -- a small and comprehensive Java tool class library, is not only a sharp tool to solve small problems in large-scale project development, but also an efficient tool in small-scale projects
  45. JQuery easyUI DataGrid performance optimization topic
  46. Maven dependency range
  47. [efficient coding] simple and comprehensive JDK monitoring commands. Just read this one!! A pawn in the sun
  48. [HTTP column introduction] HTTP learning and cognition
  49. Use of declarative transactions in spring
  50. Mybatis typealiases element label (including annotation method) and its attributes and settings
  51. Dockerfile command
  52. PNG file interpretation (2): PNG format file structure and data structure interpretation - decoding PNG data