DiskStatGaugeSet extends CachedMetricSet { public DiskStatGaugeSet() { this(DEFAULT_DATA_TTL, TimeUnit.MILLISECONDS, Clock.defaultClock(), new File[]{ new File("/") }); } DiskStatGaugeSet();  DiskStatGaugeSet(long dataTTL, TimeUnit unit);  DiskStatGaugeSet(long dataTTL, TimeUnit unit, Clock clock, File[] partitions); @Override Map<MetricName, Metric> getMetrics();  }
@SuppressWarnings("unchecked") @Test public void testDiskStatGaugeSet() { ManualClock clock = new ManualClock(); DiskStatGaugeSet diskStatGaugeSet = new DiskStatGaugeSet(10, TimeUnit.MILLISECONDS, clock, new File[]{ root }); Map<MetricName, Metric> metrics = diskStatGaugeSet.getMetrics(); Assert.assertEquals("should have 3 metrics", 3, metrics.keySet().size()); clock.addMillis(20); Gauge<Long> diskTotal = (Gauge<Long>)metrics.get(MetricName.build("disk.partition.total").tagged("partition", "/")); Gauge<Long> diskFree = (Gauge<Long>)metrics.get(MetricName.build("disk.partition.free").tagged("partition", "/")); Gauge<Double> usedRatio = (Gauge<Double>)metrics.get(MetricName.build("disk.partition.used_ratio").tagged("partition", "/")); Assert.assertEquals(10000L, diskTotal.getValue().longValue()); Assert.assertEquals(8000L, diskFree.getValue().longValue()); Assert.assertEquals(0.2d, usedRatio.getValue(), 0.0001d); }