kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8121d571880d8f6a7d4d85e4e4421b596a3591ad7c386dc1f0db5812eac37467 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-16 16:09 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-16 16:11 +02:00 |
| Parents | 8aa079df356d |
2 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | (JAVA-423) |
| 20 | 20 | - [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504) |
| 21 | 21 | - [improvement] Make schema agreement wait tuneable (JAVA-507) |
| 22 | +- [improvement] Document how to inject the driver metrics into another registry (JAVA-494) | |
| 22 | 23 | |
| 23 | 24 | |
| 24 | 25 | 2.0.6: |
modified driver-core/src/main/java/com/datastax/driver/core/Metrics.java +26 −2
| @@ -18,7 +18,8 @@ | ||
| 18 | 18 | import java.util.HashSet; |
| 19 | 19 | import java.util.Set; |
| 20 | 20 | |
| 21 | -import com.codahale.metrics.Counter; | |
| 21 | +import com.codahale.metrics.Gauge; | |
| 22 | +import com.codahale.metrics.MetricRegistryListener; | |
| 22 | 23 | |
| 23 | 24 | import com.codahale.metrics.*; |
| 24 | 25 | |
| @@ -82,7 +83,7 @@ | ||
| 82 | 83 | /** |
| 83 | 84 | * Returns the registry containing all metrics. |
| 84 | 85 | * <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 | |
| 86 | 87 | * with <a href="http://metrics.codahale.com/manual/core/#reporters">Metrics</a> |
| 87 | 88 | * or a custom written one. |
| 88 | 89 | * <p> |
| @@ -91,6 +92,29 @@ | ||
| 91 | 92 | * <pre> |
| 92 | 93 | * com.codahale.metrics.CsvReporter.forRegistry(metrics.getRegistry()).build(new File("measurements/")).start(1, TimeUnit.SECONDS); |
| 93 | 94 | * </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 | + * @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()}. | |
| 94 | 118 | * |
| 95 | 119 | * @return the registry containing all metrics. |
| 96 | 120 | */ |