com.codahale.metrics.graphite.GraphiteReporter Java Examples

The following examples show how to use com.codahale.metrics.graphite.GraphiteReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsManager.java    From emissary with Apache License 2.0 6 votes vote down vote up
protected void initGraphiteReporter() {
    if (!this.conf.findBooleanEntry("GRAPHITE_METRICS_ENABLED", false)) {
        logger.debug("Graphite Metrics are disabled");
        return;
    }

    logger.debug("Graphite Metrics are enabled");

    final String prefix = this.conf.findStringEntry("GRAPHITE_METRICS_PREFIX", "emissary");
    final String host = this.conf.findStringEntry("GRAPHITE_METRICS_HOST", "localhost");
    final int port = this.conf.findIntEntry("GRAPHITE_METRICS_PORT", 2003);
    final int interval = this.conf.findIntEntry("GRAPHITE_METRICS_INTERVAL", -1);

    final TimeUnit intervalUnit = TimeUnit.valueOf(this.conf.findStringEntry("GRAPHITE_METRICS_INTERVAL_UNIT", TimeUnit.MINUTES.name()));
    final TimeUnit rateUnit = TimeUnit.valueOf(this.conf.findStringEntry("GRAPHITE_RATE_UNIT", TimeUnit.SECONDS.name()));
    final TimeUnit durationUnit = TimeUnit.valueOf(this.conf.findStringEntry("GRAPHITE_DURATION_UNIT", TimeUnit.MILLISECONDS.name()));

    final Graphite graphite = new Graphite(new InetSocketAddress(host, port));
    final GraphiteReporter graphiteReporter =
            GraphiteReporter.forRegistry(this.metrics).prefixedWith(prefix).convertRatesTo(rateUnit).convertDurationsTo(durationUnit)
                    .filter(MetricFilter.ALL).build(graphite);

    if (interval > 0) {
        graphiteReporter.start(interval, intervalUnit);
    }
}
 
Example #2
Source File: GraphiteReporterStarter.java    From fluo with Apache License 2.0 6 votes vote down vote up
@Override
public List<AutoCloseable> start(Params params) {
  SimpleConfiguration config =
      new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("graphite");

  if (!config.getBoolean("enable", false)) {
    return Collections.emptyList();
  }

  String host = config.getString("host");
  String prefix = config.getString("prefix", "");
  int port = config.getInt("port", 8080);
  TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase());
  TimeUnit durationUnit =
      TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase());

  Graphite graphite = new Graphite(host, port);
  GraphiteReporter reporter =
      GraphiteReporter.forRegistry(params.getMetricRegistry()).convertDurationsTo(durationUnit)
          .convertRatesTo(rateUnit).prefixedWith(prefix).build(graphite);
  reporter.start(config.getInt("frequency", 60), TimeUnit.SECONDS);

  log.info("Reporting metrics to graphite server {}:{}", host, port);

  return Collections.singletonList((AutoCloseable) reporter);
}
 
Example #3
Source File: MetricsFactoryImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public MetricsFactoryImpl(MetricsFig metricsFig) {
    registry = new MetricRegistry();
    String metricsHost = metricsFig.getHost();
    if (!metricsHost.equals("false")) {
        Graphite graphite = new Graphite(new InetSocketAddress(metricsHost, 2003));
        graphiteReporter = GraphiteReporter.forRegistry(registry).prefixedWith("usergrid-metrics")
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL)
            .build(graphite);
        graphiteReporter.start(30, TimeUnit.SECONDS);
    } else {
        logger.warn("MetricsService:Logger not started.");
    }

    jmxReporter = JmxReporter.forRegistry(registry).build();
    jmxReporter.start();
}
 
Example #4
Source File: MetricsBundleTest.java    From minnal with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandlePostMount() {
	bundle.init(container, configuration);
	
	MetricRegistry metricRegistry = mock(MetricRegistry.class);
	JmxReporter jmxReporter = mock(JmxReporter.class);
	GraphiteReporter graphiteReporter = mock(GraphiteReporter.class);
	
	doReturn(metricRegistry).when(bundle).createMetricRegistry();
	doReturn(jmxReporter).when(bundle).createJmxReporter(metricRegistry);
	doReturn(graphiteReporter).when(bundle).createGraphiteReporter(eq(configuration.getGraphiteReporterConfiguration()), eq(metricRegistry));
	
	bundle.postMount(application);
	verify(jmxReporter).start();
	verify(graphiteReporter).start(configuration.getGraphiteReporterConfiguration().getPollPeriodInSecs(), TimeUnit.SECONDS);
}
 
Example #5
Source File: MetricsGraphiteReporterLoader.java    From chassis with Apache License 2.0 6 votes vote down vote up
private void createReporter(String metricFilter, String environment, String serviceName, String version, MetricRegistry metricRegistry) {
    // optionally filter metrics to send to graphite server
    MetricFilter filter = MetricFilter.FILTER_NONE;

    if (!(Strings.isNullOrEmpty(metricFilter) || "*".equals(metricFilter))) {
        filter = new MetricFilter(metricFilter);
    }

    this.filter = filter;

    this.graphiteReporter = GraphiteReporter
            .forRegistry(metricRegistry)
            .prefixedWith(getPreFix(environment, serviceName, version))
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(filter)
            .build(graphite);

}
 
Example #6
Source File: MetricsConfiguration.java    From expper with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #7
Source File: MetricsConfiguration.java    From ServiceCutter with Apache License 2.0 6 votes vote down vote up
@PostConstruct
private void init() {
    Boolean graphiteEnabled = propertyResolver.getProperty(PROP_GRAPHITE_ENABLED, Boolean.class, false);
    if (graphiteEnabled) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = propertyResolver.getRequiredProperty(PROP_HOST);
        Integer graphitePort = propertyResolver.getRequiredProperty(PROP_PORT, Integer.class);
        String graphitePrefix = propertyResolver.getProperty(PROP_GRAPHITE_PREFIX, String.class, "");

        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .prefixedWith(graphitePrefix)
                .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #8
Source File: MetricsConfiguration.java    From angularjs-springboot-bookstore with MIT License 6 votes vote down vote up
@PostConstruct
private void init() {
    Boolean graphiteEnabled = propertyResolver.getProperty(PROP_GRAPHITE_ENABLED, Boolean.class, false);
    if (graphiteEnabled) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = propertyResolver.getRequiredProperty(PROP_HOST);
        Integer graphitePort = propertyResolver.getRequiredProperty(PROP_PORT, Integer.class);
        String graphitePrefix = propertyResolver.getProperty(PROP_GRAPHITE_PREFIX, String.class, "");

        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .prefixedWith(graphitePrefix)
                .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #9
Source File: MetricsReporters.java    From StubbornJava with MIT License 6 votes vote down vote up
public static void startReporters(MetricRegistry registry) {
    // Graphite reporter to Grafana Cloud
    OkHttpClient client = new OkHttpClient.Builder()
        //.addNetworkInterceptor(HttpClient.getLoggingInterceptor())
        .build();

    if (!Configs.properties().hasPath("metrics.graphite.host")
        || !Configs.properties().hasPath("metrics.grafana.api_key")) {
        log.info("Missing metrics reporter key or host skipping");
        return;
    }

    String graphiteHost = Configs.properties().getString("metrics.graphite.host");
    String grafanaApiKey = Configs.properties().getString("metrics.grafana.api_key");
    final GraphiteHttpSender graphite = new GraphiteHttpSender(client, graphiteHost, grafanaApiKey);
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
                                                      .prefixedWith(Metrics.metricPrefix("stubbornjava"))
                                                      .convertRatesTo(TimeUnit.MINUTES)
                                                      .convertDurationsTo(TimeUnit.MILLISECONDS)
                                                      .filter(MetricFilter.ALL)
                                                      .build(graphite);
    reporter.start(10, TimeUnit.SECONDS);
}
 
Example #10
Source File: MetricsConfiguration.java    From OpenIoE with Apache License 2.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #11
Source File: MetricsConfiguration.java    From gpmr with Apache License 2.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #12
Source File: DropwizardHelper.java    From okapi with Apache License 2.0 6 votes vote down vote up
/**
 * Configure Dropwizard helper.
 * @param graphiteHost graphite server host
 * @param port  graphits server port
 * @param tu time unit
 * @param period reporting period
 * @param vopt Vert.x options
 * @param hostName logical hostname for this node (reporting)
 */
public static void config(String graphiteHost, int port, TimeUnit tu,
        int period, VertxOptions vopt, String hostName) {
  final String registryName = "okapi";
  MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);

  DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions();
  metricsOpt.setEnabled(true).setRegistryName(registryName);
  vopt.setMetricsOptions(metricsOpt);
  Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, port));
  final String prefix = "folio.okapi." + hostName;
  GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
          .prefixedWith(prefix)
          .build(graphite);
  reporter.start(period, tu);

  logger.info("Metrics remote {}:{} this {}", graphiteHost, port, prefix);
}
 
Example #13
Source File: MetricsConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #14
Source File: _MetricsConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #15
Source File: MetricsConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #16
Source File: MetricsConfiguration.java    From klask-io with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #17
Source File: MetricsConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
private void init() {
    if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
        Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
        String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .prefixedWith(graphitePrefix)
            .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }
}
 
Example #18
Source File: MetricsReporters.java    From StubbornJava with MIT License 6 votes vote down vote up
public static void startReporters(MetricRegistry registry) {
    // Graphite reporter to Grafana Cloud
    OkHttpClient client = new OkHttpClient.Builder()
        //.addNetworkInterceptor(HttpClient.getLoggingInterceptor())
        .build();

    if (!Configs.properties().hasPath("metrics.graphite.host")
        || !Configs.properties().hasPath("metrics.grafana.api_key")) {
        log.info("Missing metrics reporter key or host skipping");
        return;
    }

    String graphiteHost = Configs.properties().getString("metrics.graphite.host");
    String grafanaApiKey = Configs.properties().getString("metrics.grafana.api_key");
    final GraphiteHttpSender graphite = new GraphiteHttpSender(client, graphiteHost, grafanaApiKey);
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
                                                      .prefixedWith(Metrics.metricPrefix("stubbornjava"))
                                                      .convertRatesTo(TimeUnit.MINUTES)
                                                      .convertDurationsTo(TimeUnit.MILLISECONDS)
                                                      .filter(MetricFilter.ALL)
                                                      .build(graphite);
    reporter.start(10, TimeUnit.SECONDS);
}
 
Example #19
Source File: JbootGraphiteReporter.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void report(MetricRegistry metricRegistry) {

    JbootMetricGraphiteReporterConfig config = Jboot.config(JbootMetricGraphiteReporterConfig.class);

    if (StrUtil.isBlank(config.getHost())) {
        throw new NullPointerException("graphite reporter host must not be null, please config jboot.metrics.reporter.graphite.host in you properties.");
    }
    if (config.getPort() == null) {
        throw new NullPointerException("graphite reporter port must not be null, please config jboot.metrics.reporter.graphite.port in you properties.");
    }
    if (config.getPrefixedWith() == null) {
        throw new NullPointerException("graphite reporter prefixedWith must not be null, please config jboot.metrics.reporter.graphite.prefixedWith in you properties.");
    }

    Graphite graphite = new Graphite(new InetSocketAddress(config.getHost(), config.getPort()));

    GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry)
            .prefixedWith(config.getPrefixedWith())
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);

    reporter.start(1, TimeUnit.MINUTES);
}
 
Example #20
Source File: GraphiteMetricsReporter.java    From user-registration-V2 with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void init() {
	if (graphiteEnabled) {
		log.info("Initializing Metrics Graphite reporting");
		Graphite graphite = new Graphite(new InetSocketAddress(
				graphiteHost, graphitePort));
		GraphiteReporter graphiteReporter = GraphiteReporter
				.forRegistry(metricRegistry)
				.convertRatesTo(TimeUnit.SECONDS)
				.convertDurationsTo(TimeUnit.MILLISECONDS).build(graphite);
		graphiteReporter.start(1, TimeUnit.MINUTES);
	}
}
 
