In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Springboot how to use actuator, 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.
Springboot actuator is a health check mechanism that tracks the status of various springboot applications. You need to add a pom to use it.
Org.springframework.boot spring-boot-starter-actuator
When starting springboot, we often see such a log Exposing 20 endpoint (s) beneath base path'/ actuator'
This 20 is the number of health checkpoints for each springboot application, which varies depending on the configuration in your configuration file.
Because the Server information I configured is as follows
Server: port: 8001 servlet: context-path: / api-u
So when we access the actuator Web information as follows
Http://127.0.0.1:8001/api-u/actuator
It should be noted here that if we configure oauth 2 resource access, we need to release this path.
@ EnableResourceServer@EnableWebSecurity@EnableGlobalMethodSecurity (prePostEnabled = true,securedEnabled = true) public class ResourceServerConfig extends ResourceServerConfigurerAdapter {@ Override public void configure (HttpSecurity http) throws Exception {http.csrf () .disable () .exceptionHandling () .authenticationEntryPoint ((request, response, authException)-> response.sendError (HttpServletResponse.SC_UNAUTHORIZED)) .and () .authorizeRequests () .antMatchers (PermitAllUrl.permitAllUrl ("/ users-anon/**", "/ sys/login") "/ actuator/**") .permitAll () / add "/ actuator/**" here to release .anyRequest () .authenticated () .and () .httpBasic () } @ Override public void configure (ResourceServerSecurityConfigurer resource) throws Exception {/ / add custom exceptions to resource.authenticationEntryPoint (new AuthExceptionEntryPoint ()) .accessDeniedHandl er (new CustomAccessDeniedHandler ());} @ Bean public BCryptPasswordEncoder bCryptPasswordEncoder () {return new BCryptPasswordEncoder ();}}
Make the following configuration in the configuration file
Management: endpoint: health: show-details: always
The result of our visit to http://127.0.0.1:8001/api-u/actuator at this time is as follows
{
"_ links": {
"self": {
"href": "http://127.0.0.1:8001/api-u/actuator""
"templated": false
}
"health": {
"href": "http://127.0.0.1:8001/api-u/actuator/health""
"templated": false
}
"info": {
"href": "http://127.0.0.1:8001/api-u/actuator/info""
"templated": false
}
}
}
For details, you can refer to this official website to explain the https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/
Https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#production-ready-endpoints-enabling-endpoints and https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#_auto_configured_healthindicators
The http://127.0.0.1:8001/api-u/actuator/health is the specific information of the health examination we need.
{
"status": "DOWN"
"details": {
"rabbit": {
"status": "DOWN"
"details": {
"error": "org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)"
}
}
"diskSpace": {
"status": "UP"
"details": {
"total": 499963174912
"free": 435209195520
"threshold": 10485760
}
}
"db": {
"status": "UP"
"details": {
"database": "MySQL"
"hello": 1
}
}
"refreshScope": {
"status": "UP"
}
"discoveryComposite": {
"status": "UP"
"details": {
"discoveryClient": {
"status": "UP"
"details": {
"services": [
"register-center"
"user-center"
]
}
}
"eureka": {
"description": "Remote status from Eureka server"
"status": "UP"
"details": {
"applications": {
"REGISTER-CENTER": 1
"USER-CENTER": 1
}
}
}
}
}
"configServer": {
"status": "UNKNOWN"
"details": {
"error": "no property sources located"
}
}
"hystrix": {
"status": "UP"
}
"redis": {
"status": "UP"
"details": {
"version": "3.2.12"
}
}
}
}
Here is the health status of the various services supported by the process spring. UP is online, DOWN is offline, and UNKNOWN is unknown.
Besides http://127.0.0.1:8001/api-u/actuator/health, there is a http://127.0.0.1:8001/api-u/actuator/info.
This is a description of the information, if we do the following configuration in the configuration file
Info: app-name: user author: guanjian email: 12345@xy.com
You can see it in the returned information of http://127.0.0.1:8001/api-u/actuator/info.
{
"app-name": "user"
"author": "guanjian"
"email": "12345@xy.com"
}
However, we can see very little information in the above configuration. We need to activate all actuator endpoints. The additional configuration is as follows
Management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always
The result of visiting http://127.0.0.1:8001/api-u/actuator again at this time is as follows
{
"_ links": {
"self": {
"href": "http://127.0.0.1:8001/api-u/actuator""
"templated": false
}
"archaius": {
"href": "http://127.0.0.1:8001/api-u/actuator/archaius""
"templated": false
}
"auditevents": {
"href": "http://127.0.0.1:8001/api-u/actuator/auditevents""
"templated": false
}
"beans": {
"href": "http://127.0.0.1:8001/api-u/actuator/beans""
"templated": false
}
"health": {
"href": "http://127.0.0.1:8001/api-u/actuator/health""
"templated": false
}
"conditions": {
"href": "http://127.0.0.1:8001/api-u/actuator/conditions""
"templated": false
}
"configprops": {
"href": "http://127.0.0.1:8001/api-u/actuator/configprops""
"templated": false
}
"env": {
"href": "http://127.0.0.1:8001/api-u/actuator/env""
"templated": false
}
"env-toMatch": {
"href": "http://127.0.0.1:8001/api-u/actuator/env/{toMatch}""
"templated": true
}
"info": {
"href": "http://127.0.0.1:8001/api-u/actuator/info""
"templated": false
}
"logfile": {
"href": "http://127.0.0.1:8001/api-u/actuator/logfile""
"templated": false
}
"loggers-name": {
"href": "http://127.0.0.1:8001/api-u/actuator/loggers/{name}""
"templated": true
}
"loggers": {
"href": "http://127.0.0.1:8001/api-u/actuator/loggers""
"templated": false
}
"heapdump": {
"href": "http://127.0.0.1:8001/api-u/actuator/heapdump""
"templated": false
}
"threaddump": {
"href": "http://127.0.0.1:8001/api-u/actuator/threaddump""
"templated": false
}
"metrics-requiredMetricName": {
"href": "http://127.0.0.1:8001/api-u/actuator/metrics/{requiredMetricName}""
"templated": true
}
"metrics": {
"href": "http://127.0.0.1:8001/api-u/actuator/metrics""
"templated": false
}
"scheduledtasks": {
"href": "http://127.0.0.1:8001/api-u/actuator/scheduledtasks""
"templated": false
}
"sessions-sessionId": {
"href": "http://127.0.0.1:8001/api-u/actuator/sessions/{sessionId}""
"templated": true
}
"sessions": {
"href": "http://127.0.0.1:8001/api-u/actuator/sessions""
"templated": false
}
"httptrace": {
"href": "http://127.0.0.1:8001/api-u/actuator/httptrace""
"templated": false
}
"mappings": {
"href": "http://127.0.0.1:8001/api-u/actuator/mappings""
"templated": false
}
"refresh": {
"href": "http://127.0.0.1:8001/api-u/actuator/refresh""
"templated": false
}
"features": {
"href": "http://127.0.0.1:8001/api-u/actuator/features""
"templated": false
}
"service-registry": {
"href": "http://127.0.0.1:8001/api-u/actuator/service-registry""
"templated": false
}
}
}
Now pick a few to do instructions http://127.0.0.1:8001/api-u/actuator/configprops to view all the configuration information (of course, the password will be hidden) snippet
"spring.cloud.config-org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties": {
"prefix": "spring.cloud.config"
"properties": {
"overrideSystemProperties": true
"overrideNone": false
"allowOverride": true
}
}
"configClientProperties": {
"prefix": "spring.cloud.config"
"properties": {
"headers": {}
"discovery": {
"enabled": false
"serviceId": "configserver"
}
"profile": "default"
"name": "user-center"
"uri": "http://localhost:8888""
"enabled": true
"failFast": false
"username": "user"
}
}
Http://127.0.0.1:8001/api-u/actuator/metrics looks at the specific values of some metrics, such as JVM,tomcat and so on.
{
"names": [
"rabbitmq.acknowledged"
"rabbitmq.consumed"
"jvm.buffer.memory.used"
"jvm.memory.used"
"jvm.gc.memory.allocated"
"rabbitmq.connections"
"jvm.memory.committed"
"tomcat.global.request.max"
"tomcat.sessions.created"
"tomcat.sessions.expired"
"jvm.gc.max.data.size"
"logback.events"
"rabbitmq.published"
"system.cpu.count"
"jvm.memory.max"
"rabbitmq.rejected"
"jvm.buffer.total.capacity"
"jvm.buffer.count"
"process.files.max"
"jvm.threads.daemon"
"rabbitmq.channels"
"process.start.time"
"tomcat.global.error"
"tomcat.sessions.active.max"
"http.server.requests"
"tomcat.global.sent"
"jvm.gc.live.data.size"
"process.files.open"
"process.cpu.usage"
"tomcat.global.received"
"tomcat.servlet.request"
"jvm.gc.pause"
"process.uptime"
"tomcat.threads.config.max"
"system.load.average.1m"
"tomcat.cache.hit"
"tomcat.servlet.error"
"tomcat.threads.current"
"tomcat.servlet.request.max"
"tomcat.cache.access"
"tomcat.sessions.active.current"
"system.cpu.usage"
"jvm.threads.live"
"jvm.classes.loaded"
"jvm.classes.unloaded"
"tomcat.threads.busy"
"jvm.threads.peak"
"jvm.gc.memory.promoted"
"tomcat.sessions.rejected"
"tomcat.sessions.alive.max"
"tomcat.global.request"
]
}
For example, we want to check the maximum memory of JVM and access http://127.0.0.1:8001/api-u/actuator/metrics/jvm.memory.max.
{
"name": "jvm.memory.max"
"measurements": [
{
"statistic": "VALUE"
"value": 5.587337215 billion
}
]
"availableTags": [
{
"tag": "area"
"values": [
"heap"
"nonheap"
]
}
{
"tag": "id"
"values": [
"Compressed Class Space"
"PS Survivor Space"
"PS Old Gen"
"Metaspace"
"PS Eden Space"
"Code Cache"
]
}
]
}
Memory already used by http://127.0.0.1:8001/api-u/actuator/metrics/jvm.memory.used JVM
{
"name": "jvm.memory.used"
"measurements": [
{
"statistic": "VALUE"
"value": 931.419992 million
}
]
"availableTags": [
{
"tag": "area"
"values": [
"heap"
"nonheap"
]
}
{
"tag": "id"
"values": [
"Compressed Class Space"
"PS Old Gen"
"PS Survivor Space"
"Metaspace"
"PS Eden Space"
"Code Cache"
]
}
]
}
Http://127.0.0.1:8001/api-u/actuator/beans views all bean injected in spring
Partial fragment
"spring.cloud.config-org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties": {
"aliases": []
"scope": "singleton"
"type": "org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties"
"resource": null
"dependencies": []
}
"propertySourcesPlaceholderConfigurer": {
"aliases": []
"scope": "singleton"
"type": "org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
"resource": "org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration"
"dependencies": []
}
If we do not want to activate all endpoints, but only some endpoints, such as configprops,metrics,beans,health,info, configure as follows
Management: endpoints: web: exposure: include: "configprops,metrics,beans,health,info" endpoint: health: show-details: always
The result of accessing http://127.0.0.1:8001/api-u/actuator is as follows
{
"_ links": {
"self": {
"href": "http://127.0.0.1:8001/api-u/actuator""
"templated": false
}
"beans": {
"href": "http://127.0.0.1:8001/api-u/actuator/beans""
"templated": false
}
"health": {
"href": "http://127.0.0.1:8001/api-u/actuator/health""
"templated": false
}
"configprops": {
"href": "http://127.0.0.1:8001/api-u/actuator/configprops""
"templated": false
}
"info": {
"href": "http://127.0.0.1:8001/api-u/actuator/info""
"templated": false
}
"metrics-requiredMetricName": {
"href": "http://127.0.0.1:8001/api-u/actuator/metrics/{requiredMetricName}""
"templated": true
}
"metrics": {
"href": "http://127.0.0.1:8001/api-u/actuator/metrics""
"templated": false
}
}
}
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.