Skip to content
Vlad Mihalcea edited this page Jan 22, 2018 · 19 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.

connectionAcquireMillis

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 IncrementPoolOnTimeoutConnectionAcquiringStrategy is being used.

overallConnectionAcquireMillis

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

overflowPoolSizeHistogram

A histogram of the pool size overflowing. The pool size might overflow if the IncrementPoolOnTimeoutConnectionAcquiringStrategy is being used.

retryAttemptsHistogram

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

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 Configuration<PoolingDataSource> configuration() {
	return new Configuration.Builder<PoolingDataSource>(
			DataSourceConfiguration.class.getSimpleName(),
			poolingDataSource(),
			BitronixPoolAdapter.FACTORY
	)
	.setMetricsFactory(DropwizardMetrics.UNIFORM_RESERVOIR_FACTORY)
	.build();
}

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

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

concurrentConnectionsHistogram
concurrentConnectionsHistogram
concurrentConnectionRequestsHistogram
concurrentConnectionRequestsHistogram
connectionAcquireMillis
connectionAcquireMillis
connectionLeaseMillis
connectionLeaseMillis
maxPoolSizeHistogram
maxPoolSizeHistogram
overallConnectionAcquireMillis
overallConnectionAcquireMillis
overflowPoolSizeHistogram
overflowPoolSizeHistogram
retryAttemptsHistogram
retryAttemptsHistogram