In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to clean up the useless metrics indicators of SpringBoot applications. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Preface
Last week, a netizen asked springboot program more and more metrics, there is a 40W index, now want to remove some useless metrics, how to do?
I thought it was interesting to see this question at that time, because my online program also had dynamic metrics, but the index did not reach that large amount, so I studied how to deal with this problem.
Use what you add to make a dynamic metrics to see if deletion is supported.
Dynamic creation of metrics is a direct use of io.micrometer.core.instrument.MeterRegistry objects, such as registry.gauge (name,tags,valueObject). You can add a gauge type metrics of name to registry, and you can see the new metrics when collecting metrics.
So see if there are any other ways to delete this object:
The first time I tried the delete method, I found that there was no similar method:
Metrics-try-delete-method
Then try remove and you can see that there are two remove methods available, passing in the ID object and the metrics object, respectively, but if you need to
And clean it all up? Is there a clear method similar to List?
Metrics-try-remove-method
Try the clear method again, and found that there is this method, and I first tested it to see if the clear method can achieve the desired (clear metrics).
Metrics-try-clear-method practical test
So I had a meal of operation:
Write an API interface, the interface content is to execute meterRegistry.clear ()
Start the springboot program
The browser looks at the content returned by the / actuator/prometheus interface.
Call the API that cleans up metrics, which is the interface written in the first step
Take a look at the content returned by the / actuator/prometheus interface in the browser again.
Clean up the contents of the interface before metrics:
Clear-metrics-before
Clean up the contents of the API after metrics:
Clear-metrics-after
You can see that metrics clears the information after calling the interface.
The method is effective ✔, can reply to the netizen.
Netizens can't actually do it.
Clear-method-for-metrics
Netizens say there is no such way? What's going on?!
Click into the clear source code to take a look, the method description is very clear, 1.2.0 release method, and netizens use the version less than 1.2.0, so there is no such method.
/ * *
* Clear all meters.
* @ since 1.2.0
, /
@ Incubating (since = "1.2.0")
Public void clear () {
MeterMap.keySet () forEach (this::remove)
}
Can you delete a specific metricsclear-metrics-from-tags based on certain tags
Yes, of course!
Metrics-registry-find-tags.png
You can see that the tag list of each metrics is available, so it's easy to filter out the metrics you want to delete through tag comparison, and then delete it with the remove method.
When the program has dynamically added metrics, it is necessary to consider the mechanism of clearing useless metrics. If the number of metrics is too large, it will affect business applications.
The above content is how to clean up the useless metrics indicators of SpringBoot applications. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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.