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