-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1964 from newrelic/hikaricp-24
HikariCP 2.4.0 module
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# hikaricp-2.4.0 Instrumentation Module | ||
This module supports HikariCP version 2.4.0 to current. | ||
|
||
### Important Note Regarding Use of the Legacy HikariCP Extension Module | ||
This built in instrumentation module replaces the extension module that can be downloaded from the New Relic | ||
[download site](https://download.newrelic.com/newrelic/java-agent/extensions/). The `hikaricp-2.4.0.jar` | ||
artifact should be removed from the agent's `extension` folder if present. | ||
|
||
### Reported Metrics | ||
Every 5 seconds, the following metrics will be reported: | ||
- `Database Connection/HikariCP/{PoolName}/Busy Count[connections]`: Retrieved from the [HikariPoolMXBean](https://www.javadoc.io/doc/com.zaxxer/HikariCP/2.4.6/com/zaxxer/hikari/HikariPoolMXBean.html) instance | ||
- `Database Connection/HikariCP/{PoolName}/Idle Count[connections]`: Retrieved from the [HikariPoolMXBean](https://www.javadoc.io/doc/com.zaxxer/HikariCP/2.4.6/com/zaxxer/hikari/HikariPoolMXBean.html) instance | ||
- `Database Connection/HikariCP/{PoolName}/Max Pool Size[connections]`: Retrieved from the [HikariConfig](https://www.javadoc.io/static/com.zaxxer/HikariCP/2.4.6/index.html?com/zaxxer/hikari/pool/HikariPool.html) instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("com.zaxxer:HikariCP:2.4.1") | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.hikaricp-2.4.0' | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'com.zaxxer:HikariCP:[2.4.0,)' | ||
} | ||
|
||
site { | ||
title 'HikariCP' | ||
type 'Datastore' | ||
} |
23 changes: 23 additions & 0 deletions
23
...ation/hikaricp-2.4.0/src/main/java/com/zaxxer/hikari/pool/HikariPool_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.zaxxer.hikari.pool; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariPoolMXBean; | ||
|
||
@Weave(originalName = "com.zaxxer.hikari.pool.HikariPool", type = MatchType.ExactClass) | ||
public abstract class HikariPool_Instrumentation implements HikariPoolMXBean { | ||
|
||
public HikariPool_Instrumentation(HikariConfig config) { | ||
AgentBridge.privateApi.addSampler(new PooledDataSourceSampler(this, config), 5, TimeUnit.SECONDS); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...entation/hikaricp-2.4.0/src/main/java/com/zaxxer/hikari/pool/PooledDataSourceSampler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.zaxxer.hikari.pool; | ||
|
||
import com.newrelic.api.agent.MetricAggregator; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.zaxxer.hikari.HikariConfig; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** | ||
* This sampler keeps a weak reference to a BaseHikariPool and | ||
* reports metrics about it. | ||
*/ | ||
public class PooledDataSourceSampler implements Runnable { | ||
|
||
private final WeakReference<HikariPool_Instrumentation> hikariPoolRef; | ||
private final WeakReference<HikariConfig> hikariConfigRef; | ||
private final String baseName; | ||
|
||
public PooledDataSourceSampler(HikariPool_Instrumentation hikariPool, HikariConfig config) { | ||
this.hikariPoolRef = new WeakReference<>(hikariPool); | ||
this.hikariConfigRef = new WeakReference<>(config); | ||
this.baseName = "Database Connection/HikariCP/" + config.getPoolName() + '/'; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
HikariPool_Instrumentation hikariPool = hikariPoolRef.get(); | ||
HikariConfig config = hikariConfigRef.get(); | ||
if (null == hikariPool || null == config) { | ||
return; | ||
} | ||
|
||
MetricAggregator metricAggregator = NewRelic.getAgent().getMetricAggregator(); | ||
metricAggregator.recordMetric(baseName + "Busy Count[connections]", hikariPool.getActiveConnections()); | ||
metricAggregator.recordMetric(baseName + "Idle Count[connections]", hikariPool.getIdleConnections()); | ||
metricAggregator.recordMetric(baseName + "Max Pool Size[connections]", config.getMaximumPoolSize()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters