Skip to content

Instantly share code, notes, and snippets.

@dalexandrov
Created February 23, 2021 14:41
Show Gist options
  • Save dalexandrov/f854ab2c780363eaa5a81e933eb6391e to your computer and use it in GitHub Desktop.
Save dalexandrov/f854ab2c780363eaa5a81e933eb6391e to your computer and use it in GitHub Desktop.
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)
.notReusable()
.build();
Neo4JCounterWrapper wrapper = new Neo4JCounterWrapper(() -> fn.apply(cpm));
metricRegistry.register(metadata, wrapper);
}
}
private void registerGauge(MetricRegistry metricRegistry,
ConnectionPoolMetrics cpm,
String poolPrefix,
String name,
Function<ConnectionPoolMetrics, Integer> fn) {
String gaugeName = poolPrefix + name;
if (metricRegistry.getGauges().get(new MetricID(gaugeName)) == null) {
Metadata metadata = Metadata.builder()
.withName(poolPrefix + name)
.withType(MetricType.GAUGE)
.notReusable()
.build();
Neo4JGaugeWrapper<Integer> wrapper =
new Neo4JGaugeWrapper<>(() -> fn.apply(cpm));
metricRegistry.register(metadata, wrapper);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment