Search in sources :

Example 1 with GraphiteSender

use of com.codahale.metrics.graphite.GraphiteSender in project ninja by ninjaframework.

the class NinjaGraphite method start.

@Start(order = 90)
public void start() {
    if (ninjaProperties.getBooleanWithDefault("metrics.graphite.enabled", false)) {
        final String hostname = metricsService.getHostname();
        final String address = ninjaProperties.getOrDie("metrics.graphite.address");
        final int port = ninjaProperties.getIntegerWithDefault("metrics.graphite.port", 2003);
        final boolean isPickled = ninjaProperties.getBooleanWithDefault("metrics.graphite.pickled", false);
        final String period = ninjaProperties.getWithDefault("metrics.graphite.period", "60s");
        final int delay = TimeUtil.parseDuration(period);
        final InetSocketAddress graphiteAddress = new InetSocketAddress(address, port);
        final GraphiteSender sender;
        if (isPickled) {
            sender = new PickledGraphite(graphiteAddress);
        } else {
            sender = new Graphite(graphiteAddress);
        }
        reporter = GraphiteReporter.forRegistry(metricsService.getMetricRegistry()).prefixedWith(hostname).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(sender);
        reporter.start(delay, TimeUnit.SECONDS);
        log.info("Started Graphite Metrics reporter for '{}', updating every {}", hostname, period);
    }
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) InetSocketAddress(java.net.InetSocketAddress) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) Graphite(com.codahale.metrics.graphite.Graphite) Start(ninja.lifecycle.Start)

Example 2 with GraphiteSender

use of com.codahale.metrics.graphite.GraphiteSender in project camel by apache.

the class Application method graphiteReporter.

/**
     * Create reporter bean and tell Spring to call stop() when shutting down.
     * UPD must be enabled in carbon.conf
     * 
     * @return graphite reporter
     */
@Bean(destroyMethod = "stop")
public GraphiteReporter graphiteReporter() {
    final GraphiteSender graphite = new GraphiteUDP(new InetSocketAddress("localhost", 2003));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry).prefixedWith("camel-spring-boot").convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
    reporter.start(5, TimeUnit.SECONDS);
    return reporter;
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP) Bean(org.springframework.context.annotation.Bean)

Example 3 with GraphiteSender

use of com.codahale.metrics.graphite.GraphiteSender in project lucene-solr by apache.

the class SolrGraphiteReporter method validate.

@Override
protected void validate() throws IllegalStateException {
    if (!enabled) {
        log.info("Reporter disabled for registry " + registryName);
        return;
    }
    if (host == null) {
        throw new IllegalStateException("Init argument 'host' must be set to a valid Graphite server name.");
    }
    if (port == -1) {
        throw new IllegalStateException("Init argument 'port' must be set to a valid Graphite server port.");
    }
    if (reporter != null) {
        throw new IllegalStateException("Already started once?");
    }
    if (period < 1) {
        throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
    }
    GraphiteSender graphite;
    String id = host + ":" + port + ":" + pickled;
    graphite = serviceRegistry.getOrCreate(id, () -> {
        if (pickled) {
            return new PickledGraphite(host, port);
        } else {
            return new Graphite(host, port);
        }
    });
    if (instancePrefix == null) {
        instancePrefix = registryName;
    } else {
        instancePrefix = instancePrefix + "." + registryName;
    }
    GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metricManager.registry(registryName)).prefixedWith(instancePrefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS);
    MetricFilter filter;
    if (!filters.isEmpty()) {
        filter = new SolrMetricManager.PrefixFilter(filters);
    } else {
        filter = MetricFilter.ALL;
    }
    builder = builder.filter(filter);
    reporter = builder.build(graphite);
    reporter.start(period, TimeUnit.SECONDS);
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) MetricFilter(com.codahale.metrics.MetricFilter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) Graphite(com.codahale.metrics.graphite.Graphite) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Aggregations

GraphiteSender (com.codahale.metrics.graphite.GraphiteSender)3 Graphite (com.codahale.metrics.graphite.Graphite)2 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)2 PickledGraphite (com.codahale.metrics.graphite.PickledGraphite)2 InetSocketAddress (java.net.InetSocketAddress)2 MetricFilter (com.codahale.metrics.MetricFilter)1 GraphiteUDP (com.codahale.metrics.graphite.GraphiteUDP)1 Start (ninja.lifecycle.Start)1 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)1 Bean (org.springframework.context.annotation.Bean)1