Elffuss BraidHub

kikocis/java-driver public

Document how to inject the driver metrics into another registry (JAVA-494).
Changeset8121d571880d8f6a7d4d85e4e4421b596a3591ad7c386dc1f0db5812eac37467
Authorolim7t <omichallat+github@gmail.com> · 2014-10-16 16:09 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-16 16:11 +02:00
Parents8aa079df356d

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -19,6 +19,7 @@
1919 (JAVA-423)
2020 - [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504)
2121 - [improvement] Make schema agreement wait tuneable (JAVA-507)
22+- [improvement] Document how to inject the driver metrics into another registry (JAVA-494)
2223
2324
2425 2.0.6:
modified driver-core/src/main/java/com/datastax/driver/core/Metrics.java +26 −2
@@ -18,7 +18,8 @@
1818 import java.util.HashSet;
1919 import java.util.Set;
2020
21-import com.codahale.metrics.Counter;
21+import com.codahale.metrics.Gauge;
22+import com.codahale.metrics.MetricRegistryListener;
2223
2324 import com.codahale.metrics.*;
2425
@@ -82,7 +83,7 @@
8283 /**
8384 * Returns the registry containing all metrics.
8485 * <p>
85- * The metrics registry allows you to easily use the reporters that ships
86+ * The metrics registry allows you to easily use the reporters that ship
8687 * with <a href="http://metrics.codahale.com/manual/core/#reporters">Metrics</a>
8788 * or a custom written one.
8889 * <p>
@@ -91,6 +92,29 @@
9192 * <pre>
9293 * com.codahale.metrics.CsvReporter.forRegistry(metrics.getRegistry()).build(new File("measurements/")).start(1, TimeUnit.SECONDS);
9394 * </pre>
95+ * <p>
96+ * If you already have a {@code MetricRegistry} in your application and which to
97+ * add the driver's metrics to it, the recommended approach is to use a listener:
98+ * <pre>
99+ * // Your existing registry:
100+ * final com.codahale.metrics.MetricRegistry myRegistry = ...
101+ *
102+ * cluster.getMetrics().getRegistry().addListener(new com.codahale.metrics.MetricRegistryListener() {
103+ * &#64;Override
104+ * public void onGaugeAdded(String name, Gauge<?> gauge) {
105+ * if (myRegistry.getNames().contains(name)) {
106+ * // name is already taken, maybe prefix with a namespace
107+ * ...
108+ * } else {
109+ * myRegistry.register(name, gauge);
110+ * }
111+ * }
112+ *
113+ * ... // Implement other methods in a similar fashion
114+ * });
115+ * </pre>
116+ * Since reporting is handled by your registry, you'll probably also want to disable
117+ * JMX reporting with {@link Cluster.Builder#withoutJMXReporting()}.
94118 *
95119 * @return the registry containing all metrics.
96120 */