Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CommonsObjectPool2Metrics #1712

Closed
wants to merge 2 commits into from

Conversation

chang-chao
Copy link

fixes #1711

@skabashnyuk
Copy link

skabashnyuk commented Nov 19, 2019

Can this code be reused to implement #1710 org.apache.commons.dbcp2.BasicDataSource statistic?

@chang-chao
Copy link
Author

chang-chao commented Nov 19, 2019

Can this code be reused to implement #1710 org.apache.commons.dbcp2.BasicDataSource statistic?

because dbcp2 uses commons pool2, so I believe yes.all the common metrics of commons pool will be exposed, like MaxIdle , etc, and will check and confirm this.

For the metrics specific to dbcp, like defaultQueryTimeout , this fix will not create them.

@Override
public void bindTo(MeterRegistry registry) {
for (String type : TYPES) {
registerMetricsEventually(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a non-JMX way to register these?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other ways are not always possible as far as I know, because libraries using commons-pool2(like jedis or dbcp2) keeps the pool objects as internal properties, and we cannot get them.
and commons-pool exposes JMX, so using JMX seems to be a natural fit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree JMX as the default is a good idea. I was more curious if there was a way if we did have access to the pool directly. I used commons pool in some of my own code and didn't have JMX enabled at the time. It would be nice to offer a way to still gather those metrics if posssible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we can see from the following code, JMX registration in commons-pool2 is enabled by default , unless you configure to disable it explicitly, which I don't think a serious application should do.
https://github.com/apache/commons-pool/blob/2d2049233940b10c7dd35df70a353d383f601053/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java#L139

"objects");

registerTimeGaugeForObject(
registry, o, "MaxBorrowWaitTimeMillis", "maxBorrowWaitTime", tags, "The maximum time a thread has waited to borrow objects from the pool");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use dot separated names like max.borrow.wait.time, which will be camel-cased by certain NamingConvention implementations. By keeping dot-separated names in the core code, we maximize the portability of the metric to many different monitoring systems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkschneider thanks for pointing it out, fixed in 32c5c0d

@IcyEagle
Copy link

IcyEagle commented Mar 4, 2020

@chao-chang-paypay is this PR considered finished? Can I help you somehow?

I'm actually looking forward to this update 👍

@jkschneider
Copy link
Contributor

Thanks for the hard work on this @chao-chang-paypay. I can see that this was a non-trivial implementation, and you did a fantastic job on it! Polished a bit and merged with 2f7f51b.

@jkschneider jkschneider closed this May 8, 2020
@jkschneider jkschneider added this to the 1.6.0 milestone May 8, 2020
@jkschneider jkschneider added the enhancement A general enhancement label May 8, 2020
@CoderLan0668
Copy link

CoderLan0668 commented Jul 17, 2020

@chang-chao @jkschneider

I already see these code in branch Master,but can not find tnem in the latest release version. What's the problem? and i can not wait anymore.

@AnkitKaneri
Copy link

@chang-chao @jkschneider I am using 1.6.0 version of micrometer-core and micrometer-registry-prometheus. I am not able to find jedis metrics under /actuator/prometheus endpoint. Am I missing anything here?

@izeye
Copy link
Contributor

izeye commented Nov 5, 2020

@AnkitKaneri There's no out-of-the-box support for CommonsObjectPool2Metrics from Spring Boot, so you need to configure it yourself.

See spring-projects/spring-boot#23525 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apache commons pool2 statistics
9 participants