Search in sources :

Example 1 with GMetricType

use of info.ganglia.gmetric4j.gmetric.GMetricType in project metrics by dropwizard.

the class GangliaReporter method reportGauge.

private void reportGauge(String name, Gauge gauge) {
    final String sanitizedName = escapeSlashes(name);
    final String group = group(name);
    final Object obj = gauge.getValue();
    final String value = String.valueOf(obj);
    final GMetricType type = detectType(obj);
    try {
        announce(name(prefix, sanitizedName), group, value, type, "");
    } catch (GangliaException e) {
        LOGGER.warn("Unable to report gauge {}", name, e);
    }
}
Also used : GMetricType(info.ganglia.gmetric4j.gmetric.GMetricType) GangliaException(info.ganglia.gmetric4j.gmetric.GangliaException)

Example 2 with GMetricType

use of info.ganglia.gmetric4j.gmetric.GMetricType 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 3 with GMetricType

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

the class GangliaProducer method process.

public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    GangliaConfiguration conf = gangliaEndpoint.getConfiguration();
    String groupName = conf.getGroupName();
    if (message.getHeaders().containsKey(GangliaConstants.GROUP_NAME)) {
        groupName = message.getHeader(GangliaConstants.GROUP_NAME, String.class);
    }
    String prefix = conf.getPrefix();
    String metricName = conf.getMetricName();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_NAME)) {
        metricName = message.getHeader(GangliaConstants.METRIC_NAME, String.class);
    }
    if (prefix != null && prefix.length() > 0) {
        metricName = prefix + "_" + metricName;
    }
    GMetricType type = conf.getType();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_TYPE)) {
        type = message.getHeader(GangliaConstants.METRIC_TYPE, GMetricType.class);
    }
    GMetricSlope slope = conf.getSlope();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_SLOPE)) {
        slope = message.getHeader(GangliaConstants.METRIC_SLOPE, GMetricSlope.class);
    }
    String units = conf.getUnits();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_UNITS)) {
        units = message.getHeader(GangliaConstants.METRIC_UNITS, String.class);
    }
    int tmax = conf.getTmax();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_TMAX)) {
        tmax = message.getHeader(GangliaConstants.METRIC_TMAX, Integer.class);
    }
    int dmax = conf.getDmax();
    if (message.getHeaders().containsKey(GangliaConstants.METRIC_DMAX)) {
        dmax = message.getHeader(GangliaConstants.METRIC_DMAX, Integer.class);
    }
    String value = message.getBody(String.class);
    if ((value == null || value.length() == 0) && (type == GMetricType.FLOAT || type == GMetricType.DOUBLE)) {
        log.debug("Metric {} string value was null, using NaN", metricName);
        value = "NaN";
    }
    if (log.isDebugEnabled()) {
        log.debug("Sending metric {} to Ganglia: {}", metricName, value);
    }
    publisher.publish(groupName, metricName, value, type, slope, tmax, dmax, units);
    log.trace("Sending metric done");
}
Also used : Message(org.apache.camel.Message) GMetricSlope(info.ganglia.gmetric4j.gmetric.GMetricSlope) GMetricType(info.ganglia.gmetric4j.gmetric.GMetricType)

Aggregations

GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)3 Result (com.googlecode.jmxtrans.model.Result)1 GMetric (info.ganglia.gmetric4j.gmetric.GMetric)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 GangliaException (info.ganglia.gmetric4j.gmetric.GangliaException)1 Map (java.util.Map)1 Message (org.apache.camel.Message)1