@Test public void testMetrics() throws Exception { InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository(); repository.set(new Metric<Double>("a", 0.d, new Date())); repository.set(new Metric<Double>("a", 0.5d, new Date())); RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics( repository); Map<String, Metric<?>> results = new HashMap<String, Metric<?>>(); for (Metric<?> metric : metrics.metrics()) { results.put(metric.getName(), metric); } assertThat(results.containsKey("a.val")).isTrue(); assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d); assertThat(results.containsKey("a.avg")).isTrue(); assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d); assertThat(results.containsKey("a.min")).isTrue(); assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d); assertThat(results.containsKey("a.max")).isTrue(); assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d); assertThat(results.containsKey("a.count")).isTrue(); assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L); assertThat(results.containsKey("a.alpha")).isTrue(); assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d); }
@Test public void testMetrics() throws Exception { InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository(); repository.set(new Metric<Double>("a", 0.d, new Date())); repository.set(new Metric<Double>("a", 0.5d, new Date())); RichGaugeReaderPublicMetrics metrics = new RichGaugeReaderPublicMetrics( repository); Map<String, Metric<?>> results = new HashMap<String, Metric<?>>(); for (Metric<?> metric : metrics.metrics()) { results.put(metric.getName(), metric); } assertTrue(results.containsKey("a.val")); assertThat(results.get("a.val").getValue().doubleValue(), equalTo(0.5d)); assertTrue(results.containsKey("a.avg")); assertThat(results.get("a.avg").getValue().doubleValue(), equalTo(0.25d)); assertTrue(results.containsKey("a.min")); assertThat(results.get("a.min").getValue().doubleValue(), equalTo(0.0d)); assertTrue(results.containsKey("a.max")); assertThat(results.get("a.max").getValue().doubleValue(), equalTo(0.5d)); assertTrue(results.containsKey("a.count")); assertThat(results.get("a.count").getValue().longValue(), equalTo(2L)); assertTrue(results.containsKey("a.alpha")); assertThat(results.get("a.alpha").getValue().doubleValue(), equalTo(-1.d)); }
@Bean @Primary public InMemoryRichGaugeRepository inMemoryRichGaugeRepository() { return new InMemoryRichGaugeRepository(); }
/** * This repository will be added automatically to the ones getting data from the * GaugeService. Take a look at the MetricRepositoryAutoConfiguration for more information: * The 'primaryMetricWriter' is collecting references to all MetricWriter implementations, * and this is an implementation of MetricWriter. */ @Bean @ConditionalOnMissingBean(RichGaugeRepository.class) public RichGaugeRepository richGaugeRepository() { return new InMemoryRichGaugeRepository(); }