In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to monitor spring boot. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. Index monitoring
Introduce the jar package:
Org.springframework.boot spring-boot-actuator
Enable it in web mode:
# enable all management.endpoints.enabled-by-default=true#web methods to expose management.endpoints.web.exposure.include=*
Second, commonly used monitoring endpoints
Look at this: the portal.
The most commonly used:
Health: health status to see if the app is available
Metrics:
Runtime metrics, JVM, threads, etc. (important)
Loggers:
Log record
Third, customize EndPoint
It is relatively simple to customize component health information, and you can also implement the interface mode:
Package com.example.demo; import org.springframework.boot.actuate.health.AbstractHealthIndicator;import org.springframework.boot.actuate.health.Health;import org.springframework.stereotype.Component; import java.util.HashMap;import java.util.Map / * * @ author Administrator * / @ Componentpublic class MyComHealthIndicator extends AbstractHealthIndicator {/ * Real check method * @ param builder * @ throws Exception * / @ Override protected void doHealthCheck (Health.Builder builder) throws Exception {Map map = new HashMap (); if (1 check 1) {builder.up (); map.put ("count", 1) Map.put ("msg", "health");} else {builder.down (); map.put ("msg", "timeout");} builder.withDetail ("code", 100) .withdetails (map);}}
Definition of INFO Endpoint:
1. The configuration file directly defines:
Info.mavenProjectName = @ project.artifactId@info.mavenProjectVersion=@project.version@
2. Write code:
Package com.example.demo; import org.springframework.boot.actuate.info.Info;import org.springframework.boot.actuate.info.InfoContributor;import org.springframework.stereotype.Component; @ Componentpublic class AppInfo implements InfoContributor {@ Override public void contribute (Info.Builder builder) {builder.withDetail ("msg", "really handsome!") ;}}
Metrics customizes endpoint, using MeterRegistry directly.
Custom Endpoint to monitor endpoints:
Package com.example.demo; import org.springframework.boot.actuate.endpoint.annotation.Endpoint;import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;import org.springframework.stereotype.Component; import java.util.Collections;import java.util.Map; @ Component@Endpoint (id = "myEndPoint") public class EndPoint {@ ReadOperation public Map read () {return Collections.singletonMap ("MG", "MG GOGO") } @ WriteOperation public void write () {System.out.println (tired);}}
When you access a custom metric, you access the read method
4. Spring boot admin (can be used)
Prepare a server that will regularly get the relevant content of each service.
De.codecentric spring-boot-admin-starter-server
Client registration:
De.codecentric spring-boot-admin-starter-client
Configuration properties file:
Spring: application: name: admin-client boot: admin: client: url: http://localhost:8769 interface:# use IP to register prefer-ip: tureserver: port: 8768 management: endpoints: web: exposure: include:'* endpoint: health: show-details: ALWAYS this article on "how spring boot is monitored" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.