HikariCP icon indicating copy to clipboard operation
HikariCP copied to clipboard

Configurable Metrics prefix

Open EdgeCaseBerg opened this issue 8 years ago • 2 comments

Hi! I saw issue 615 and figure'd it would be something pretty easy to do in a morning. All the tests still pass, and I've written the update so that it wouldn't break anyone's metrics that are relying on the hardcoded "pool" being added to the pool name as the base of the metrics name.

EdgeCaseBerg avatar Apr 30 '16 16:04 EdgeCaseBerg

Coverage Status

Coverage decreased (-0.3%) to 75.125% when pulling 11055d1281a7fa8acc3bcd9b15ad9031d5d8291d on EdgeCaseBerg:Metrics-Prefix into 39aa95eef464fc3f16a7953dbc92f0f6b91e666c on brettwooldridge:dev.

coveralls avatar Apr 30 '16 17:04 coveralls

Seems to look good.

With Metrics 4.x in the future HikariConfig would also need an API to provide metric tags because in Metrics 4.x (currently their master branch) their metrics name will be represented by an instance of MetricName (https://github.com/dropwizard/metrics/blob/master/metrics-core/src/main/java/io/dropwizard/metrics/MetricName.java) which is immutable. This class supports attaching custom tags to a metric so that metric names do not have to be relatively long just because tags are encoded directly in the metric name like I described in my issue.

So with Metrics 4.x you could do:

Map<String, String> tags = ....;
tags.put("customer", "example.com");
tags.put("host", "cluster-host-01");
tags.put("jvm-instance", "1");

// with "metricPrefix" just being, e.g. "connection-pool" or "hikaricp".
registry.register(new MetricName(metricPrefix + ".activeConnections", tags), someGauge);

jnehlmeier avatar Apr 30 '16 18:04 jnehlmeier