Skip to content
Vlad Mihalcea edited this page Oct 27, 2024 · 21 revisions

Metrics

FlexyPool records the following metrics

Name Description

concurrentConnectionsHistogram

A histogram of the number of concurrent connections. This indicates how many connections are being used at once.

concurrentConnectionRequestsHistogram

A histogram of the number of concurrent connection requests. This indicates how many connection are being requested at once.

connectionAcquisitionMillis

A time histogram for the target data source connection acquire interval.

connectionLeaseMillis

A time histogram for the connection lease time. The lease time is the duration between the moment a connection is acquired and the time it gets released.

maxPoolSizeHistogram

A histogram of the target pool size. The pool size might change if the IncrementPoolOnTimeoutConnectionAcquisitionStrategy is being used.

overallconnectionAcquisitionMillis

A time histogram for the total connection acquire interval. This is the connectionAcquisitionMillis plus the time spent by the connection acquire strategies.

overgrowPoolSizeHistogram

A histogram of the pool size overgrowing. The pool size might overgrow if the IncrementPoolOnTimeoutConnectionAcquisitionStrategy is being used.

retryAttemptsHistogram

A histogram of the retry attempts number. This is incremented by the RetryConnectionAcquisitionStrategy.

Flexy Pool defaults to Dropwizard Metrics when dealing with Metrics, but you are free to supply your own MetricsFactory implementation, if that’s suits you better.

Dropwizard Metrics

Make sure you read the Dropwizard manual first, especially the Reservoir section as it greatly influences the Metrics results.

Dropwizard Reservoirs

Basically, there are four reservoir options:

  • Uniform Reservoir is useful when you are interested in all the data that was ever produced as opposed to a time window data snapshot.

  • Exponentially Decaying Reservoir is the default Reservoir used by both Dropwizard and FlexyPool. It approximates the last five minutes of data, so the metrics are meaningful only for the most recent data.

  • Sliding Window Reservoir only considers the last N data entries, so the metrics are meaningful only for the most recent data.

  • Sliding Time Window Reservoir only considers the last N seconds of data entries, so the metrics are meaningful only for the most recent data.

A real-life example

The following Metrics example was produced using the following Configuration. I explicitly set the MetricsFactory option to use the DropwizardMetrics.UNIFORM_RESERVOIR_FACTORY or the DropwizardMetrics.UNIFORM_RESERVOIR_FACTORY, which uses the Dropwizard UniformReservoir.

<data.source.minPoolSize>0</data.source.minPoolSize>
<data.source.maxPoolSize>1</data.source.maxPoolSize>
<data.source.maxIdleTime>60</data.source.maxIdleTime>
<data.source.acquisitionTimeout>1</data.source.acquisitionTimeout>
<data.source.shareTransactionConnections>true</data.source.shareTransactionConnections>
@Bean(initMethod = "init", destroyMethod = "close")
public PoolingDataSource poolingDataSource() {
	PoolingDataSource poolingDataSource = new PoolingDataSource();
	poolingDataSource.setClassName(dataSourceClassName.getName());
	poolingDataSource.setUniqueName(dataSourceUniqueName);
	poolingDataSource.setMinPoolSize(dataSourceMinPoolSize);
	poolingDataSource.setMaxPoolSize(dataSourceMaxPoolSize);
	poolingDataSource.setMaxIdleTime(dataSourceMaxIdleTime);
	poolingDataSource.setAcquisitionTimeout(dataSourceAcquisitionTimeout);
	poolingDataSource.setShareTransactionConnections(shareTransactionConnections);
	poolingDataSource.setDriverProperties(dataSourceDriverPropertiesMap.get(dataSourceType));
	return poolingDataSource;
}

@Bean
public FlexyPoolConfiguration<PoolingDataSource> configuration() {
	return new FlexyPoolConfiguration.Builder<PoolingDataSource>(
			DataSourceConfiguration.class.getSimpleName(),
			poolingDataSource(),
			BitronixPoolAdapter.FACTORY
	)
	.setMetricsFactory(DropwizardMetrics.UNIFORM_RESERVOIR_FACTORY)
	.build();
}

@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dtfDataSource() {
	FlexyPoolConfiguration<PoolingDataSource> configuration = configuration();
	return new FlexyPoolDataSource<PoolingDataSource>(configuration,
			new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
			new RetryConnectionAcquisitionStrategy.Factory(2)
	);
}

This is how the metrics look like when connecting JConsole to our currently running application.

concurrentConnectionsHistogram
concurrentConnectionsHistogram
concurrentConnectionRequestsHistogram
concurrentConnectionRequestsHistogram
connectionAcquisitionMillis
connectionAcquisitionMillis
connectionLeaseMillis
connectionLeaseMillis
maxPoolSizeHistogram
maxPoolSizeHistogram
overallconnectionAcquisitionMillis
overallconnectionAcquisitionMillis
overgrowPoolSizeHistogram
overgrowPoolSizeHistogram
retryAttemptsHistogram
retryAttemptsHistogram