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

How to monitor spring boot

2025-01-17 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.

Share To

Development

Wechat

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

12
Report