@Test public void closesConnectionIfGraphiteIsUnavailable() throws Exception { doThrow(new UnknownHostException("UNKNOWN-HOST")).when(graphite).connect(); reporter.report(map("gauge", gauge(1)), emptyMap(), emptyMap(), emptyMap(), emptyMap()); InOrder inOrder = inOrder(graphite); inOrder.verify(graphite).connect(); inOrder.verify(graphite).close(); }
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; try { initConnection(); gauges.forEach((name, gauge) -> doReport(name, gauge, timestamp, this::reportGauge)); counters.forEach((name, counter) -> doReport(name, counter, timestamp, this::reportCounter)); histograms.forEach((name, histogram) -> doReport(name, histogram, timestamp, this::reportHistogram)); meters.forEach((name, meter) -> doReport(name, meter, timestamp, this::reportMetered)); timers.forEach((name, timer) -> doReport(name, timer, timestamp, this::reportTimer)); graphite.flush(); } catch (Exception e) { LOGGER.error("Error reporting metrics" + e.getMessage(), e); } finally { try { graphite.close(); } catch (IOException e1) { LOGGER.warn("Error closing Graphite", e1); } } }
GraphiteReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; try { initConnection(); gauges.forEach((name, gauge) -> doReport(name, gauge, timestamp, this::reportGauge)); counters.forEach((name, counter) -> doReport(name, counter, timestamp, this::reportCounter)); histograms.forEach((name, histogram) -> doReport(name, histogram, timestamp, this::reportHistogram)); meters.forEach((name, meter) -> doReport(name, meter, timestamp, this::reportMetered)); timers.forEach((name, timer) -> doReport(name, timer, timestamp, this::reportTimer)); graphite.flush(); } catch (Exception e) { LOGGER.error("Error reporting metrics" + e.getMessage(), e); } finally { try { graphite.close(); } catch (IOException e1) { LOGGER.warn("Error closing Graphite", e1); } } } }
GraphiteReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; try { initConnection(); gauges.forEach((name, gauge) -> doReport(name, gauge, timestamp, this::reportGauge)); counters.forEach((name, counter) -> doReport(name, counter, timestamp, this::reportCounter)); histograms.forEach((name, histogram) -> doReport(name, histogram, timestamp, this::reportHistogram)); meters.forEach((name, meter) -> doReport(name, meter, timestamp, this::reportMetered)); timers.forEach((name, timer) -> doReport(name, timer, timestamp, this::reportTimer)); graphite.flush(); } catch (Exception e) { LOGGER.error("Error reporting metrics" + e.getMessage(), e); } finally { try { graphite.close(); } catch (IOException e1) { LOGGER.warn("Error closing Graphite", e1); } } } private  GraphiteReporter(MetricRegistry registry,
                             GraphiteSender graphite,
                             Clock clock,
                             String prefix,
                             TimeUnit rateUnit,
                             TimeUnit durationUnit,
                             MetricFilter filter); }
GraphiteReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; try { initConnection(); gauges.forEach((name, gauge) -> doReport(name, gauge, timestamp, this::reportGauge)); counters.forEach((name, counter) -> doReport(name, counter, timestamp, this::reportCounter)); histograms.forEach((name, histogram) -> doReport(name, histogram, timestamp, this::reportHistogram)); meters.forEach((name, meter) -> doReport(name, meter, timestamp, this::reportMetered)); timers.forEach((name, timer) -> doReport(name, timer, timestamp, this::reportTimer)); graphite.flush(); } catch (Exception e) { LOGGER.error("Error reporting metrics" + e.getMessage(), e); } finally { try { graphite.close(); } catch (IOException e1) { LOGGER.warn("Error closing Graphite", e1); } } } private  GraphiteReporter(MetricRegistry registry,
                             GraphiteSender graphite,
                             Clock clock,
                             String prefix,
                             TimeUnit rateUnit,
                             TimeUnit durationUnit,
                             MetricFilter filter); static Builder forRegistry(MetricRegistry registry); @Override void report(SortedMap<String, Gauge> gauges,
                       SortedMap<String, Counter> counters,
                       SortedMap<String, Histogram> histograms,
                       SortedMap<String, Meter> meters,
                       SortedMap<String, Timer> timers); @Override void stop(); }
GraphiteReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime() / 1000; try { initConnection(); gauges.forEach((name, gauge) -> doReport(name, gauge, timestamp, this::reportGauge)); counters.forEach((name, counter) -> doReport(name, counter, timestamp, this::reportCounter)); histograms.forEach((name, histogram) -> doReport(name, histogram, timestamp, this::reportHistogram)); meters.forEach((name, meter) -> doReport(name, meter, timestamp, this::reportMetered)); timers.forEach((name, timer) -> doReport(name, timer, timestamp, this::reportTimer)); graphite.flush(); } catch (Exception e) { LOGGER.error("Error reporting metrics" + e.getMessage(), e); } finally { try { graphite.close(); } catch (IOException e1) { LOGGER.warn("Error closing Graphite", e1); } } } private  GraphiteReporter(MetricRegistry registry,
                             GraphiteSender graphite,
                             Clock clock,
                             String prefix,
                             TimeUnit rateUnit,
                             TimeUnit durationUnit,
                             MetricFilter filter); static Builder forRegistry(MetricRegistry registry); @Override void report(SortedMap<String, Gauge> gauges,
                       SortedMap<String, Counter> counters,
                       SortedMap<String, Histogram> histograms,
                       SortedMap<String, Meter> meters,
                       SortedMap<String, Timer> timers); @Override void stop();  }