Example #21
Source File: GraphiteMetrics.java    From replicator with Apache License 2.0 5 votes vote down vote up
@Override
protected ScheduledReporter getReporter(Map<String, Object> configuration, MetricRegistry registry) {
    Object namespace = configuration.get(Configuration.GRAPHITE_NAMESPACE);
    Object hostname = configuration.get(Configuration.GRAPHITE_HOSTNAME);
    Object port = configuration.get(Configuration.GRAPHITE_PORT);

    Objects.requireNonNull(namespace, String.format("Configuration required: %s", Configuration.GRAPHITE_NAMESPACE));
    Objects.requireNonNull(hostname, String.format("Configuration required: %s", Configuration.GRAPHITE_HOSTNAME));
    Objects.requireNonNull(port, String.format("Configuration required: %s", Configuration.GRAPHITE_PORT));

    registry.register(MetricRegistry.name("jvm", "gc"), new GarbageCollectorMetricSet());
    registry.register(MetricRegistry.name("jvm", "threads"), new ThreadStatesGaugeSet());
    registry.register(MetricRegistry.name("jvm", "classes"), new ClassLoadingGaugeSet());
    registry.register(MetricRegistry.name("jvm", "fd"), new FileDescriptorRatioGauge());
    registry.register(MetricRegistry.name("jvm", "memory"), new MemoryUsageGaugeSet());

    ScheduledReporter reporter = GraphiteReporter
            .forRegistry(registry)
            .prefixedWith(namespace.toString())
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.SECONDS)
            .build(new Graphite(new InetSocketAddress(hostname.toString(), Integer.parseInt(port.toString()))));

    reporter.start(1L, TimeUnit.MINUTES);

    return reporter;
}
 
Example #22
Source File: GraphiteScheduledReporterFactory.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Override
public ScheduledReporter newInstance(String qualifiedReplicaName) {
  InetSocketAddress address = new InetSocketAddressFactory().newInstance(graphiteHost);
  Graphite graphite = new Graphite(address);
  String prefix = DotJoiner.join(graphitePrefix, qualifiedReplicaName);
  return GraphiteReporter.forRegistry(runningMetricRegistry).prefixedWith(prefix).build(graphite);
}
 
Example #23
Source File: GraphiteMetricsReporter.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void start(MetricsContext metricsContext) throws MetricsReporterException {
  MetricRegistry registry = (MetricRegistry) metricsContext.getProperty(
      DefaultMetricsService.METRICS_REGISTRY);
  reporter = GraphiteReporter.forRegistry(registry)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .filter(MetricFilter.ALL)
      .build(graphite);
  reporter.start(reportingFrequency, TimeUnit.MINUTES);
}
 
Example #24
Source File: Main.java    From RestExpress-Examples with Apache License 2.0 5 votes vote down vote up
private static void configureMetrics(Configuration config, RestExpress server)
  {
MetricsConfig mc = config.getMetricsConfig();

   if (mc.isEnabled())
{
   	MetricRegistry registry = new MetricRegistry();
	new MetricsPlugin(registry)
		.register(server);

	if (mc.isGraphiteEnabled())
	{
		final Graphite graphite = new Graphite(new InetSocketAddress(mc.getGraphiteHost(), mc.getGraphitePort()));
		final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
			.prefixedWith(mc.getPrefix())
			.convertRatesTo(TimeUnit.SECONDS)
			.convertDurationsTo(TimeUnit.MILLISECONDS)
			.filter(MetricFilter.ALL)
			.build(graphite);
		reporter.start(mc.getPublishSeconds(), TimeUnit.SECONDS);
	}
	else
	{
		LOG.warn("*** Graphite Metrics Publishing is Disabled ***");
	}
}
else
{
	LOG.warn("*** Metrics Generation is Disabled ***");
}
  }
 
Example #25
Source File: DefaultGraphiteMetricsReporter.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds reporter with the given graphite config.
 *
 * @param graphiteCfg graphite config
 * @return reporter
 */
private GraphiteReporter buildReporter(Graphite graphiteCfg) {
    MetricRegistry metricRegistry = metricsService.getMetricRegistry();
    return GraphiteReporter.forRegistry(filter(metricRegistry))
            .prefixedWith(metricNamePrefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(graphiteCfg);
}
 
Example #26
Source File: MetricsBundle.java    From minnal with Apache License 2.0 5 votes vote down vote up
protected GraphiteReporter createGraphiteReporter(GraphiteReporterConfiguration config, MetricRegistry registry) {
	Graphite graphite = new Graphite(new InetSocketAddress(config.getGraphiteHost(), config.getGraphitePort()));
	return GraphiteReporter.forRegistry(registry).prefixedWith(config.getPrefix())
           .convertRatesTo(TimeUnit.SECONDS)
           .convertDurationsTo(TimeUnit.MILLISECONDS)
           .filter(MetricFilter.ALL)
           .build(graphite);
}
 
Example #27
Source File: MetricsConfiguration.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "metrics.graphite", name = "enabled", havingValue = "true")
ScheduledReporter graphiteReporter(GraphiteProperties graphiteProperties, MetricRegistry metricRegistry) {
    final Graphite graphite = new Graphite(graphiteProperties.getHost(), graphiteProperties.getPort());
    final ScheduledReporter reporter = GraphiteReporter.forRegistry(metricRegistry)
            .prefixedWith(graphiteProperties.getPrefix())
            .build(graphite);
    reporter.start(graphiteProperties.getInterval(), TimeUnit.SECONDS);

    return reporter;
}
 
