Skip to content

Commit

Permalink
Add Ganglia component
Browse files Browse the repository at this point in the history
  • Loading branch information
dpocock authored and davsclaus committed Feb 20, 2015
1 parent 84eaba9 commit 6605b82
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 21 deletions.
1 change: 1 addition & 0 deletions apache-camel/src/main/descriptors/common-bin.xml
Expand Up @@ -73,6 +73,7 @@
<include>org.apache.camel:camel-freemarker</include>
<include>org.apache.camel:camel-ftp</include>
<include>org.apache.camel:camel-gae</include>
<include>org.apache.camel:camel-ganglia</include>
<include>org.apache.camel:camel-geocoder</include>
<include>org.apache.camel:camel-github</include>
<include>org.apache.camel:camel-google-calendar</include>
Expand Down
2 changes: 1 addition & 1 deletion components/camel-ganglia/pom.xml
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>info.ganglia.gmetric4j</groupId>
<artifactId>gmetric4j</artifactId>
<version>1.0.7</version>
<version>${gmetric4j-version}</version>
</dependency>

<!-- test dependencies -->
Expand Down
Expand Up @@ -22,14 +22,13 @@
import info.ganglia.gmetric4j.gmetric.GMetric;
import info.ganglia.gmetric4j.gmetric.GMetricSlope;
import info.ganglia.gmetric4j.gmetric.GMetricType;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;

