GraphiteMetricsService extends AbstractIdleService { @Override protected void startUp() throws Exception { if (reporter != null) { LOGGER.info("already started {}, service: {}, prefix: {}, interval: {}", serviceName(), service, prefix, interval); return; } LOGGER.info("starting {}, service: {}, prefix: {}, interval: {}", serviceName(), service, prefix, interval); Graphite graphite = new Graphite(service.getHost(), service.getPort()); reporter = GraphiteReporter.forRegistry(metricRegistry) .prefixedWith(prefix) .convertRatesTo(SECONDS) .convertDurationsTo(MILLISECONDS) .filter(ALL) .build(graphite); reporter.start(interval, SECONDS); LOGGER.info("started {}, service: {}, prefix: {}, interval: {}", serviceName(), service, prefix, interval); } @Inject  GraphiteMetricsService(@Named("metrics.graphite.service") final URI service,
                                  @Named("metrics.graphite.service.prefix") final String prefix,
                                  @Named("metrics.graphite.interval.seconds") final int interval,
                                  final MetricRegistry metricRegistry);   }
@Test public void startUp() throws Exception { graphiteMetricsService.startUp(); }
@Test public void startUpAlreadyStarted() throws Exception { graphiteMetricsService.startUp(); graphiteMetricsService.startUp(); }