Search in sources :

Example 1 with GMetricSlope

use of info.ganglia.gmetric4j.gmetric.GMetricSlope 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

GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)1 Message (org.apache.camel.Message)1