/**
* @version
* @version
*/
@UriParams
public class GangliaConfiguration implements Cloneable {
Expand All @@ -53,7 +52,7 @@ public class GangliaConfiguration implements Cloneable {
@UriPath
private int port = DEFAULT_PORT;

@UriParam
@UriParam(defaultValue = "MULTICAST")
private GMetric.UDPAddressingMode mode = DEFAULT_MODE;

@UriParam(defaultValue = "5")
Expand All @@ -65,22 +64,22 @@ public class GangliaConfiguration implements Cloneable {
@UriParam
private String spoofHostname;

@UriParam(defaultValue = "Java")
@UriParam(defaultValue = "java")
private String groupName = DEFAULT_GROUP_NAME;

@UriParam
private String prefix;
private String prefix = null;

@UriParam(defaultValue = "metric")
private String metricName = DEFAULT_METRIC_NAME;

@UriParam
@UriParam(defaultValue = "STRING")
private GMetricType type = DEFAULT_TYPE;

@UriParam
@UriParam(defaultValue = "BOTH")
private GMetricSlope slope = DEFAULT_SLOPE;

@UriParam(defaultValue = "")
@UriParam
private String units = DEFAULT_UNITS;

@UriParam(defaultValue = "60")
Expand Down Expand Up @@ -114,8 +113,7 @@ public void configure(URI uri) {

public GMetric createGMetric() {
try {
return new GMetric(host, port, mode, ttl, wireFormat31x,
null, spoofHostname);
return new GMetric(host, port, mode, ttl, wireFormat31x, null, spoofHostname);
} catch (IOException ex) {
throw new RuntimeCamelException("Failed to initialize Ganglia", ex);
}
Expand Down Expand Up @@ -217,19 +215,23 @@ public void setUnits(String units) {
this.units = units;
}

public int getTMax() {
public boolean isWireFormat31x() {
return wireFormat31x;
}

public int getTmax() {
return tmax;
}

public void setTMax(int tmax) {
public void setTmax(int tmax) {
this.tmax = tmax;
}

public int getDMax() {
public int getDmax() {
return dmax;
}

public void setDMax(int dmax) {
public void setDmax(int dmax) {
this.dmax = dmax;
}

Expand Down
Expand Up @@ -26,8 +26,8 @@ public final class GangliaConstants {
public static final String METRIC_TYPE = "CamelGangliaMetricType";
public static final String METRIC_SLOPE = "CamelGangliaMetricSlope";
public static final String METRIC_UNITS = "CamelGangliaMetricUnits";
public static final String METRIC_TMAX = "CamelGangliaMetricTMax";
public static final String METRIC_DMAX = "CamelGangliaMetricDMax";
public static final String METRIC_TMAX = "CamelGangliaMetricTmax";
public static final String METRIC_DMAX = "CamelGangliaMetricDmax";

private GangliaConstants() {
}
Expand Down
Expand Up @@ -19,7 +19,6 @@
import info.ganglia.gmetric4j.Publisher;
import info.ganglia.gmetric4j.gmetric.GMetric;
import info.ganglia.gmetric4j.gmetric.GMetricPublisher;

import org.apache.camel.Component;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
Expand Down
Expand Up @@ -23,6 +23,9 @@
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;

/**
* @version
*/
public class GangliaProducer extends DefaultProducer {

private final Publisher publisher;
Expand Down Expand Up @@ -68,17 +71,22 @@ public void process(Exchange exchange) throws Exception {
units = message.getHeader(GangliaConstants.METRIC_UNITS, String.class);
}

int tmax = conf.getTMax();
int tmax = conf.getTmax();
if (message.getHeaders().containsKey(GangliaConstants.METRIC_TMAX)) {
tmax = message.getHeader(GangliaConstants.METRIC_TMAX, Integer.class);
}

int dmax = conf.getDMax();
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);
Expand Down
7 changes: 7 additions & 0 deletions parent/pom.xml
Expand Up @@ -177,6 +177,7 @@
<geronimo-servlet-spec-version>1.0</geronimo-servlet-spec-version>
<geronimo-ws-metadata-spec-version>1.1.3</geronimo-ws-metadata-spec-version>
<gmaven-plugin-version>1.4</gmaven-plugin-version>
<gmetric4j-version>1.0.9</gmetric4j-version>
<google-app-engine-version>1.8.3</google-app-engine-version>
<google-app-engine-bundle-version>1.8.3_1</google-app-engine-bundle-version>
<google-gdata-version>1.41.5.w1</google-gdata-version>
Expand Down Expand Up @@ -354,6 +355,7 @@
<olingo2-version>2.0.0</olingo2-version>
<olingo-odata2-core-bundle-version>2.0.0_1</olingo-odata2-core-bundle-version>
<ognl-version>3.0.8_1</ognl-version>
<oncrpc-version>1.1.2</oncrpc-version>
<openejb-version>4.6.0.2</openejb-version>
<openjpa-version>2.3.0</openjpa-version>
<opensaml-version>2.5.1_2</opensaml-version>
Expand Down Expand Up @@ -816,6 +818,11 @@
<artifactId>camel-ftp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ganglia</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-github</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion platforms/karaf/features/src/main/resources/features.xml
Expand Up @@ -52,7 +52,7 @@
<bundle>mvn:org.apache.camel/camel-blueprint/${project.version}</bundle>
</feature>

<!-- the following features is sorted A..Z -->
<!-- the following features are sorted A..Z -->

<feature name='camel-ahc' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
Expand Down Expand Up @@ -408,6 +408,12 @@
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.gae/${google-app-engine-bundle-version}</bundle>
<bundle>mvn:org.apache.camel/camel-gae/${project.version}</bundle>
</feature>
<feature name='camel-ganglia' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:org.acplt.remotetea/remotetea-oncrpc/${oncrpc-version}</bundle>
<bundle dependency='true'>mvn:info.ganglia.gmetric4j/gmetric4j/${gmetric4j-version}</bundle>
<bundle>mvn:org.apache.camel/camel-ganglia/${project.version}</bundle>
</feature>
<feature name='camel-geocoder' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/${commons-httpclient-bundle-version}</bundle>
Expand Down
@@ -0,0 +1,40 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.itest.karaf;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;

@RunWith(PaxExam.class)
public class CamelGangliaTest extends AbstractFeatureTest {

public static final String COMPONENT = extractName(CamelGangliaTest.class);

@Test
public void test() throws Exception {
testComponent(COMPONENT);
}

@Configuration
public static Option[] configure() {
return configure(COMPONENT);
}

}

0 comments on commit 6605b82

Please sign in to comment.