Search in sources :

Example 16 with Graphite

use of com.codahale.metrics.graphite.Graphite in project entrada by SIDN.

the class HistoricalMetricManager method flush.

/**
 * Uses a threshhold to determine if the value should be sent to graphite low values may indicate
 * trailing queries in later pcap files. duplicate timestamps get overwritten by graphite and only
 * the last timestamp value is used by graphite.
 */
public void flush() {
    log.info("Flushing metrics to Graphite, size: {}", metricCache.size());
    if (!metricsEnabled) {
        // do nothing
        return;
    }
    int oldSize = metricCache.size();
    metricCache.entrySet().stream().forEach(e -> log.info("Metric: {}  datapoints: {}", e.getKey(), e.getValue().size()));
    GraphiteSender graphite = new Graphite(host, port);
    try {
        graphite.connect();
        // send each metrics to graphite
        metricCache.entrySet().stream().map(Entry::getValue).forEach(m -> send(graphite, m));
    } catch (Exception e) {
        // cannot connect connect to graphite
        log.error("Could not connect to Graphite", e);
    } finally {
        // remove sent metric, avoiding sending them again.
        metricCache.values().stream().forEach(this::trunc);
        // check if any metric has an empty list of time-buckets, if so the list
        metricCache.entrySet().removeIf(e -> e.getValue().size() == 0);
        try {
            // close will also do a flush
            graphite.close();
        } catch (Exception e) {
        // ignore
        }
    }
    int newSize = metricCache.size();
    log.info("-------------- Metrics Manager Stats ---------------------");
    log.info("Metrics processed: {}", metricCounter);
    log.info("Metrics count before flush: {}", oldSize);
    log.info("Metrics count after flush: {}", newSize);
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) Graphite(com.codahale.metrics.graphite.Graphite) IOException(java.io.IOException)

Example 17 with Graphite

use of com.codahale.metrics.graphite.Graphite in project engineblock by engineblock.

the class MetricReporters method addGraphite.

public MetricReporters addGraphite(String host, int graphitePort, String prefix) {
    logger.debug("Adding graphite reporter to " + host + " with port " + graphitePort + " and prefix " + prefix);
    if (metricRegistries.isEmpty()) {
        throw new RuntimeException("There are no metric registries.");
    }
    for (PrefixedRegistry prefixedRegistry : metricRegistries) {
        Graphite graphite = new Graphite(new InetSocketAddress(host, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(prefixedRegistry.metricRegistry).prefixedWith(prefixedRegistry.prefix != null ? (!prefixedRegistry.prefix.isEmpty() ? prefix + "." + prefixedRegistry.prefix : prefix) : prefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.NANOSECONDS).filter(ActivityMetrics.METRIC_FILTER).build(graphite);
        scheduledReporters.add(graphiteReporter);
    }
    return this;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Graphite(com.codahale.metrics.graphite.Graphite)

Example 18 with Graphite

use of com.codahale.metrics.graphite.Graphite in project riposte by Nike-Inc.

the class DefaultGraphiteReporterFactory method getReporter.

@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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Graphite(com.codahale.metrics.graphite.Graphite)

Example 19 with Graphite

use of com.codahale.metrics.graphite.Graphite in project neo4j by neo4j.

the class GraphiteOutput method init.

@Override
public void init() {
    // Setup Graphite reporting
    final Graphite graphite = new Graphite(hostnamePort.getHost(), hostnamePort.getPort());
    graphiteReporter = GraphiteReporter.forRegistry(registry).prefixedWith(prefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
}
Also used : Graphite(com.codahale.metrics.graphite.Graphite)

Example 20 with Graphite

use of com.codahale.metrics.graphite.Graphite 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

Graphite (com.codahale.metrics.graphite.Graphite)30 InetSocketAddress (java.net.InetSocketAddress)19 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)13 MetricRegistry (com.codahale.metrics.MetricRegistry)9 GraphiteSender (com.codahale.metrics.graphite.GraphiteSender)4 GraphiteUDP (com.codahale.metrics.graphite.GraphiteUDP)4 TimeUnit (java.util.concurrent.TimeUnit)4 ConsoleReporter (com.codahale.metrics.ConsoleReporter)3 ScheduledReporter (com.codahale.metrics.ScheduledReporter)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Inject (javax.inject.Inject)3 IndyMetricsConfig (org.commonjava.indy.metrics.conf.IndyMetricsConfig)3 IndyMetricsNamed (org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed)3 ZabbixCacheStorage (org.commonjava.indy.metrics.zabbix.cache.ZabbixCacheStorage)3 IndyZabbixReporter (org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter)3 IndyZabbixSender (org.commonjava.indy.metrics.zabbix.sender.IndyZabbixSender)3 IndyHttpProvider (org.commonjava.indy.subsys.http.IndyHttpProvider)3 PickledGraphite (com.codahale.metrics.graphite.PickledGraphite)2 HostAndPort (com.google.common.net.HostAndPort)2 DropwizardMetricsOptions (io.vertx.ext.dropwizard.DropwizardMetricsOptions)2