@Test public void hasGaugesForGcCountsAndElapsedTimes() throws Exception { assertThat(metrics.getMetrics().keySet()) .containsOnly(PS_OLDGEN_TIME, PS_OLDGEN_COUNT, PS_OLDGEN_TIME_DELTA, PS_OLDGEN_COUNT_DELTA); }
@Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); int index = 0; for (final GarbageCollectorMXBean gc : garbageCollectors) { final String name = WHITESPACE.matcher(gc.getName()).replaceAll("_").toLowerCase(); final int i = index; gauges.put(MetricRegistry.name(name, "count"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionCount(); } }); gauges.put(MetricRegistry.name(name, "time"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionTime(); } }); gauges.put(MetricRegistry.name(name, "count.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionCount(); long result = current - lastGarbageCountCollectors.get(i); lastGarbageCountCollectors.set(i, current); return result; } }); gauges.put(MetricRegistry.name(name, "time.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionTime(); long result = current - lastGarbageTimeCollectors.get(i); lastGarbageTimeCollectors.set(i, current); return result; } }); index = i + 1; } return Collections.unmodifiableMap(gauges); }
GarbageCollectorMetricSet implements MetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); int index = 0; for (final GarbageCollectorMXBean gc : garbageCollectors) { final String name = WHITESPACE.matcher(gc.getName()).replaceAll("_").toLowerCase(); final int i = index; gauges.put(MetricRegistry.name(name, "count"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionCount(); } }); gauges.put(MetricRegistry.name(name, "time"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionTime(); } }); gauges.put(MetricRegistry.name(name, "count.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionCount(); long result = current - lastGarbageCountCollectors.get(i); lastGarbageCountCollectors.set(i, current); return result; } }); gauges.put(MetricRegistry.name(name, "time.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionTime(); long result = current - lastGarbageTimeCollectors.get(i); lastGarbageTimeCollectors.set(i, current); return result; } }); index = i + 1; } return Collections.unmodifiableMap(gauges); } }
GarbageCollectorMetricSet implements MetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); int index = 0; for (final GarbageCollectorMXBean gc : garbageCollectors) { final String name = WHITESPACE.matcher(gc.getName()).replaceAll("_").toLowerCase(); final int i = index; gauges.put(MetricRegistry.name(name, "count"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionCount(); } }); gauges.put(MetricRegistry.name(name, "time"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionTime(); } }); gauges.put(MetricRegistry.name(name, "count.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionCount(); long result = current - lastGarbageCountCollectors.get(i); lastGarbageCountCollectors.set(i, current); return result; } }); gauges.put(MetricRegistry.name(name, "time.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionTime(); long result = current - lastGarbageTimeCollectors.get(i); lastGarbageTimeCollectors.set(i, current); return result; } }); index = i + 1; } return Collections.unmodifiableMap(gauges); } GarbageCollectorMetricSet();  GarbageCollectorMetricSet(Collection<GarbageCollectorMXBean> garbageCollectors); }
GarbageCollectorMetricSet implements MetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); int index = 0; for (final GarbageCollectorMXBean gc : garbageCollectors) { final String name = WHITESPACE.matcher(gc.getName()).replaceAll("_").toLowerCase(); final int i = index; gauges.put(MetricRegistry.name(name, "count"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionCount(); } }); gauges.put(MetricRegistry.name(name, "time"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionTime(); } }); gauges.put(MetricRegistry.name(name, "count.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionCount(); long result = current - lastGarbageCountCollectors.get(i); lastGarbageCountCollectors.set(i, current); return result; } }); gauges.put(MetricRegistry.name(name, "time.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionTime(); long result = current - lastGarbageTimeCollectors.get(i); lastGarbageTimeCollectors.set(i, current); return result; } }); index = i + 1; } return Collections.unmodifiableMap(gauges); } GarbageCollectorMetricSet();  GarbageCollectorMetricSet(Collection<GarbageCollectorMXBean> garbageCollectors); @Override Map<MetricName, Metric> getMetrics(); @Override long lastUpdateTime(); }
GarbageCollectorMetricSet implements MetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); int index = 0; for (final GarbageCollectorMXBean gc : garbageCollectors) { final String name = WHITESPACE.matcher(gc.getName()).replaceAll("_").toLowerCase(); final int i = index; gauges.put(MetricRegistry.name(name, "count"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionCount(); } }); gauges.put(MetricRegistry.name(name, "time"), new PersistentGauge<Long>() { @Override public Long getValue() { return gc.getCollectionTime(); } }); gauges.put(MetricRegistry.name(name, "count.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionCount(); long result = current - lastGarbageCountCollectors.get(i); lastGarbageCountCollectors.set(i, current); return result; } }); gauges.put(MetricRegistry.name(name, "time.delta"), new PersistentGauge<Long>() { @Override public Long getValue() { long current = gc.getCollectionTime(); long result = current - lastGarbageTimeCollectors.get(i); lastGarbageTimeCollectors.set(i, current); return result; } }); index = i + 1; } return Collections.unmodifiableMap(gauges); } GarbageCollectorMetricSet();  GarbageCollectorMetricSet(Collection<GarbageCollectorMXBean> garbageCollectors); @Override Map<MetricName, Metric> getMetrics(); @Override long lastUpdateTime();  }