TcpGaugeSet extends CachedMetricSet { public TcpGaugeSet() { this(DEFAULT_FILE_PATH, DEFAULT_DATA_TTL, TimeUnit.MILLISECONDS, Clock.defaultClock()); } TcpGaugeSet();  TcpGaugeSet(String filePath);  TcpGaugeSet(long dataTTL, TimeUnit unit);  TcpGaugeSet(String filePath, long dataTTL, TimeUnit unit, Clock clock); @Override Map<MetricName, Metric> getMetrics(); void setFilePath(String filePath);  }
@SuppressWarnings("unchecked") @Test public void testTcpGaugeSet() { ManualClock clock = new ManualClock(); TcpGaugeSet tcpGaugeSet = new TcpGaugeSet( "src/test/resources/proc_net_snmp", 10, TimeUnit.MILLISECONDS, clock); Map<MetricName, Metric> metrics = tcpGaugeSet.getMetrics(); Assert.assertEquals(11, metrics.keySet().size()); clock.addMillis(20); final String[] METRICS = { "tcp.active_opens", "tcp.passive_opens", "tcp.attempt_fails", "tcp.estab_resets", "tcp.in_segs", "tcp.out_segs", "tcp.retran_segs", "tcp.in_errs", "tcp.out_rsts", }; Gauge<Double> tcpActiveOpens = (Gauge<Double>)metrics.get(MetricName.build("tcp.active_opens")); Gauge<Double> tcpPassiveOpens = (Gauge<Double>)metrics.get(MetricName.build("tcp.passive_opens")); Gauge<Double> attemptFails = (Gauge<Double>)metrics.get(MetricName.build("tcp.attempt_fails")); Gauge<Long> currentEstab = (Gauge<Long>)metrics.get(MetricName.build("tcp.current_estab")); Gauge<Double> outSegs = (Gauge<Double>)metrics.get(MetricName.build("tcp.out_segs")); Gauge<Double> retranSeg = (Gauge<Double>)metrics.get(MetricName.build("tcp.retran_segs")); Gauge<Double> retranRatio = (Gauge<Double>)metrics.get(MetricName.build("tcp.retran_ratio")); Assert.assertEquals(0.0d, tcpActiveOpens.getValue(), 0.0001d); Assert.assertEquals(0.0d, tcpPassiveOpens.getValue(), 0.0001d); Assert.assertEquals(0.0d, attemptFails.getValue(), 0.0001d); clock.addMillis(200); tcpGaugeSet.setFilePath("src/test/resources/proc_net_snmp_2"); Assert.assertEquals(10000.0d, tcpActiveOpens.getValue(), 0.0001d); Assert.assertEquals(1000.0d, tcpPassiveOpens.getValue(), 0.0001d); Assert.assertEquals(0.0d, attemptFails.getValue(), 0.0001d); clock.addMillis(200); tcpGaugeSet.setFilePath("src/test/resources/proc_net_snmp_3"); Assert.assertEquals(0.0d, tcpActiveOpens.getValue(), 0.0001d); Assert.assertEquals(0.0d, tcpPassiveOpens.getValue(), 0.0001d); Assert.assertEquals(15000.0d, attemptFails.getValue(), 0.0001d); Assert.assertEquals(10L, currentEstab.getValue().longValue()); Assert.assertEquals(2500.0d, outSegs.getValue(), 0.001d); Assert.assertEquals(1000.0d, retranSeg.getValue(), 0.001d); Assert.assertEquals(0.4d, retranRatio.getValue(), 0.001d); }