Search in sources :

Example 1 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric in project flink by apache.

the class GangliaReporter method getReporter.

@Override
public ScheduledReporter getReporter(MetricConfig config) {
    try {
        String host = config.getString(ARG_HOST, null);
        int port = config.getInteger(ARG_PORT, -1);
        if (host == null || host.length() == 0 || port < 1) {
            throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
        }
        String addressingMode = config.getString(ARG_MODE_ADDRESSING, "MULTICAST");
        int ttl = config.getInteger(ARG_TTL, 1);
        GMetric gMetric = new GMetric(host, port, GMetric.UDPAddressingMode.valueOf(addressingMode), ttl);
        String prefix = config.getString(ARG_PREFIX, null);
        String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
        String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
        int dMax = config.getInteger(ARG_DMAX, 0);
        int tMax = config.getInteger(ARG_TMAX, 60);
        com.codahale.metrics.ganglia.GangliaReporter.Builder builder = com.codahale.metrics.ganglia.GangliaReporter.forRegistry(registry);
        if (prefix != null) {
            builder.prefixedWith(prefix);
        }
        if (conversionRate != null) {
            builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
        }
        if (conversionDuration != null) {
            builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
        }
        builder.withDMax(dMax);
        builder.withTMax(tMax);
        log.info("Configured GangliaReporter with {host:{}, port:{}, dmax:{}, tmax:{}, ttl:{}, addressingMode:{}}", host, port, dMax, tMax, ttl, addressingMode);
        return builder.build(gMetric);
    } catch (IOException e) {
        throw new RuntimeException("Error while instantiating GangliaReporter.", e);
    }
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) IOException(java.io.IOException)

Example 2 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric in project lucene-solr by apache.

the class SolrGangliaReporter method start.

//this is a separate method for unit tests
void start() {
    if (!testing) {
        String id = host + ":" + port + ":" + multicast;
        ganglia = serviceRegistry.getOrCreate(id, () -> new GMetric(host, port, multicast ? GMetric.UDPAddressingMode.MULTICAST : GMetric.UDPAddressingMode.UNICAST, 1));
        if (ganglia == null) {
            return;
        }
    }
    if (instancePrefix == null) {
        instancePrefix = registryName;
    } else {
        instancePrefix = instancePrefix + "." + registryName;
    }
    GangliaReporter.Builder builder = GangliaReporter.forRegistry(metricManager.registry(registryName)).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).prefixedWith(instancePrefix);
    MetricFilter filter;
    if (!filters.isEmpty()) {
        filter = new SolrMetricManager.PrefixFilter(filters);
    } else {
        filter = MetricFilter.ALL;
    }
    builder = builder.filter(filter);
    reporter = builder.build(ganglia);
    reporter.start(period, TimeUnit.SECONDS);
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) MetricFilter(com.codahale.metrics.MetricFilter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) GangliaReporter(com.codahale.metrics.ganglia.GangliaReporter)

Example 3 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric in project jmxtrans by jmxtrans.

the class GangliaWriter method internalWrite.

/**
	 * Send query result values to Ganglia.
	 */
@Override
public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
    for (final Result result : results) {
        for (final Map.Entry<String, Object> resultValue : result.getValues().entrySet()) {
            final String name = KeyUtils.getKeyString(query, result, resultValue, getTypeNames());
            Object transformedValue = valueTransformer.apply(resultValue.getValue());
            GMetricType dataType = getType(resultValue.getValue());
            log.debug("Sending Ganglia metric {}={} [type={}]", name, transformedValue, dataType);
            try (GMetric metric = new GMetric(host, port, addressingMode, ttl, v31, null, spoofedHostName)) {
                metric.announce(name, transformedValue.toString(), dataType, units, slope, tmax, dmax, groupName);
            }
        }
    }
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) GMetricType(info.ganglia.gmetric4j.gmetric.GMetricType) Map(java.util.Map) Result(com.googlecode.jmxtrans.model.Result)

Example 4 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric in project ninja by ninjaframework.

the class NinjaGanglia method start.

@Start(order = 90)
public void start() {
    if (ninjaProperties.getBooleanWithDefault("metrics.ganglia.enabled", false)) {
        final String hostname = metricsService.getHostname();
        final String address = ninjaProperties.getOrDie("metrics.ganglia.address");
        final int port = ninjaProperties.getIntegerWithDefault("metrics.ganglia.port", 8649);
        final String period = ninjaProperties.getWithDefault("metrics.ganglia.period", "60s");
        final int delay = TimeUtil.parseDuration(period);
        try {
            GMetric ganglia = new GMetric(address, port, UDPAddressingMode.MULTICAST, 1);
            reporter = GangliaReporter.forRegistry(metricsService.getMetricRegistry()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(ganglia);
            reporter.start(delay, TimeUnit.SECONDS);
            log.info("Started Ganglia Metrics reporter for '{}', updating every {}", hostname, period);
        } catch (IOException e) {
            log.error("Failed to start Ganglia reporter!", e);
        }
    }
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) IOException(java.io.IOException) Start(ninja.lifecycle.Start)

Example 5 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric in project camel by apache.

the class GangliaEndpoint method getPublisher.

public synchronized Publisher getPublisher() {
    if (publisher == null) {
        GMetric gmetric = configuration.createGMetric();
        publisher = new GMetricPublisher(gmetric);
    }
    return publisher;
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) GMetricPublisher(info.ganglia.gmetric4j.gmetric.GMetricPublisher)

Aggregations

GMetric (info.ganglia.gmetric4j.gmetric.GMetric)6 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)2 IOException (java.io.IOException)2 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)2 MetricFilter (com.codahale.metrics.MetricFilter)1 GangliaReporter (com.codahale.metrics.ganglia.GangliaReporter)1 Result (com.googlecode.jmxtrans.model.Result)1 GMetricPublisher (info.ganglia.gmetric4j.gmetric.GMetricPublisher)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Start (ninja.lifecycle.Start)1 CoreContainer (org.apache.solr.core.CoreContainer)1 NodeConfig (org.apache.solr.core.NodeConfig)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)1 TestHarness (org.apache.solr.util.TestHarness)1 Test (org.junit.Test)1