Example #28
Source File: MetricsConfiguration.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public void configureReporters(MetricRegistry registry) {
  if (graphiteEndpoint != null) {
    log.info("Starting Graphite reporter");
    reporter = registerReporter(GraphiteReporter
        .forRegistry(registry)
        .prefixedWith(MetricRegistry.name("road", "truck-park", "host", getHostname(), "road", roadName))
        .convertRatesTo(SECONDS)
        .convertDurationsTo(MILLISECONDS)
        .build(new Graphite(graphiteEndpoint)));
  }
}
 
Example #29
Source File: BaragonAgentGraphiteReporterManaged.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws Exception {
  if (!graphiteConfiguration.isEnabled()) {
    LOG.info("Not reporting data points to graphite.");
    return;
  }

  LOG.info("Reporting data points to graphite server {}:{} every {} seconds with prefix '{}' and predicates '{}'.", graphiteConfiguration.getHostname(),
      graphiteConfiguration.getPort(), graphiteConfiguration.getPeriodSeconds(), graphiteConfiguration.getPrefix(), JavaUtils.COMMA_JOINER.join(graphiteConfiguration.getPredicates()));

  final Graphite graphite = new Graphite(new InetSocketAddress(graphiteConfiguration.getHostname(), graphiteConfiguration.getPort()));

  final GraphiteReporter.Builder reporterBuilder = GraphiteReporter.forRegistry(registry);

  if (!Strings.isNullOrEmpty(graphiteConfiguration.getPrefix())) {
    reporterBuilder.prefixedWith(graphiteConfiguration.getPrefix());
  }

  if (!graphiteConfiguration.getPredicates().isEmpty()) {
    reporterBuilder.filter(new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        for (String predicate : graphiteConfiguration.getPredicates()) {
          if (name.startsWith(predicate)) {
            return true;
          }
        }
        return false;
      }
    });
  }

  reporter = Optional.of(reporterBuilder.build(graphite));
  reporter.get().start(graphiteConfiguration.getPeriodSeconds(), TimeUnit.SECONDS);
}
 
Example #30
Source File: BaragonGraphiteReporterManaged.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws Exception {
  if (!graphiteConfiguration.isEnabled()) {
    LOG.info("Not reporting data points to graphite.");
    return;
  }

  final String prefix = buildGraphitePrefix();

  LOG.info("Reporting data points to graphite server {}:{} every {} seconds with prefix '{}' and predicates '{}'.", graphiteConfiguration.getHostname(),
      graphiteConfiguration.getPort(), graphiteConfiguration.getPeriodSeconds(), graphiteConfiguration.getPrefix(), JavaUtils.COMMA_JOINER.join(graphiteConfiguration.getPredicates()));

  final Graphite graphite = new Graphite(new InetSocketAddress(graphiteConfiguration.getHostname(), graphiteConfiguration.getPort()));

  final GraphiteReporter.Builder reporterBuilder = GraphiteReporter.forRegistry(registry);

  if (!Strings.isNullOrEmpty(graphiteConfiguration.getPrefix())) {
    reporterBuilder.prefixedWith(prefix);
  }

  if (!graphiteConfiguration.getPredicates().isEmpty()) {
    reporterBuilder.filter(new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        for (String predicate : graphiteConfiguration.getPredicates()) {
          if (name.startsWith(predicate)) {
            return true;
          }
        }
        return false;
      }
    });
  }

  reporter = Optional.of(reporterBuilder.build(graphite));
  reporter.get().start(graphiteConfiguration.getPeriodSeconds(), TimeUnit.SECONDS);
}