com.codahale.metrics.graphite.Graphite Java Examples

The following examples show how to use com.codahale.metrics.graphite.Graphite. 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: 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 #2
Source File: GraphiteSenderProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public GraphiteSender get() {
    HostAndPort hostAndPort = configuration.getAddress();
    String host = hostAndPort.getHost();
    int port = hostAndPort.getPortOrDefault(2003);

    switch (configuration.getProtocol()) {
        case PICKLE:
            return new PickledGraphite(
                    host,
                    port,
                    SocketFactory.getDefault(),
                    configuration.getCharset(),
                    configuration.getPickleBatchSize());
        case TCP:
            return new Graphite(host, port, SocketFactory.getDefault(), configuration.getCharset());
        case UDP:
            return new GraphiteUDP(host, port);
        default:
            throw new IllegalArgumentException("Unknown Graphite protocol \"" + configuration.getProtocol() + "\"");
    }
}
 
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: 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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: GraphiteReporterTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    Clock clock = mock(Clock.class);
    graphite = mock(Graphite.class);

    MetricRegistry registry = mock(MetricRegistry.class);

    when(clock.getTime()).thenReturn(TIMESTAMP * 1000);
    reporter = forRegistry(registry)
            .withClock(clock)
            .prefixedWith("prefix")
            .convertRatesTo(SECONDS)
            .convertDurationsTo(MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);

    logging = new LoggingTestSupport(GraphiteReporter.class);
}
 
Example #15
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 #16
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 #17
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 #18
Source File: MetricsTest.java    From okapi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) {
  String graphiteHost = System.getProperty("graphiteHost");

  final String registryName = "okapi";
  MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);

  // Note the setEnabled (true or false)
  DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions().
          setEnabled(false).setRegistryName(registryName);

  vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(metricsOpt));

  reporter1 = ConsoleReporter.forRegistry(registry).build();
  reporter1.start(1, TimeUnit.SECONDS);

  if (graphiteHost != null) {
    Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, 2003));
    reporter2 = GraphiteReporter.forRegistry(registry)
            .prefixedWith("okapiserver")
            .build(graphite);
    reporter2.start(1, TimeUnit.MILLISECONDS);
  }

  DeploymentOptions opt = new DeploymentOptions()
    .setConfig(new JsonObject().put("port", Integer.toString(port)));


  vertx.deployVerticle(MainVerticle.class.getName(),
          opt, context.asyncAssertSuccess());
  httpClient = vertx.createHttpClient();
}
 
Example #19
Source File: GraphiteMetricsReporter.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void init(GatewayConfig config) throws MetricsReporterException {
  if (config.isMetricsEnabled() && config.isGraphiteMetricsReportingEnabled()) {
    graphite = new Graphite(new InetSocketAddress(config.getGraphiteHost(), config.getGraphitePort()));
    reportingFrequency = config.getGraphiteReportingFrequency();
    setEnabled(true);
  }
}
 
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: 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 #22
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 #23
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 #24
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 #25
Source File: MetricsConfiguration.java    From find with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnProperty(GRAPHITE_HOST_PROPERTY_KEY)
public GraphiteReporter graphiteReporter(final MetricRegistry registry,
                                         @Value(GRAPHITE_HOST_PROPERTY) final String graphiteHost,
                                         @Value(GRAPHITE_PORT_PROPERTY) final int graphitePort,
                                         @Value(GRAPHITE_SCHEDULE_INTERVAL_PROPERTY) final int graphiteScheduleInterval) {
    final Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
        .prefixedWith(GRAPHITE_PREFIX)
        .build(graphite);
    reporter.start(graphiteScheduleInterval, TimeUnit.MILLISECONDS);
    return reporter;
}
 
Example #26
Source File: DefaultGraphiteMetricsReporter.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Configures parameters for graphite config.
 */
private void configGraphite() {
    try {
        graphite = new Graphite(new InetSocketAddress(address, port));
    } catch (Exception e) {
        log.error("Fail to connect to given graphite server! : " + e.getMessage());
    }
}
 
Example #27
Source File: GraphiteSenderProviderTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void getReturnsGraphite() throws Exception {
    final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() {
        @Override
        public GraphiteProtocol getProtocol() {
            return GraphiteProtocol.TCP;
        }
    };
    final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration);

    final GraphiteSender graphiteSender = provider.get();
    assertTrue(graphiteSender instanceof Graphite);
    assertFalse(graphiteSender.isConnected());
}
 
Example #28
Source File: DropwizardReporterGraphite.java    From kafka-dropwizard-reporter with Apache License 2.0 5 votes vote down vote up
@Override
public void init(List<KafkaMetric> list) {
  super.init(list);
  InetSocketAddress address = new InetSocketAddress(
      config.getString(DropwizardReporterConfig.GRAPHITE_HOST_PROPERTY_NAME),
      config.getInt(DropwizardReporterConfig.GRAPHITE_PORT_PROPERTY_NAME));
  graphite = new Graphite(address);
  reporter = GraphiteReporter.forRegistry(registry)
      .prefixedWith(config.getString(DropwizardReporterConfig.GRAPHITE_PREFIX_PROPERTY_NAME))
      .build(graphite);
  LOGGER.info("Starting the reporter");
  reporter.start(11, TimeUnit.SECONDS);
}
 
Example #29
Source File: DefaultGraphiteReporterFactory.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Reporter getReporter(MetricRegistry registry) {
    if (null == reporter) {
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteURL, graphitePort));
        reporter = GraphiteReporter.forRegistry(registry)
                                   .prefixedWith(prefix)
                                   .convertRatesTo(TimeUnit.SECONDS)
                                   .convertDurationsTo(TimeUnit.MILLISECONDS)
                                   .filter(MetricFilter.ALL)
                                   .build(graphite);
    }
    return reporter;
}
 
Example #30
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;
}