JvmAttributeGaugeSet implements MetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("name"), new PersistentGauge<String>() { @Override public String getValue() { return runtime.getName(); } }); gauges.put(MetricName.build("vendor"), new PersistentGauge<String>() { @Override public String getValue() { return String.format(Locale.US, "%s %s %s (%s)", runtime.getVmVendor(), runtime.getVmName(), runtime.getVmVersion(), runtime.getSpecVersion()); } }); gauges.put(MetricName.build("uptime"), new PersistentGauge<Long>() { @Override public Long getValue() { return runtime.getUptime(); } }); return Collections.unmodifiableMap(gauges); } JvmAttributeGaugeSet();  JvmAttributeGaugeSet(RuntimeMXBean runtime); @Override Map<MetricName, Metric> getMetrics(); @Override long lastUpdateTime();  }
@Test public void hasASetOfGauges() throws Exception { assertThat(gauges.getMetrics().keySet()) .containsOnly( MetricName.build("vendor"), MetricName.build("name"), MetricName.build("uptime")); }
@Test public void hasAGaugeForTheJVMName() throws Exception { final Gauge gauge = (Gauge) gauges.getMetrics().get(MetricName.build("name")); assertThat(gauge.getValue()) .isEqualTo("9928@example.com"); }
@Test public void hasAGaugeForTheJVMVendor() throws Exception { final Gauge gauge = (Gauge) gauges.getMetrics().get(MetricName.build("vendor")); assertThat(gauge.getValue()) .isEqualTo("Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 23.7-b01 (1.7)"); }
@Test public void hasAGaugeForTheJVMUptime() throws Exception { final Gauge gauge = (Gauge) gauges.getMetrics().get(MetricName.build("uptime")); assertThat(gauge.getValue()) .isEqualTo(100L); }
@Test public void autoDiscoversTheRuntimeBean() throws Exception { final Gauge gauge = (Gauge) new JvmAttributeGaugeSet().getMetrics().get(MetricName.build("uptime")); assertThat((Long) gauge.getValue()) .isPositive(); }