# Instrumentation for ConnectionPool

**URL:** <https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942>\
**Category:** APM\
**Tags:** java\
**Created:** [July 6, 2020, 2:57am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942 "2020-07-06T02:57:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CoderLan](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@CoderLan](https://discuss.elastic.co/u/CoderLan)\
**Post date:** [July 6, 2020, 2:57am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/1 "2020-07-06T02:57:26Z")

</div>

Connection Pool , including JDBC and redis, i think it's necessary to record that how long it takes to get a connection from connection pool. What's more, metrics about connection pool, for example active connection num, idle connection num, max total num , they are useful to anaylize the performnce of the application.

The question is that how can i acheive the goals above by the current java agent?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [July 7, 2020, 7:07am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/2 "2020-07-07T07:07:22Z")

</div>

Hi @CoderLan,

Does the connection pool you are currently using provides monitoring metrics through JMX ?  
If yes (and most of them do), that means that you should be able to track those metrics through [capture\_jmx\_metrics](https://www.elastic.co/guide/en/apm/agent/java/current/config-jmx.html#config-capture-jmx-metrics) configuration option.

APM agent does not collect the time to get a connection from pool, this metric is often used as a proxy to know if the pool (or the backend server) is under pressure or not. However, with proper monitoring of the pool state itself, it should not be required.

---

<div class="post-metadata">

**Author:** ![CoderLan](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@CoderLan](https://discuss.elastic.co/u/CoderLan)\
**Post date:** [July 7, 2020, 8:53am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/3 "2020-07-07T08:53:58Z")

</div>

@Sylvain_Juge

As the pool is under pressure, the request will takes a long time, if the span of getting connection from pool is miss, the timeline of this transaction will confuse the developers, they don't know what's the performance problem, util they analyze the metrics of the pool.

So, is it helpful?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [July 7, 2020, 9:30am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/4 "2020-07-07T09:30:26Z")

</div>

I see, so if I understand correctly:

- there is no dedicated span for the "get connection from pool" in transaction timeline
- unless watching pool metrics, it's not really obvious that the issue is around DB pool (and/or DB server)

Thus in other words, providing a way to capture "how much time is spent waiting for connection" maybe as a span in transaction timeline would make it easier, right ?

---

<div class="post-metadata">

**Author:** ![CoderLan](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@CoderLan](https://discuss.elastic.co/u/CoderLan)\
**Post date:** [July 7, 2020, 9:32am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/5 "2020-07-07T09:32:02Z")

</div>

Yes, that's it.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [July 7, 2020, 1:27pm UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/6 "2020-07-07T13:27:58Z")

</div>

Ok, so we already have [an issue (#941)](https://github.com/elastic/apm-agent-java/issues/941) to implement this, so it's not covered yet.

However, agent now includes a sampling profiler that allows to create inferred spans automatically for slow methods. Here are a few links to know more and to how to use it:

- [blog post](https://www.elastic.co/blog/from-distributed-tracing-to-distributed-profiling-with-elastic-apm) that explains how the feature works
- [profiling configuration](https://www.elastic.co/guide/en/apm/agent/java/current/config-profiling.html)
- [how to find slow methods](https://www.elastic.co/guide/en/apm/agent/java/current/java-method-monitoring.html)

---

<div class="post-metadata">

**Author:** ![CoderLan](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@CoderLan](https://discuss.elastic.co/u/CoderLan)\
**Post date:** [July 8, 2020, 11:22am UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/8 "2020-07-08T11:22:36Z")

</div>

@Sylvain_Juge

I'm sure that the jmx metrics has been reported to the apm server, but i can not find any charts of these jmx metrics in kibana, where can i get it?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [July 8, 2020, 4:03pm UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/9 "2020-07-08T16:03:46Z")

</div>

There is no pre-defined chart for JMX metrics, mostly because that requires some knowledge about what is measured.

The easiest way is to use `Lens` or `TSVB` (Time Series Visualization Builder) in Kibana to create those.

One thing to know is that those metrics aren't included in KQL auto-completion by default. You have to use "refresh field list" icon in top right of "Index Patterns" section (between star and delete icon), here is a screenshot with version 7.8:

 ![Screenshot from 2020-07-08 17-59-31](https://us1.discourse-cdn.com/elastic/original/3X/f/d/fd4034304cd565b59fe4e2136faeaf83a59f3921.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 29, 2020, 12:07pm UTC](https://discuss.elastic.co/t/instrumentation-for-connectionpool/239942/10 "2020-07-29T12:07:18Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
