Skip to content

Instantly share code, notes, and snippets.

View dalexandrov's full-sized avatar

Dmitry Aleksandrov dalexandrov

View GitHub Profile
Config helidonConfig = MpConfig.toHelidonConfig(config).get(NEO4J_METRIC_NAME_PREFIX);
ConfigValue<Neo4j> configValue = helidonConfig.as(Neo4j::create);
return configValue.get().driver();
@Inject
public MovieRepository(Driver driver) {
this.driver = driver;
}
# Neo4j settings
neo4j.uri=bolt://localhost:7687
neo4j.authentication.username=neo4j
neo4j.authentication.password: secret
neo4j.pool.metricsEnabled: true
public static class Builder implements io.helidon.common.Builder<Neo4jMetricsSupport> {
private Driver driver;
private Builder() {
}
public Neo4jMetricsSupport build() {
Objects.requireNonNull(driver, "Must set driver before building");
return new Neo4jMetricsSupport(this);
}
public Builder driver(Driver driver) {
this.driver = driver;
private static class Neo4JCounterWrapper implements Counter {
private final Supplier<Long> fn;
private Neo4JCounterWrapper(Supplier<Long> fn) {
this.fn = fn;
}
@Override
public void inc() {
throw new UnsupportedOperationException();
}
@Override
private void registerCounter(MetricRegistry metricRegistry,
ConnectionPoolMetrics cpm,
String poolPrefix,
String name,
Function<ConnectionPoolMetrics, Long> fn) {
String counterName = poolPrefix + name;
if (metricRegistry.getCounters().get(new MetricID(counterName)) == null) {
Metadata metadata = Metadata.builder()
.withName(counterName)
.withType(MetricType.COUNTER)
private void reinit() {
Map<String, Function<ConnectionPoolMetrics, Long>> counters = Map.ofEntries(
entry("acquired", ConnectionPoolMetrics::acquired),
entry("closed", ConnectionPoolMetrics::closed),
entry("created", ConnectionPoolMetrics::created),
entry("failedToCreate", ConnectionPoolMetrics::failedToCreate),
entry("timedOutToAcquire", ConnectionPoolMetrics::timedOutToAcquire),
entry("totalAcquisitionTime", ConnectionPoolMetrics::totalAcquisitionTime),
entry("totalConnectionTime", ConnectionPoolMetrics::totalConnectionTime),
entry("totalInUseCount", ConnectionPoolMetrics::totalInUseCount),
private void refreshMetrics(ScheduledExecutorService executor) {
Collection<ConnectionPoolMetrics> currentPoolMetrics = driver.metrics().connectionPoolMetrics();
if (!metricsInitialized.get() && currentPoolMetrics.size() >= 1) {
lastPoolMetrics.set(currentPoolMetrics);
reinit();
if (metricsInitialized.get()) {
reinitFuture.get().cancel(false);
executor.shutdown();
}
}