@Test public void testSystemLoadMetrics() { SystemLoadGaugeSet systemLoadGaugeSet = new SystemLoadGaugeSet( 10, TimeUnit.MILLISECONDS, "src/test/resources/proc_loadavg"); Map<MetricName, Metric> metrics = systemLoadGaugeSet.getMetrics(); Assert.assertEquals(3, metrics.keySet().size()); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } Gauge _1min = (Gauge)metrics.get(MetricName.build("load.1min")); Gauge _5min = (Gauge)metrics.get(MetricName.build("load.5min")); Gauge _15min = (Gauge)metrics.get(MetricName.build("load.15min")); Assert.assertEquals(0.08f, _1min.getValue()); Assert.assertEquals(0.06f, _5min.getValue()); Assert.assertEquals(0.05f, _15min.getValue()); }
@Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("load.1min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.ONE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.5min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIVE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.15min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIFTEEN_MIN.ordinal()]; } }); return gauges; }
SystemLoadGaugeSet extends CachedMetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("load.1min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.ONE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.5min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIVE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.15min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIFTEEN_MIN.ordinal()]; } }); return gauges; } }
SystemLoadGaugeSet extends CachedMetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("load.1min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.ONE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.5min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIVE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.15min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIFTEEN_MIN.ordinal()]; } }); return gauges; } SystemLoadGaugeSet();  SystemLoadGaugeSet(long dataTTL, TimeUnit unit);  SystemLoadGaugeSet(long dataTTL, TimeUnit unit, String filePath); }
SystemLoadGaugeSet extends CachedMetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("load.1min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.ONE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.5min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIVE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.15min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIFTEEN_MIN.ordinal()]; } }); return gauges; } SystemLoadGaugeSet();  SystemLoadGaugeSet(long dataTTL, TimeUnit unit);  SystemLoadGaugeSet(long dataTTL, TimeUnit unit, String filePath); @Override Map<MetricName, Metric> getMetrics(); }
SystemLoadGaugeSet extends CachedMetricSet { @Override public Map<MetricName, Metric> getMetrics() { final Map<MetricName, Metric> gauges = new HashMap<MetricName, Metric>(); gauges.put(MetricName.build("load.1min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.ONE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.5min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIVE_MIN.ordinal()]; } }); gauges.put(MetricName.build("load.15min"), new PersistentGauge<Float>() { @Override public Float getValue() { refreshIfNecessary(); return loadAvg[LoadAvg.FIFTEEN_MIN.ordinal()]; } }); return gauges; } SystemLoadGaugeSet();  SystemLoadGaugeSet(long dataTTL, TimeUnit unit);  SystemLoadGaugeSet(long dataTTL, TimeUnit unit, String filePath); @Override Map<MetricName, Metric> getMetrics();  }