In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about how to cooperate with the container for SpringBoot health examination. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Needless to say about the importance of monitoring, do not spend any more time in meetings to discuss its necessity, when you encounter problems online, you will no longer suspect that monitoring is a waste of development costs. Monitoring lets people say goodbye to the fire fighting status quo maintained by "guessing", and it can leave evidence to support our follow-up analysis.
As the primary goal of monitoring, the viability of the service, that is, its health, has become a top priority. SpringBoot can turn on health check with simple parameters and can be integrated with mainstream monitoring systems.
1. Monitoring on
In Spring, actuator components are used to do monitoring and other related operations. You can add the following starter to pom:
Org.springframework.boot spring-boot-starter-actuator
For gradle, add the following.
Dependencies {compile ("org.springframework.boot:spring-boot-starter-actuator")}
Visit / actuator/health to get the health status of the project.
{"status": "UP"}
In the application.yml file, add the following:
Management: endpoint: health: show-details: always
If you visit this interface again, you will output the details. Including the status of DB, disk status and so on. As you can see, the outermost status is actually a collection of internal component states.
{"status": "UP", "components": {"db": {"status": "UP", "details": {"database": "H2", "validationQuery": "isValid ()"}}, "diskSpace": {"status": "UP" "details": {"total": 250685575168, "free": 31373905920, "threshold": 10485760, "exists": true}}, "ping": {"status": "UP"}
two。 Custom Indicator
These functions are realized by Indicators (HealthIndicator). Such as the following:
DataSourceHealthIndicator
DiskSpaceHealthIndicator
CouchbaseHealthIndicator
MongoHealthIndicator
RedisHealthIndicator
CassandraHealthIndicator
If you are using the starter provided by the component, the Indicator will be aggregated in the / health interface, and if you do not want to monitor a component, you can turn it off in the configuration.
Management: health: mongo: enabled: false
With this in mind, when working on some components, you can provide the health check that comes with the component in this way: you only need to implement the HealthIndicator interface. The code example is as follows:
@ Component @ Slf4j public class X implements HealthIndicator {@ Override public Health health () {try {/ / check component status exception message} catch (Exception e) {log.warn ("Failed to connect to: {}", URL) Return Health.down () .withdetail ("error", e.getMessage ()) .build ();} return Health.up () .build ();}}
3. Access to the monitoring system
In more cases, we hope to collect the business monitoring data using professional monitoring components. This can be done in SpringBoot using micrometer.
Take the most popular prometheus as an example, add the following to pom.
Io.micrometer micrometer-registry-prometheus
Of course, we also need to configure some content in yaml. It now looks like this:
Management: endpoints: web: exposure: include: health,info,prometheus endpoint: health: show-details: always
At this point, visit / actuator/prometheus to obtain the monitoring data in prometheus format.
Similar to the following:
Jvm_memory_used_bytes {area= "heap", id= "PS Survivor Space",} 0.0 jvm_memory_used_bytes {area= "heap", id= "PS Old Gen",} 29.444904 million jvm_memory_used_bytes {area= "heap", id= "PS Eden Space",} 68.29 million jvm_memory_used_bytes {area= "nonheap", id= "Metaspace",} 59.17196 million jvm_memory_used_bytes {area= "nonheap", id= "Code Cache",} 10.929088 million jvm_memory_used_bytes {area= "nonheap" Id= "Compressed Class Space",} 8420512.0
On the target page of prometheus, you can see the following information:
Finally, in Grafana, it looks a little more flirtatious.
What can it monitor? Let's take a look:
Basic information of service nodes, including memory CPU, network IO, etc.
JVM stack information
JVM GC information, STW information
Connection pool information for default HikariCP
HTTP requests interface information (maximum time consuming, highest QPS)
Tomcat container monitoring
Logback log printing monitoring (number of entries at all levels)
... Other
As you can see, only by exposing such an interface, you can have a more comprehensive control of the components in the project.
4. Cooperate with the container
Finally, because of SpringBoot services, it is often published to containers, such as docker. At this point, use the probes configuration (kube has the same concept). Probes means probe and is used to distinguish between Liveness and Readiness.
The final configuration is as follows:
Management: health: probes: enabled: true endpoints: web: exposure: include: health,info,prometheus endpoint: health: show-details: always
At this point, we will get two groups in the browser's interface, as shown below:
Http://localhost:8080/actuator/health/liveness
Http://localhost:8080/actuator/health/readiness
These two links, the former is used to determine whether the container should be restarted, while the latter determines whether the service is available and, if available, will begin to accept external requests.
End
For small-scale SpringBoot applications, monitoring such as SpringBootAdmin is sufficient. But if your enterprise is centralized deployment, many nodes and frequent changes, a unified monitoring and construction platform is very necessary.
In addition to Prometheus,SpringBoot 's Metrics, the following components are supported:
AppOptics
Atlas
Datadog
Dynatrace
Elastic
Ganglia
Graphite
Humio
Influx
JMX
KairosDB
New Relic
Prometheus
SignalFx
Simple (in-memory)
Stackdriver
StatsD
Wavefront
This is how the SpringBoot health check shared by the editor cooperates with the container. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.