Search in sources :

Example 1 with PickledGraphite

use of com.codahale.metrics.graphite.PickledGraphite 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 customPrefix = ninjaProperties.get("metrics.graphite.prefix");
        final String hostname = metricsService.getHostname();
        final String prefix = StringUtils.isNotBlank(customPrefix) ? customPrefix : hostname;
        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(prefix).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 {}", prefix, 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 PickledGraphite

use of com.codahale.metrics.graphite.PickledGraphite 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)2 GraphiteSender (com.codahale.metrics.graphite.GraphiteSender)2 PickledGraphite (com.codahale.metrics.graphite.PickledGraphite)2 MetricFilter (com.codahale.metrics.MetricFilter)1 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)1 InetSocketAddress (java.net.InetSocketAddress)1 Start (ninja.lifecycle.Start)1 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)1