├── .gitignore
├── .travis.yml
├── src
├── main
│ ├── resources
│ │ └── META-INF
│ │ │ └── MANIFEST.MF
│ ├── java
│ │ └── info
│ │ │ └── ganglia
│ │ │ └── gmetric4j
│ │ │ ├── GScheduler.java
│ │ │ ├── gmetric
│ │ │ ├── package.html
│ │ │ ├── GMetricSlope.java
│ │ │ ├── GMetricType.java
│ │ │ ├── Protocol.java
│ │ │ ├── GMetricPublisher.java
│ │ │ ├── GangliaException.java
│ │ │ ├── Protocolv30x.java
│ │ │ ├── AbstractProtocol.java
│ │ │ ├── Protocolv31x.java
│ │ │ └── GMetric.java
│ │ │ ├── Publisher.java
│ │ │ ├── xdr
│ │ │ ├── v30x
│ │ │ │ ├── package.html
│ │ │ │ ├── Ganglia_value_types.java
│ │ │ │ ├── Ganglia_spoof_header.java
│ │ │ │ ├── Ganglia_spoof_message.java
│ │ │ │ ├── Ganglia_gmetric_message.java
│ │ │ │ ├── Ganglia_25metric.java
│ │ │ │ ├── Ganglia_message_formats.java
│ │ │ │ └── Ganglia_message.java
│ │ │ └── v31x
│ │ │ │ ├── package.html
│ │ │ │ ├── Ganglia_value_types.java
│ │ │ │ ├── Ganglia_msg_formats.java
│ │ │ │ ├── Ganglia_metadatareq.java
│ │ │ │ ├── Ganglia_extra_data.java
│ │ │ │ ├── Ganglia_metadatadef.java
│ │ │ │ ├── Ganglia_metric_id.java
│ │ │ │ ├── Ganglia_gmetric_int.java
│ │ │ │ ├── Ganglia_gmetric_uint.java
│ │ │ │ ├── Ganglia_gmetric_float.java
│ │ │ │ ├── Ganglia_gmetric_short.java
│ │ │ │ ├── Ganglia_gmetric_double.java
│ │ │ │ ├── Ganglia_gmetric_ushort.java
│ │ │ │ ├── Ganglia_gmetric_string.java
│ │ │ │ ├── Ganglia_uuid.java
│ │ │ │ ├── Ganglia_metadata_message.java
│ │ │ │ ├── Ganglia_25metric.java
│ │ │ │ ├── Ganglia_metadata_msg.java
│ │ │ │ └── Ganglia_value_msg.java
│ │ │ ├── CoreSampler.java
│ │ │ ├── DefaultGScheduler.java
│ │ │ ├── GSampler.java
│ │ │ └── GMonitor.java
│ └── assembly
│ │ └── bin.xml
└── test
│ └── java
│ └── info
│ └── ganglia
│ └── gmetric4j
│ └── gmetric
│ ├── GMetricIT.java
│ └── GMetricResult.java
├── .project
├── README
├── .classpath
├── COPYING
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | classes/
2 | gmetric4j.jar
3 | /target
4 | /.settings
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk7
4 | - openjdk6
5 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Boot-Class-Path: remotetea-oncrpc.jar
3 | Can-Redefine-Classes: false
4 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/GScheduler.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public interface GScheduler {
6 |
7 | public void onStart();
8 | public void onStop();
9 |
10 | public void scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Provides a class that implements the Ganglia gmetric command in 100% java.
8 |
9 | Package Specification
10 |
11 | Related Documentation
12 |
13 | For a description of Ganglia, please see:
14 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | gmetric4j
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/Publisher.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 | import info.ganglia.gmetric4j.gmetric.GMetricSlope;
4 | import info.ganglia.gmetric4j.gmetric.GMetricType;
5 | import info.ganglia.gmetric4j.gmetric.GangliaException;
6 |
7 | public interface Publisher {
8 | void publish( String processName, String attributeName,
9 | String value, GMetricType type, GMetricSlope slope, String units )
10 | throws GangliaException;
11 |
12 | void publish( String processName, String attributeName,
13 | String value, GMetricType type, GMetricSlope slope, int delay,
14 | int lifetime, String units )
15 | throws GangliaException;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/GMetricSlope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package info.ganglia.gmetric4j.gmetric;
7 |
8 | /**
9 | *
10 | * @author humphrej
11 | */
12 | public enum GMetricSlope {
13 | //zero|positive|negative|both
14 | ZERO(0),
15 | POSITIVE(1),
16 | NEGATIVE(2),
17 | BOTH(3);
18 |
19 | private int gangliaSlope ;
20 |
21 | GMetricSlope( int gangliaSlope ) {
22 | this.gangliaSlope = gangliaSlope ;
23 | }
24 |
25 | public int getGangliaSlope() {
26 | return gangliaSlope ;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | RemoteTea generated classes that implement the Ganglia v3.0.x XDR style protocol. These classes were generated from the ganglia protocol.x.
8 |
9 | Package Specification
10 |
11 | Related Documentation
12 |
13 | For a description of Ganglia, please see:
14 |
17 | For a description of RemoteTea, please see:
18 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | RemoteTea generated classes that implement the Ganglia v3.1.x XDR style protocol. These classes were generated from the ganglia protocol.x.
8 |
9 | Package Specification
10 |
11 | Related Documentation
12 |
13 | For a description of Ganglia, please see:
14 |
17 | For a description of RemoteTea, please see:
18 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/assembly/bin.xml:
--------------------------------------------------------------------------------
1 |
2 | bin
3 |
4 | zip
5 |
6 | true
7 |
8 |
9 | false
10 |
11 |
12 |
13 |
14 |
15 | etc/*
16 | README*
17 | LICENSE*
18 | NOTICE*
19 | COPYING*
20 | CHANGES*
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/GMetricType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package info.ganglia.gmetric4j.gmetric;
7 |
8 | /**
9 | *
10 | * @author humphrej
11 | */
12 | public enum GMetricType {
13 | //string|int8|uint8|int16|uint16|int32|uint32|float|double
14 | STRING("string"),
15 | INT8("int8"),
16 | UINT8("uint8"),
17 | INT16("int16"),
18 | UINT16("uint16"),
19 | INT32("int32"),
20 | UINT32("uint32"),
21 | FLOAT("float"),
22 | DOUBLE("double");
23 |
24 | private String gangliaType ;
25 |
26 | GMetricType( String gangliaType ) {
27 | this.gangliaType = gangliaType ;
28 | }
29 |
30 | public String getGangliaType() {
31 | return gangliaType ;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/CoreSampler.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 | import info.ganglia.gmetric4j.gmetric.GMetricSlope;
4 | import info.ganglia.gmetric4j.gmetric.GMetricType;
5 | import info.ganglia.gmetric4j.gmetric.GangliaException;
6 |
7 | //import java.util.logging.Logger;
8 |
9 |
10 | public class CoreSampler extends GSampler {
11 |
12 | // private static Logger log =
13 | // Logger.getLogger(CoreSampler.class.getName());
14 |
15 | public CoreSampler() {
16 | super(0, 30, "core");
17 | }
18 |
19 | public void run() {
20 | Publisher gm = getPublisher();
21 | // log.finer("Announcing heartbeat");
22 | try {
23 | gm.publish("core", "heartbeat", "0", GMetricType.UINT32, GMetricSlope.ZERO, "");
24 | } catch (GangliaException e) {
25 | // log.severe("Exception while sending heartbeat");
26 | e.printStackTrace();
27 | }
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/Protocol.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import java.io.Closeable;
4 |
5 | /**
6 | * An interface to be implemented by protocol implementations
7 | *
8 | */
9 | public interface Protocol extends Closeable {
10 |
11 | /**
12 | * Announces a metric
13 | * @param name the metric name
14 | * @param value the metric value
15 | * @param type the metric type
16 | * @param units the units
17 | * @param slope the slope
18 | * @param tmax the tmax
19 | * @param dmax the dmax
20 | * @param groupName the metric group
21 | * @throws Exception
22 | */
23 | void announce( String name,
24 | String value,
25 | GMetricType type,
26 | String units,
27 | GMetricSlope slope,
28 | int tmax,
29 | int dmax,
30 | String groupName ) throws Exception ;
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/GMetricPublisher.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import info.ganglia.gmetric4j.Publisher;
4 |
5 | public class GMetricPublisher implements Publisher {
6 |
7 | private GMetric gm = null ;
8 | public GMetricPublisher( GMetric gm ) {
9 | this.gm = gm ;
10 | }
11 |
12 | public void publish(String processName, String attributeName, String value,
13 | GMetricType type, GMetricSlope slope, String units) throws GangliaException {
14 | publish(processName, attributeName, value, type, slope, 60, 0, units);
15 | }
16 |
17 | @Override
18 | public void publish(String processName, String attributeName, String value,
19 | GMetricType type, GMetricSlope slope, int delay, int lifetime, String units)
20 | throws GangliaException {
21 | gm.announce(attributeName, value, type, units,
22 | slope, delay, lifetime, processName);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_value_types.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | /**
8 | * Enumeration (collection of constants).
9 | */
10 | public interface Ganglia_value_types {
11 |
12 | public static final int GANGLIA_VALUE_UNKNOWN = 0;
13 | public static final int GANGLIA_VALUE_STRING = 0+1;
14 | public static final int GANGLIA_VALUE_UNSIGNED_SHORT = 0+1+1;
15 | public static final int GANGLIA_VALUE_SHORT = 0+1+1+1;
16 | public static final int GANGLIA_VALUE_UNSIGNED_INT = 0+1+1+1+1;
17 | public static final int GANGLIA_VALUE_INT = 0+1+1+1+1+1;
18 | public static final int GANGLIA_VALUE_FLOAT = 0+1+1+1+1+1+1;
19 | public static final int GANGLIA_VALUE_DOUBLE = 0+1+1+1+1+1+1+1;
20 |
21 | }
22 | // End of Ganglia_value_types.java
23 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_value_types.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | /**
8 | * Enumeration (collection of constants).
9 | */
10 | public interface Ganglia_value_types {
11 |
12 | public static final int GANGLIA_VALUE_UNKNOWN = 0;
13 | public static final int GANGLIA_VALUE_STRING = 0+1;
14 | public static final int GANGLIA_VALUE_UNSIGNED_SHORT = 0+1+1;
15 | public static final int GANGLIA_VALUE_SHORT = 0+1+1+1;
16 | public static final int GANGLIA_VALUE_UNSIGNED_INT = 0+1+1+1+1;
17 | public static final int GANGLIA_VALUE_INT = 0+1+1+1+1+1;
18 | public static final int GANGLIA_VALUE_FLOAT = 0+1+1+1+1+1+1;
19 | public static final int GANGLIA_VALUE_DOUBLE = 0+1+1+1+1+1+1+1;
20 |
21 | }
22 | // End of Ganglia_value_types.java
23 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/GangliaException.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | /**
4 | *
5 | * @author humphrej
6 | */
7 | public class GangliaException extends Exception {
8 | private static final long serialVersionUID = 1L;
9 |
10 | /**
11 | * Creates a new instance of GangliaException without detail message.
12 | */
13 | public GangliaException() {
14 | }
15 |
16 |
17 | /**
18 | * Constructs an instance of GangliaException with the specified detail message.
19 | * @param msg the detail message.
20 | */
21 | public GangliaException(String msg) {
22 | super(msg);
23 | }
24 |
25 | /**
26 | * Constructs an instance of GangliaException with the specified detail message and cause.
27 | * @param msg the detail message
28 | * @param cause the cause
29 | */
30 | public GangliaException( String msg, Throwable cause ) {
31 | super( msg, cause );
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_msg_formats.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | /**
8 | * Enumeration (collection of constants).
9 | */
10 | public interface Ganglia_msg_formats {
11 |
12 | public static final int gmetadata_full = 128;
13 | public static final int gmetric_ushort = 128+1;
14 | public static final int gmetric_short = 128+1+1;
15 | public static final int gmetric_int = 128+1+1+1;
16 | public static final int gmetric_uint = 128+1+1+1+1;
17 | public static final int gmetric_string = 128+1+1+1+1+1;
18 | public static final int gmetric_float = 128+1+1+1+1+1+1;
19 | public static final int gmetric_double = 128+1+1+1+1+1+1+1;
20 | public static final int gmetadata_request = 128+1+1+1+1+1+1+1+1;
21 |
22 | }
23 | // End of Ganglia_msg_formats.java
24 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Name
2 | gmetric4j - gmetric and gmond functionality in Java
3 |
4 | Version
5 | The latest version of this software and document will always be found at
6 | http://github.com/ganglia/gmetric4j
7 |
8 | Synopsis
9 | gmetric4j is a 100% java, configurable Ganglia agent that periodically polls
10 | arbitrary attributes and reports their values to Ganglia.
11 |
12 | It supports both the v3.1 wire format and the legacy wire format.
13 |
14 | This code is based on the jmxetric project code. It has been generalized for
15 | use in non-JMX situations (e.g. any Java app, Android app, ...). The JMX
16 | support could be re-implemented on top of these generalized classes without
17 | significant difficulty.
18 |
19 | The gmetric4j protocol implementation uses classes generated by the LGPL
20 | remotetea project (http://remotetea.sf.net).
21 |
22 | Copyright
23 |
24 | Copyright (C) 2010-2015 Daniel Pocock
25 | Copyright (c) 2008-2011 Jasper Humphrey
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_metadatareq.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_metadatareq implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 |
13 | public Ganglia_metadatareq() {
14 | }
15 |
16 | public Ganglia_metadatareq(XdrDecodingStream xdr)
17 | throws OncRpcException, IOException {
18 | xdrDecode(xdr);
19 | }
20 |
21 | public void xdrEncode(XdrEncodingStream xdr)
22 | throws OncRpcException, IOException {
23 | metric_id.xdrEncode(xdr);
24 | }
25 |
26 | public void xdrDecode(XdrDecodingStream xdr)
27 | throws OncRpcException, IOException {
28 | metric_id = new Ganglia_metric_id(xdr);
29 | }
30 |
31 | }
32 | // End of Ganglia_metadatareq.java
33 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/DefaultGScheduler.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 | import java.util.concurrent.ScheduledThreadPoolExecutor;
4 | import java.util.concurrent.ThreadFactory;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | public class DefaultGScheduler implements GScheduler {
8 |
9 | private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
10 |
11 | boolean daemon = true;
12 |
13 | private ThreadFactory daemonThreadGroup = new ThreadFactory() {
14 | public Thread newThread(Runnable r) {
15 | Thread t = new Thread(r);
16 | t.setName("Ganglia Sampling Thread");
17 | t.setDaemon(daemon);
18 | return t;
19 | }
20 | };
21 |
22 | public DefaultGScheduler() {
23 | }
24 |
25 | public void scheduleAtFixedRate(Runnable command, long initialDelay,
26 | long period, TimeUnit unit) {
27 | executor.scheduleAtFixedRate(command, initialDelay, period, unit);
28 | }
29 |
30 | public void onStart() {
31 | executor.setThreadFactory(daemonThreadGroup);
32 | }
33 |
34 | public void onStop() {
35 | executor.shutdown();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_extra_data.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_extra_data implements XdrAble {
11 | public String name;
12 | public String data;
13 |
14 | public Ganglia_extra_data() {
15 | }
16 |
17 | public Ganglia_extra_data(XdrDecodingStream xdr)
18 | throws OncRpcException, IOException {
19 | xdrDecode(xdr);
20 | }
21 |
22 | public void xdrEncode(XdrEncodingStream xdr)
23 | throws OncRpcException, IOException {
24 | xdr.xdrEncodeString(name);
25 | xdr.xdrEncodeString(data);
26 | }
27 |
28 | public void xdrDecode(XdrDecodingStream xdr)
29 | throws OncRpcException, IOException {
30 | name = xdr.xdrDecodeString();
31 | data = xdr.xdrDecodeString();
32 | }
33 |
34 | }
35 | // End of Ganglia_extra_data.java
36 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_spoof_header.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_spoof_header implements XdrAble {
11 | public String spoofName;
12 | public String spoofIP;
13 |
14 | public Ganglia_spoof_header() {
15 | }
16 |
17 | public Ganglia_spoof_header(XdrDecodingStream xdr)
18 | throws OncRpcException, IOException {
19 | xdrDecode(xdr);
20 | }
21 |
22 | public void xdrEncode(XdrEncodingStream xdr)
23 | throws OncRpcException, IOException {
24 | xdr.xdrEncodeString(spoofName);
25 | xdr.xdrEncodeString(spoofIP);
26 | }
27 |
28 | public void xdrDecode(XdrDecodingStream xdr)
29 | throws OncRpcException, IOException {
30 | spoofName = xdr.xdrDecodeString();
31 | spoofIP = xdr.xdrDecodeString();
32 | }
33 |
34 | }
35 | // End of Ganglia_spoof_header.java
36 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_metadatadef.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_metadatadef implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public Ganglia_metadata_message metric;
13 |
14 | public Ganglia_metadatadef() {
15 | }
16 |
17 | public Ganglia_metadatadef(XdrDecodingStream xdr)
18 | throws OncRpcException, IOException {
19 | xdrDecode(xdr);
20 | }
21 |
22 | public void xdrEncode(XdrEncodingStream xdr)
23 | throws OncRpcException, IOException {
24 | metric_id.xdrEncode(xdr);
25 | metric.xdrEncode(xdr);
26 | }
27 |
28 | public void xdrDecode(XdrDecodingStream xdr)
29 | throws OncRpcException, IOException {
30 | metric_id = new Ganglia_metric_id(xdr);
31 | metric = new Ganglia_metadata_message(xdr);
32 | }
33 |
34 | }
35 | // End of Ganglia_metadatadef.java
36 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_spoof_message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_spoof_message implements XdrAble {
11 | public Ganglia_spoof_header spheader;
12 | public Ganglia_gmetric_message gmetric;
13 |
14 | public Ganglia_spoof_message() {
15 | }
16 |
17 | public Ganglia_spoof_message(XdrDecodingStream xdr)
18 | throws OncRpcException, IOException {
19 | xdrDecode(xdr);
20 | }
21 |
22 | public void xdrEncode(XdrEncodingStream xdr)
23 | throws OncRpcException, IOException {
24 | spheader.xdrEncode(xdr);
25 | gmetric.xdrEncode(xdr);
26 | }
27 |
28 | public void xdrDecode(XdrDecodingStream xdr)
29 | throws OncRpcException, IOException {
30 | spheader = new Ganglia_spoof_header(xdr);
31 | gmetric = new Ganglia_gmetric_message(xdr);
32 | }
33 |
34 | }
35 | // End of Ganglia_spoof_message.java
36 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_metric_id.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_metric_id implements XdrAble {
11 | public String host;
12 | public String name;
13 | public boolean spoof;
14 |
15 | public Ganglia_metric_id() {
16 | }
17 |
18 | public Ganglia_metric_id(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | xdr.xdrEncodeString(host);
26 | xdr.xdrEncodeString(name);
27 | xdr.xdrEncodeBoolean(spoof);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | host = xdr.xdrDecodeString();
33 | name = xdr.xdrDecodeString();
34 | spoof = xdr.xdrDecodeBoolean();
35 | }
36 |
37 | }
38 | // End of Ganglia_metric_id.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_int.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_int implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public int si;
14 |
15 | public Ganglia_gmetric_int() {
16 | }
17 |
18 | public Ganglia_gmetric_int(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeInt(si);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | si = xdr.xdrDecodeInt();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_int.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_uint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_uint implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public int ui;
14 |
15 | public Ganglia_gmetric_uint() {
16 | }
17 |
18 | public Ganglia_gmetric_uint(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeInt(ui);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | ui = xdr.xdrDecodeInt();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_uint.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_float.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_float implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public float f;
14 |
15 | public Ganglia_gmetric_float() {
16 | }
17 |
18 | public Ganglia_gmetric_float(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeFloat(f);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | f = xdr.xdrDecodeFloat();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_float.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_short.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_short implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public short ss;
14 |
15 | public Ganglia_gmetric_short() {
16 | }
17 |
18 | public Ganglia_gmetric_short(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeShort(ss);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | ss = xdr.xdrDecodeShort();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_short.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_double.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_double implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public double d;
14 |
15 | public Ganglia_gmetric_double() {
16 | }
17 |
18 | public Ganglia_gmetric_double(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeDouble(d);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | d = xdr.xdrDecodeDouble();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_double.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_ushort.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_ushort implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public short us;
14 |
15 | public Ganglia_gmetric_ushort() {
16 | }
17 |
18 | public Ganglia_gmetric_ushort(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeShort(us);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | us = xdr.xdrDecodeShort();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_ushort.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_gmetric_string.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_string implements XdrAble {
11 | public Ganglia_metric_id metric_id;
12 | public String fmt;
13 | public String str;
14 |
15 | public Ganglia_gmetric_string() {
16 | }
17 |
18 | public Ganglia_gmetric_string(XdrDecodingStream xdr)
19 | throws OncRpcException, IOException {
20 | xdrDecode(xdr);
21 | }
22 |
23 | public void xdrEncode(XdrEncodingStream xdr)
24 | throws OncRpcException, IOException {
25 | metric_id.xdrEncode(xdr);
26 | xdr.xdrEncodeString(fmt);
27 | xdr.xdrEncodeString(str);
28 | }
29 |
30 | public void xdrDecode(XdrDecodingStream xdr)
31 | throws OncRpcException, IOException {
32 | metric_id = new Ganglia_metric_id(xdr);
33 | fmt = xdr.xdrDecodeString();
34 | str = xdr.xdrDecodeString();
35 | }
36 |
37 | }
38 | // End of Ganglia_gmetric_string.java
39 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/GSampler.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 | public abstract class GSampler implements Runnable {
4 |
5 | /*
6 | * The internal data structure is a hashmap of key=mbean name
7 | */
8 | private int delay;
9 | private int initialDelay;
10 | private Publisher publisher = null;
11 | protected String process = null ;
12 |
13 | /**
14 | * Creates a GSampler
15 | * @param delay the sample interval in seconds
16 | * @param process the process name that is appended to metrics
17 | */
18 | public GSampler(int initialDelay, int delay, String process ) {
19 | this.initialDelay = initialDelay ;
20 | this.delay = delay;
21 | this.process = process;
22 | }
23 |
24 | /**
25 | * Returns the sample interval
26 | * @return the sample interval in seconds
27 | */
28 | public int getDelay() {
29 | return delay;
30 | }
31 | /**
32 | * Returns the initial delay before sampling begins
33 | * @return the delay in seconds
34 | */
35 | public int getInitialDelay() {
36 | return initialDelay;
37 | }
38 |
39 | public Publisher getPublisher() {
40 | return publisher;
41 | }
42 |
43 | public void setPublisher(Publisher publisher) {
44 | this.publisher = publisher;
45 | }
46 |
47 | }
48 |
49 |
50 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | Title: gmetric4j
2 |
3 | Copyright:
4 |
5 | Copyright (C) 2012 Daniel Pocock
6 | Copyright (c) 2008-2011 Jasper Humphrey
7 |
8 | Based on: jmxetric by Jasper Humphrey (BSD style license)
9 |
10 | License: BSD terms
11 |
12 | Copyright (C) 2010-2012 Daniel Pocock
13 | Copyright (c) 2008-2011 Jasper Humphrey
14 |
15 | Permission is hereby granted, free of charge, to any person obtaining a copy
16 | of this software and associated documentation files (the "Software"), to deal
17 | in the Software without restriction, including without limitation the rights
18 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 | copies of the Software, and to permit persons to whom the Software is
20 | furnished to do so, subject to the following conditions:
21 |
22 | The above copyright notice and this permission notice shall be included in
23 | all copies or substantial portions of the Software.
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 | THE SOFTWARE.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_uuid.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.xdr.v31x;
2 |
3 | import java.io.IOException;
4 | import java.nio.ByteBuffer;
5 | import java.nio.ByteOrder;
6 | import java.util.UUID;
7 |
8 | import org.acplt.oncrpc.OncRpcException;
9 | import org.acplt.oncrpc.XdrAble;
10 | import org.acplt.oncrpc.XdrDecodingStream;
11 | import org.acplt.oncrpc.XdrEncodingStream;
12 |
13 | public class Ganglia_uuid implements XdrAble {
14 | public UUID uuid;
15 |
16 | public Ganglia_uuid() {
17 | }
18 |
19 | public Ganglia_uuid(XdrDecodingStream xdr)
20 | throws OncRpcException, IOException {
21 | xdrDecode(xdr);
22 | }
23 |
24 | protected byte[] getUUIDBytes() {
25 | Long msb = uuid.getMostSignificantBits();
26 | Long lsb = uuid.getLeastSignificantBits();
27 | byte[] buf = new byte[16];
28 | ByteBuffer _b = ByteBuffer.wrap(buf);
29 | _b.order(ByteOrder.BIG_ENDIAN);
30 | _b.putLong(msb);
31 | _b.putLong(lsb);
32 | return buf;
33 | }
34 |
35 | public void xdrEncode(XdrEncodingStream xdr)
36 | throws OncRpcException, IOException {
37 | xdr.xdrEncodeByteFixedVector(getUUIDBytes(), 16);
38 | }
39 |
40 | public void xdrDecode(XdrDecodingStream xdr)
41 | throws OncRpcException, IOException {
42 | uuid = getUUIDFromBytes(xdr.xdrDecodeByteFixedVector(16));
43 | }
44 |
45 | private UUID getUUIDFromBytes(byte[] buf) {
46 | ByteBuffer _b = ByteBuffer.wrap(buf);
47 | _b.order(ByteOrder.BIG_ENDIAN);
48 | Long msb = _b.getLong();
49 | Long lsb = _b.getLong();
50 | return new UUID(msb, lsb);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_gmetric_message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_gmetric_message implements XdrAble {
11 | public String type;
12 | public String name;
13 | public String value;
14 | public String units;
15 | public int slope;
16 | public int tmax;
17 | public int dmax;
18 |
19 | public Ganglia_gmetric_message() {
20 | }
21 |
22 | public Ganglia_gmetric_message(XdrDecodingStream xdr)
23 | throws OncRpcException, IOException {
24 | xdrDecode(xdr);
25 | }
26 |
27 | public void xdrEncode(XdrEncodingStream xdr)
28 | throws OncRpcException, IOException {
29 | xdr.xdrEncodeString(type);
30 | xdr.xdrEncodeString(name);
31 | xdr.xdrEncodeString(value);
32 | xdr.xdrEncodeString(units);
33 | xdr.xdrEncodeInt(slope);
34 | xdr.xdrEncodeInt(tmax);
35 | xdr.xdrEncodeInt(dmax);
36 | }
37 |
38 | public void xdrDecode(XdrDecodingStream xdr)
39 | throws OncRpcException, IOException {
40 | type = xdr.xdrDecodeString();
41 | name = xdr.xdrDecodeString();
42 | value = xdr.xdrDecodeString();
43 | units = xdr.xdrDecodeString();
44 | slope = xdr.xdrDecodeInt();
45 | tmax = xdr.xdrDecodeInt();
46 | dmax = xdr.xdrDecodeInt();
47 | }
48 |
49 | }
50 | // End of Ganglia_gmetric_message.java
51 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_25metric.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_25metric implements XdrAble {
11 | public int key;
12 | public String name;
13 | public int tmax;
14 | public int type;
15 | public String units;
16 | public String slope;
17 | public String fmt;
18 | public int msg_size;
19 |
20 | public Ganglia_25metric() {
21 | }
22 |
23 | public Ganglia_25metric(XdrDecodingStream xdr)
24 | throws OncRpcException, IOException {
25 | xdrDecode(xdr);
26 | }
27 |
28 | public void xdrEncode(XdrEncodingStream xdr)
29 | throws OncRpcException, IOException {
30 | xdr.xdrEncodeInt(key);
31 | xdr.xdrEncodeString(name);
32 | xdr.xdrEncodeInt(tmax);
33 | xdr.xdrEncodeInt(type);
34 | xdr.xdrEncodeString(units);
35 | xdr.xdrEncodeString(slope);
36 | xdr.xdrEncodeString(fmt);
37 | xdr.xdrEncodeInt(msg_size);
38 | }
39 |
40 | public void xdrDecode(XdrDecodingStream xdr)
41 | throws OncRpcException, IOException {
42 | key = xdr.xdrDecodeInt();
43 | name = xdr.xdrDecodeString();
44 | tmax = xdr.xdrDecodeInt();
45 | type = xdr.xdrDecodeInt();
46 | units = xdr.xdrDecodeString();
47 | slope = xdr.xdrDecodeString();
48 | fmt = xdr.xdrDecodeString();
49 | msg_size = xdr.xdrDecodeInt();
50 | }
51 |
52 | }
53 | // End of Ganglia_25metric.java
54 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_metadata_message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_metadata_message implements XdrAble {
11 | public String type;
12 | public String name;
13 | public String units;
14 | public int slope;
15 | public int tmax;
16 | public int dmax;
17 | public Ganglia_extra_data [] metadata;
18 |
19 | public Ganglia_metadata_message() {
20 | }
21 |
22 | public Ganglia_metadata_message(XdrDecodingStream xdr)
23 | throws OncRpcException, IOException {
24 | xdrDecode(xdr);
25 | }
26 |
27 | public void xdrEncode(XdrEncodingStream xdr)
28 | throws OncRpcException, IOException {
29 | xdr.xdrEncodeString(type);
30 | xdr.xdrEncodeString(name);
31 | xdr.xdrEncodeString(units);
32 | xdr.xdrEncodeInt(slope);
33 | xdr.xdrEncodeInt(tmax);
34 | xdr.xdrEncodeInt(dmax);
35 | { int $size = metadata.length; xdr.xdrEncodeInt($size); for ( int $idx = 0; $idx < $size; ++$idx ) { metadata[$idx].xdrEncode(xdr); } }
36 | }
37 |
38 | public void xdrDecode(XdrDecodingStream xdr)
39 | throws OncRpcException, IOException {
40 | type = xdr.xdrDecodeString();
41 | name = xdr.xdrDecodeString();
42 | units = xdr.xdrDecodeString();
43 | slope = xdr.xdrDecodeInt();
44 | tmax = xdr.xdrDecodeInt();
45 | dmax = xdr.xdrDecodeInt();
46 | { int $size = xdr.xdrDecodeInt(); metadata = new Ganglia_extra_data[$size]; for ( int $idx = 0; $idx < $size; ++$idx ) { metadata[$idx] = new Ganglia_extra_data(xdr); } }
47 | }
48 |
49 | }
50 | // End of Ganglia_metadata_message.java
51 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_25metric.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_25metric implements XdrAble {
11 | public int key;
12 | public String name;
13 | public int tmax;
14 | public int type;
15 | public String units;
16 | public String slope;
17 | public String fmt;
18 | public int msg_size;
19 | public String desc;
20 | public int metadata;
21 |
22 | public Ganglia_25metric() {
23 | }
24 |
25 | public Ganglia_25metric(XdrDecodingStream xdr)
26 | throws OncRpcException, IOException {
27 | xdrDecode(xdr);
28 | }
29 |
30 | public void xdrEncode(XdrEncodingStream xdr)
31 | throws OncRpcException, IOException {
32 | xdr.xdrEncodeInt(key);
33 | xdr.xdrEncodeString(name);
34 | xdr.xdrEncodeInt(tmax);
35 | xdr.xdrEncodeInt(type);
36 | xdr.xdrEncodeString(units);
37 | xdr.xdrEncodeString(slope);
38 | xdr.xdrEncodeString(fmt);
39 | xdr.xdrEncodeInt(msg_size);
40 | xdr.xdrEncodeString(desc);
41 | xdr.xdrEncodeInt(metadata);
42 | }
43 |
44 | public void xdrDecode(XdrDecodingStream xdr)
45 | throws OncRpcException, IOException {
46 | key = xdr.xdrDecodeInt();
47 | name = xdr.xdrDecodeString();
48 | tmax = xdr.xdrDecodeInt();
49 | type = xdr.xdrDecodeInt();
50 | units = xdr.xdrDecodeString();
51 | slope = xdr.xdrDecodeString();
52 | fmt = xdr.xdrDecodeString();
53 | msg_size = xdr.xdrDecodeInt();
54 | desc = xdr.xdrDecodeString();
55 | metadata = xdr.xdrDecodeInt();
56 | }
57 |
58 | }
59 | // End of Ganglia_25metric.java
60 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_metadata_msg.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_metadata_msg implements XdrAble {
11 | public int id;
12 | public Ganglia_metadatadef gfull;
13 | public Ganglia_metadatareq grequest;
14 | public Ganglia_uuid uuid;
15 |
16 | public Ganglia_metadata_msg() {
17 | }
18 |
19 | public Ganglia_metadata_msg(XdrDecodingStream xdr)
20 | throws OncRpcException, IOException {
21 | xdrDecode(xdr);
22 | }
23 |
24 | protected boolean hasUUID() {
25 | return ((id & 0x40) == 0x40);
26 | }
27 |
28 | public void xdrEncode(XdrEncodingStream xdr)
29 | throws OncRpcException, IOException {
30 | xdr.xdrEncodeInt(id);
31 |
32 | int _id = id & 0xbf;
33 |
34 | switch ( _id ) {
35 | case Ganglia_msg_formats.gmetadata_full:
36 | gfull.xdrEncode(xdr);
37 | break;
38 | case Ganglia_msg_formats.gmetadata_request:
39 | grequest.xdrEncode(xdr);
40 | break;
41 | default:
42 | break;
43 | }
44 |
45 | if(hasUUID()) {
46 | uuid.xdrEncode(xdr);
47 | }
48 | }
49 |
50 | public void xdrDecode(XdrDecodingStream xdr)
51 | throws OncRpcException, IOException {
52 | id = xdr.xdrDecodeInt();
53 |
54 | int _id = id & 0xbf;
55 |
56 | switch ( _id ) {
57 | case Ganglia_msg_formats.gmetadata_full:
58 | gfull = new Ganglia_metadatadef(xdr);
59 | break;
60 | case Ganglia_msg_formats.gmetadata_request:
61 | grequest = new Ganglia_metadatareq(xdr);
62 | break;
63 | default:
64 | break;
65 | }
66 |
67 | if(hasUUID()) {
68 | uuid = new Ganglia_uuid(xdr);
69 | }
70 | }
71 |
72 | }
73 | // End of Ganglia_metadata_msg.java
74 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/Protocolv30x.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import java.io.IOException;
4 |
5 | import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
6 | import info.ganglia.gmetric4j.xdr.v30x.Ganglia_gmetric_message;
7 | import info.ganglia.gmetric4j.xdr.v30x.Ganglia_message;
8 | import info.ganglia.gmetric4j.xdr.v30x.Ganglia_message_formats;
9 |
10 | import org.acplt.oncrpc.XdrBufferEncodingStream;
11 |
12 | public class Protocolv30x extends AbstractProtocol {
13 |
14 | private static final int MAX_BUFFER_SIZE = 1024 ;
15 | private XdrBufferEncodingStream xdr = new XdrBufferEncodingStream( MAX_BUFFER_SIZE );
16 |
17 | public Protocolv30x( String group, int port, UDPAddressingMode mode, int ttl ) throws IOException {
18 | super(group, port, mode, ttl);
19 | }
20 |
21 | @Override
22 | public void announce( String name, String value,
23 | GMetricType type, String units, GMetricSlope slope, int tmax,
24 | int dmax, String groupName) throws Exception {
25 | encodeGMetric( name, value, type, units, slope, tmax, dmax );
26 | send( xdr.getXdrData(), xdr.getXdrLength());
27 | }
28 |
29 | /**
30 | * Encodes the metric using the classes generated by remotetea
31 | */
32 | private void encodeGMetric( String name,
33 | String value,
34 | GMetricType type,
35 | String units,
36 | GMetricSlope slope,
37 | int tmax,
38 | int dmax )
39 | throws Exception {
40 | Ganglia_message msg = new Ganglia_message() ;
41 | Ganglia_gmetric_message gmetric_msg = new Ganglia_gmetric_message() ;
42 |
43 | msg.id = Ganglia_message_formats.metric_user_defined ;
44 | msg.gmetric = gmetric_msg ;
45 | gmetric_msg.name = name ;
46 | gmetric_msg.value = value ;
47 | gmetric_msg.type = type.getGangliaType() ;
48 | gmetric_msg.units = units ;
49 | gmetric_msg.slope = slope.getGangliaSlope() ;
50 | gmetric_msg.tmax = tmax ;
51 | gmetric_msg.dmax = dmax ;
52 |
53 | xdr.beginEncoding(udpAddr, port) ;
54 | msg.xdrEncode(xdr);
55 | xdr.endEncoding();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/AbstractProtocol.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 |
4 | import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
5 |
6 | import java.io.IOException;
7 | import java.net.DatagramPacket;
8 | import java.net.DatagramSocket;
9 | import java.net.InetAddress;
10 | import java.net.MulticastSocket;
11 | // import java.util.logging.Level;
12 | // import java.util.logging.Logger;
13 |
14 |
15 | /**
16 | * The base implementation for a protocol, does the socket work
17 | */
18 | public abstract class AbstractProtocol implements Protocol {
19 | protected InetAddress udpAddr = null ;
20 | protected int port ;
21 | protected String group ;
22 | private DatagramSocket socket ;
23 | //private static Logger log =
24 | // Logger.getLogger(AbstractProtocol.class.getName());
25 |
26 | public AbstractProtocol( String group, int port, UDPAddressingMode mode, int ttl ) throws IOException {
27 | this.group = group ;
28 | this.port = port ;
29 | this.udpAddr = InetAddress.getByName( group ) ;
30 |
31 | if ( mode == UDPAddressingMode.MULTICAST ) {
32 | MulticastSocket multicastSocket = new MulticastSocket() ;
33 | multicastSocket.setTimeToLive(ttl);
34 | this.socket = multicastSocket ;
35 | } else {
36 | this.socket = new DatagramSocket() ;
37 | }
38 | }
39 |
40 | /**
41 | * Closes the underlying socket to prevent socket leaks.
42 | */
43 | public void close() throws IOException {
44 | if (this.socket != null) {
45 | this.socket.close();
46 | }
47 | }
48 |
49 | /**
50 | * Sends the provided byte buffer
51 | * @param buf a buffer containing the message
52 | * @param len the num of bytes to send from the buffer
53 | * @throws Exception
54 | */
55 | protected void send( byte[] buf, int len) throws Exception {
56 | DatagramPacket packet = new DatagramPacket( buf, len, udpAddr, port) ;
57 |
58 | //log.log(Level.FINEST,"Sending message of length " + len);
59 |
60 | socket.send( packet ) ;
61 |
62 | }
63 |
64 |
65 | public abstract void announce(String name, String value,
66 | GMetricType type, String units, GMetricSlope slope, int tmax,
67 | int dmax, String groupName) throws Exception ;
68 |
69 | /**
70 | * @see java.lang.Object#finalize()
71 | */
72 | @Override
73 | protected void finalize() throws Throwable {
74 | // help gc out here a bit to prevent socket leaks
75 | close();
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/GMonitor.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j;
2 |
3 |
4 | import info.ganglia.gmetric4j.gmetric.GMetric;
5 | import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
6 | import info.ganglia.gmetric4j.gmetric.GMetricPublisher;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.concurrent.TimeUnit;
11 | // import java.util.logging.Logger;
12 |
13 | public class GMonitor {
14 |
15 | // private static Logger log =
16 | // Logger.getLogger(GMonitor.class.getName());
17 |
18 | private List samplers = new ArrayList();
19 | private boolean daemon = true ;
20 | private GMetric gmetric = null ;
21 |
22 | private GScheduler scheduler;
23 |
24 | public GMonitor() {
25 | scheduler = new DefaultGScheduler();
26 | }
27 |
28 | public GMonitor(GScheduler scheduler) {
29 | this.scheduler = scheduler;
30 | }
31 | /**
32 | * Starts the sampling
33 | */
34 | public void start() {
35 | scheduler.onStart();
36 | // log.info("Setting up " + samplers.size() + " samplers");
37 | for (GSampler s : samplers) {
38 | scheduler.scheduleAtFixedRate(s, s.getInitialDelay(), s.getDelay(), TimeUnit.SECONDS);
39 | }
40 | }
41 | /**
42 | * Stops the sampling of MBeans
43 | */
44 | public void stop() {
45 | scheduler.onStop();
46 | }
47 | /**
48 | * Adds a new MBeanSampler to be sampled
49 | * @param s the MBeanSampler
50 | */
51 | public void addSampler(GSampler s) {
52 | samplers.add(s);
53 | s.setPublisher( new GMetricPublisher(gmetric));
54 | }
55 | /**
56 | * Returns the daemon status of the scheduler thread
57 | * @return true if the scheduler thread is a daemon
58 | */
59 | public boolean isDaemon() {
60 | return daemon;
61 | }
62 | /**
63 | * Sets the scheduler daemon thread to be true/false. This only has an
64 | * effect before the start method is called.
65 | * @param daemon the requested scheduler daemon status
66 | */
67 | public void setDaemon(boolean daemon) {
68 | this.daemon = daemon;
69 | }
70 | public GMetric getGmetric() {
71 | return gmetric;
72 | }
73 | public void setGmetric(GMetric gmetric) {
74 | this.gmetric = gmetric;
75 | }
76 | /**
77 | * A log running, trivial main method for test purposes
78 | * premain method
79 | * @param args Not used
80 | */
81 | public static void main(String[] args) throws Exception {
82 |
83 | GMonitor a = null ;
84 | try {
85 | a = new GMonitor();
86 | a.setGmetric(new GMetric("239.2.11.71", 8649, UDPAddressingMode.MULTICAST, 1));
87 | a.addSampler(new CoreSampler());
88 | a.start();
89 | } catch ( Exception ex ) {
90 | //log.severe("Exception starting GMonitor");
91 | ex.printStackTrace();
92 | }
93 |
94 | while( true ) {
95 | Thread.sleep(1000*60*5);
96 | System.out.println("Test wakeup");
97 | }
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/test/java/info/ganglia/gmetric4j/gmetric/GMetricIT.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import static org.junit.Assert.*;
4 | import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
5 |
6 | import java.io.IOException;
7 |
8 | import org.junit.Before;
9 | import org.junit.Test;
10 |
11 | /**
12 | *
13 | */
14 | public class GMetricIT {
15 |
16 | private GMetric instance = null;
17 |
18 | @Before
19 | public void setUp() throws IOException {
20 | instance = new GMetric("239.2.11.71", 8649, UDPAddressingMode.MULTICAST, 1, true);
21 | }
22 |
23 | /**
24 | * Test of announce method, type String
25 | */
26 | @Test
27 | public void announceString() throws Exception {
28 | System.out.println("announceString");
29 | String name = "TEST1";
30 | String value = "BOING";
31 | GMetricType type = GMetricType.STRING;
32 | String units = "UNITS";
33 | GMetricSlope slope = GMetricSlope.BOTH;
34 | int tmax = 60;
35 | int dmax = 0;
36 | instance.announce(name, value, type, units, slope, tmax, dmax, "STRINGGROUP");
37 | GMetricResult.GMetricDetail readValue = GMetricResult.getGMetric(name);
38 | assertEquals(value, readValue.value);
39 | assertEquals(type.getGangliaType(), readValue.type);
40 | assertEquals(units, readValue.units);
41 | assertEquals( slope.name().toLowerCase(), readValue.slope);
42 | }
43 | /**
44 | * Test of announce method, type int
45 | */
46 | @Test
47 | public void announceInt() throws Exception {
48 | System.out.println("announceInt");
49 | String name = "TESTINT";
50 | int value = 334567 ;
51 | instance.announce(name, value, "INTGROUP" );
52 | GMetricResult.GMetricDetail readValue = GMetricResult.getGMetric(name);
53 | assertEquals(value, Integer.valueOf(readValue.value));
54 | assertEquals(GMetricType.INT32.getGangliaType(), readValue.type);
55 | }
56 | /**
57 | * Test of announce method, type long
58 | */
59 | @Test
60 | public void announceLong() throws Exception {
61 | System.out.println("announceLong");
62 | String name = "TESTLONG";
63 | long value = 334567 ;
64 | instance.announce(name, value, "LONGGROUP" );
65 | GMetricResult.GMetricDetail readValue = GMetricResult.getGMetric(name);
66 | assertEquals(value, Long.valueOf(readValue.value));
67 | assertEquals(GMetricType.DOUBLE.getGangliaType(), readValue.type);
68 | }
69 | /**
70 | * Test of announce method, type float
71 | */
72 | @Test
73 | public void announceFloat() throws Exception {
74 | System.out.println("announceFloat");
75 | String name = "TESTFLOAT";
76 | float value = 334567.543f ;
77 | instance.announce(name, value, "FLOATGROUP" );
78 | GMetricResult.GMetricDetail readValue = GMetricResult.getGMetric(name);
79 | assertEquals(value, Float.valueOf(readValue.value));
80 | assertEquals(GMetricType.FLOAT.getGangliaType(), readValue.type);
81 | }
82 | /**
83 | * Test of announce method, type double
84 | */
85 | @Test
86 | public void announceDouble() throws Exception {
87 | System.out.println("announceDouble");
88 | String name = "TESTDOUBLE";
89 | double value = 334567.54355555 ;
90 | instance.announce(name, value, "DOUBLEGROUP" );
91 | GMetricResult.GMetricDetail readValue = GMetricResult.getGMetric(name);
92 | assertEquals(value, Double.valueOf(readValue.value));
93 | assertEquals(GMetricType.DOUBLE.getGangliaType(), readValue.type);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v31x/Ganglia_value_msg.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 10/23/08 8:11 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v31x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_value_msg implements XdrAble {
11 | public int id;
12 | public Ganglia_gmetric_ushort gu_short;
13 | public Ganglia_gmetric_short gs_short;
14 | public Ganglia_gmetric_int gs_int;
15 | public Ganglia_gmetric_uint gu_int;
16 | public Ganglia_gmetric_string gstr;
17 | public Ganglia_gmetric_float gf;
18 | public Ganglia_gmetric_double gd;
19 | public Ganglia_uuid uuid;
20 |
21 | public Ganglia_value_msg() {
22 | }
23 |
24 | public Ganglia_value_msg(XdrDecodingStream xdr)
25 | throws OncRpcException, IOException {
26 | xdrDecode(xdr);
27 | }
28 |
29 | public void xdrEncode(XdrEncodingStream xdr)
30 | throws OncRpcException, IOException {
31 | xdr.xdrEncodeInt(id);
32 |
33 | int _id = id & 0xbf;
34 |
35 | switch ( _id ) {
36 | case Ganglia_msg_formats.gmetric_ushort:
37 | gu_short.xdrEncode(xdr);
38 | break;
39 | case Ganglia_msg_formats.gmetric_short:
40 | gs_short.xdrEncode(xdr);
41 | break;
42 | case Ganglia_msg_formats.gmetric_int:
43 | gs_int.xdrEncode(xdr);
44 | break;
45 | case Ganglia_msg_formats.gmetric_uint:
46 | gu_int.xdrEncode(xdr);
47 | break;
48 | case Ganglia_msg_formats.gmetric_string:
49 | gstr.xdrEncode(xdr);
50 | break;
51 | case Ganglia_msg_formats.gmetric_float:
52 | gf.xdrEncode(xdr);
53 | break;
54 | case Ganglia_msg_formats.gmetric_double:
55 | gd.xdrEncode(xdr);
56 | break;
57 | default:
58 | break;
59 | }
60 |
61 | if(hasUUID()) {
62 | uuid.xdrEncode(xdr);
63 | }
64 | }
65 |
66 | protected boolean hasUUID() {
67 | return ((id & 0x40) == 0x40);
68 | }
69 |
70 | public void xdrDecode(XdrDecodingStream xdr)
71 | throws OncRpcException, IOException {
72 | id = xdr.xdrDecodeInt();
73 |
74 | int _id = id & 0xbf;
75 |
76 | switch ( _id ) {
77 | case Ganglia_msg_formats.gmetric_ushort:
78 | gu_short = new Ganglia_gmetric_ushort(xdr);
79 | break;
80 | case Ganglia_msg_formats.gmetric_short:
81 | gs_short = new Ganglia_gmetric_short(xdr);
82 | break;
83 | case Ganglia_msg_formats.gmetric_int:
84 | gs_int = new Ganglia_gmetric_int(xdr);
85 | break;
86 | case Ganglia_msg_formats.gmetric_uint:
87 | gu_int = new Ganglia_gmetric_uint(xdr);
88 | break;
89 | case Ganglia_msg_formats.gmetric_string:
90 | gstr = new Ganglia_gmetric_string(xdr);
91 | break;
92 | case Ganglia_msg_formats.gmetric_float:
93 | gf = new Ganglia_gmetric_float(xdr);
94 | break;
95 | case Ganglia_msg_formats.gmetric_double:
96 | gd = new Ganglia_gmetric_double(xdr);
97 | break;
98 | default:
99 | break;
100 | }
101 |
102 | if(hasUUID()) {
103 | uuid = new Ganglia_uuid(xdr);
104 | }
105 | }
106 |
107 | }
108 | // End of Ganglia_value_msg.java
109 |
--------------------------------------------------------------------------------
/src/test/java/info/ganglia/gmetric4j/gmetric/GMetricResult.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.CharArrayReader;
5 | import java.io.InputStreamReader;
6 | import java.net.Socket;
7 |
8 | import javax.xml.parsers.SAXParser;
9 | import javax.xml.parsers.SAXParserFactory;
10 |
11 | import org.xml.sax.Attributes;
12 | import org.xml.sax.InputSource;
13 | import org.xml.sax.XMLReader;
14 | import org.xml.sax.helpers.DefaultHandler;
15 |
16 | public class GMetricResult {
17 |
18 |
19 | final private static int buffSize = 1024 * 50;
20 |
21 | public static GMetricDetail getGMetric(String metricName) throws Exception {
22 | // Open the socket, get the XML
23 | Socket gangliaXMLSocket = new Socket("localhost", 8649);
24 | BufferedReader in = new BufferedReader(new InputStreamReader(
25 | gangliaXMLSocket.getInputStream()));
26 | char[] charBuff = new char[buffSize];
27 | int in_buff = in.read(charBuff, 0, buffSize);
28 |
29 | System.out.println("in_buff = " + in_buff);
30 | System.out.println("charBuff length: " + charBuff.length);
31 |
32 | if (in_buff != -1) {
33 | System.out.println("End of file");
34 | }
35 |
36 | //System.out.println(charBuff);
37 |
38 | // Parse XML
39 | CharArrayReader car = new CharArrayReader(charBuff, 0, in_buff); // these two lines have to be here.
40 | BufferedReader br_car = new BufferedReader(car);
41 |
42 | SAXParserFactory spf = SAXParserFactory.newInstance();
43 | spf.setValidating(true);
44 |
45 | XMLReader xmlReader = null;
46 | SAXParser saxParser = spf.newSAXParser();
47 | xmlReader = saxParser.getXMLReader();
48 |
49 | // Set the ContentHandler of the XMLReader
50 | MyXMLHandler handler = new MyXMLHandler( metricName );
51 | xmlReader.setContentHandler(handler);
52 |
53 | // Set an ErrorHandler before parsing
54 | // xmlReader.setErrorHandler(new MyErrorHandler(System.err));
55 |
56 | xmlReader.parse(new InputSource(br_car));
57 | in.close();
58 | gangliaXMLSocket.close();
59 |
60 | return handler.getDetail() ;
61 | }
62 |
63 | private static class MyXMLHandler extends DefaultHandler {
64 |
65 | public void startElement(String uri,
66 | String localName,
67 | String qname,
68 | Attributes attributes) {
69 | //System.out.println(qname);
70 | if ( !qname.equals("METRIC"))
71 | return ;
72 | String name = attributes.getValue("","NAME");
73 | if ( name.equals(metricName)) {
74 | gmetricDetail = new GMetricDetail() ;
75 | gmetricDetail.metricName = metricName ;
76 | gmetricDetail.value = attributes.getValue("","VAL");
77 | gmetricDetail.type = attributes.getValue("","TYPE");
78 | gmetricDetail.units = attributes.getValue("","UNITS");
79 | gmetricDetail.dmax = attributes.getValue("","DMAX");
80 | gmetricDetail.tmax = attributes.getValue("","TMAX");
81 | gmetricDetail.slope = attributes.getValue("","SLOPE");
82 | System.out.println(gmetricDetail);
83 | }
84 |
85 | // process start of element
86 | }
87 |
88 | public void endElement(String uri,
89 | String localName,
90 | String qname) {
91 | // process end of element
92 | }
93 |
94 | public void characters(char[] ch,
95 | int start,
96 | int length) {
97 | // process characters
98 | }
99 |
100 | private String metricName = null ;
101 | private GMetricDetail gmetricDetail = null ;
102 |
103 | public MyXMLHandler( String metricName )
104 | throws org.xml.sax.SAXException {
105 | super();
106 | this.metricName = metricName ;
107 | }
108 |
109 | public GMetricDetail getDetail() {
110 | return gmetricDetail ;
111 | }
112 | }
113 |
114 | public static class GMetricDetail {
115 | public String metricName = null ;
116 | public String type = null ;
117 | public String units = null ;
118 | public String value = null ;
119 | public String dmax = null ;
120 | public String tmax = null ;
121 | public String slope = null ;
122 |
123 | public String toString() {
124 | StringBuilder b = new StringBuilder() ;
125 | b.append( metricName );
126 | b.append("/");
127 | b.append( type );
128 | b.append("/");
129 | b.append( value );
130 | b.append("/");
131 | b.append( units );
132 | b.append("/");
133 | b.append( dmax );
134 | b.append("/");
135 | b.append( tmax );
136 | b.append("/");
137 | b.append( slope );
138 | b.append("/");
139 | return b.toString() ;
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_message_formats.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | /**
8 | * Enumeration (collection of constants).
9 | */
10 | public interface Ganglia_message_formats {
11 |
12 | public static final int metric_user_defined = 0;
13 | public static final int metric_cpu_num = 0+1;
14 | public static final int metric_cpu_speed = 0+1+1;
15 | public static final int metric_mem_total = 0+1+1+1;
16 | public static final int metric_swap_total = 0+1+1+1+1;
17 | public static final int metric_boottime = 0+1+1+1+1+1;
18 | public static final int metric_sys_clock = 0+1+1+1+1+1+1;
19 | public static final int metric_machine_type = 0+1+1+1+1+1+1+1;
20 | public static final int metric_os_name = 0+1+1+1+1+1+1+1+1;
21 | public static final int metric_os_release = 0+1+1+1+1+1+1+1+1+1;
22 | public static final int metric_cpu_user = 0+1+1+1+1+1+1+1+1+1+1;
23 | public static final int metric_cpu_nice = 0+1+1+1+1+1+1+1+1+1+1+1;
24 | public static final int metric_cpu_system = 0+1+1+1+1+1+1+1+1+1+1+1+1;
25 | public static final int metric_cpu_idle = 0+1+1+1+1+1+1+1+1+1+1+1+1+1;
26 | public static final int metric_cpu_aidle = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
27 | public static final int metric_load_one = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
28 | public static final int metric_load_five = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
29 | public static final int metric_load_fifteen = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
30 | public static final int metric_proc_run = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
31 | public static final int metric_proc_total = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
32 | public static final int metric_mem_free = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
33 | public static final int metric_mem_shared = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
34 | public static final int metric_mem_buffers = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
35 | public static final int metric_mem_cached = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
36 | public static final int metric_swap_free = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
37 | public static final int metric_gexec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
38 | public static final int metric_heartbeat = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
39 | public static final int metric_mtu = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
40 | public static final int metric_location = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
41 | public static final int metric_bytes_out = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
42 | public static final int metric_bytes_in = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
43 | public static final int metric_pkts_in = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
44 | public static final int metric_pkts_out = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
45 | public static final int metric_disk_total = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
46 | public static final int metric_disk_free = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
47 | public static final int metric_part_max_used = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
48 | public static final int metric_cpu_wio = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
49 | public static final int metric_bread_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
50 | public static final int metric_bwrite_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
51 | public static final int metric_lread_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
52 | public static final int metric_lwrite_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
53 | public static final int metric_rcache = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
54 | public static final int metric_wcache = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
55 | public static final int metric_phread_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
56 | public static final int metric_phwrite_sec = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
57 | public static final int metric_cpu_intr = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
58 | public static final int metric_cpu_sintr = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
59 | public static final int metric_mem_arm = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
60 | public static final int metric_mem_rm = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
61 | public static final int metric_mem_avm = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
62 | public static final int metric_mem_vm = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
63 | public static final int GANGLIA_NUM_25_METRICS = 0+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
64 | public static final int spoof_metric = 4096;
65 | public static final int spoof_heartbeat = 4097;
66 |
67 | }
68 | // End of Ganglia_message_formats.java
69 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/Protocolv31x.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
4 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_extra_data;
5 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_gmetric_string;
6 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadata_message;
7 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadata_msg;
8 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadatadef;
9 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metric_id;
10 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats;
11 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_uuid;
12 | import info.ganglia.gmetric4j.xdr.v31x.Ganglia_value_msg;
13 |
14 | import java.io.IOException;
15 | import java.net.InetAddress;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 | import java.util.UUID;
19 |
20 | import org.acplt.oncrpc.XdrBufferEncodingStream;
21 |
22 |
23 | public class Protocolv31x extends AbstractProtocol {
24 | private static final int MAX_BUFFER_SIZE = 1024 ;
25 | private XdrBufferEncodingStream xdr = new XdrBufferEncodingStream( MAX_BUFFER_SIZE );
26 | private Map metricCounterMap = new HashMap();
27 | private int metadataMessageInterval;
28 | private UUID uuid;
29 | private boolean isSpoofName;
30 | private String localHostName;
31 |
32 | public Protocolv31x(String group, int port, UDPAddressingMode mode, int ttl,
33 | int metadataMessageInterval, UUID uuid, String spoofName) throws IOException {
34 | super(group, port, mode, ttl);
35 | this.metadataMessageInterval = metadataMessageInterval ;
36 | this.uuid = uuid;
37 | if (spoofName != null && !spoofName.isEmpty()) {
38 | this.isSpoofName = true;
39 | this.localHostName = spoofName;
40 | } else {
41 | this.isSpoofName = false;
42 | this.localHostName = InetAddress.getLocalHost().getHostName();
43 | }
44 | }
45 |
46 | private boolean isTimeToSendMetadata( String metricName ) {
47 | boolean ret = false ;
48 | Integer counter = metricCounterMap.get(metricName);
49 | if (counter == null) {
50 | counter = 0;
51 | ret = true ;
52 | } else {
53 | counter++;
54 | if ( counter >= metadataMessageInterval ) {
55 | counter = 0 ;
56 | ret = true ;
57 | }
58 | }
59 | metricCounterMap.put(metricName, counter);
60 | return ret ;
61 | }
62 | @Override
63 | public void announce( String name, String value,
64 | GMetricType type, String units, GMetricSlope slope, int tmax,
65 | int dmax, String groupName) throws Exception {
66 |
67 | Ganglia_metric_id metric_id = new Ganglia_metric_id();
68 | metric_id.spoof = isSpoofName;
69 | metric_id.host = localHostName;
70 | metric_id.name = name;
71 |
72 | if ( isTimeToSendMetadata( name ) ) {
73 | encodeGMetric( metric_id, name, value, type, units, slope, tmax, dmax, groupName );
74 | send(xdr.getXdrData(),xdr.getXdrLength());
75 | }
76 | encodeGValue( metric_id, value );
77 | send(xdr.getXdrData(),xdr.getXdrLength());
78 | }
79 | /**
80 | * Encodes the metric using the classes generated by remotetea
81 | */
82 | private void encodeGMetric(
83 | Ganglia_metric_id metric_id,
84 | String name,
85 | String value,
86 | GMetricType type,
87 | String units,
88 | GMetricSlope slope,
89 | int tmax,
90 | int dmax,
91 | String groupName)
92 | throws Exception {
93 | Ganglia_metadata_message metadata_message = new Ganglia_metadata_message() ;
94 | Ganglia_extra_data[] extra_data_array = new Ganglia_extra_data[3];
95 | Ganglia_extra_data extra_data1 = new Ganglia_extra_data();
96 | extra_data_array[0] = extra_data1;
97 | extra_data1.name = "GROUP";
98 | extra_data1.data = groupName;
99 | Ganglia_extra_data extra_data2 = new Ganglia_extra_data();
100 | extra_data_array[1] = extra_data2;
101 | extra_data2.name = "TITLE";
102 | extra_data2.data = name;
103 | Ganglia_extra_data extra_data3 = new Ganglia_extra_data();
104 | extra_data_array[2] = extra_data3;
105 | extra_data3.name = "DESC";
106 | extra_data3.data = name;
107 |
108 | metadata_message.metadata = extra_data_array ;
109 | metadata_message.name = name ;
110 | metadata_message.type = type.getGangliaType() ;
111 | metadata_message.units = units ;
112 | metadata_message.slope = slope.getGangliaSlope() ;
113 | metadata_message.tmax = tmax ;
114 | metadata_message.dmax = dmax ;
115 |
116 | Ganglia_metadatadef metadatadef = new Ganglia_metadatadef();
117 | metadatadef.metric_id = metric_id;
118 | metadatadef.metric = metadata_message;
119 |
120 | Ganglia_metadata_msg metadata_msg = new Ganglia_metadata_msg();
121 | metadata_msg.id = Ganglia_msg_formats.gmetadata_full;
122 | if(uuid != null) {
123 | metadata_msg.id |= 0x40;
124 | Ganglia_uuid _uuid = new Ganglia_uuid();
125 | _uuid.uuid = uuid;
126 | metadata_msg.uuid = _uuid;
127 | }
128 | metadata_msg.gfull = metadatadef;
129 |
130 | xdr.beginEncoding(udpAddr, port) ;
131 | metadata_msg.xdrEncode(xdr);
132 | xdr.endEncoding();
133 | }
134 |
135 | private void encodeGValue(Ganglia_metric_id metric_id, String value)
136 | throws Exception {
137 | Ganglia_value_msg value_msg = new Ganglia_value_msg();
138 | value_msg.id = Ganglia_msg_formats.gmetric_string;
139 | if(uuid != null) {
140 | value_msg.id |= 0x40;
141 | Ganglia_uuid _uuid = new Ganglia_uuid();
142 | _uuid.uuid = uuid;
143 | value_msg.uuid = _uuid;
144 | }
145 | Ganglia_gmetric_string str = new Ganglia_gmetric_string();
146 | str.str = value;
147 | str.metric_id = metric_id;
148 | str.fmt = "%s";
149 | value_msg.gstr = str;
150 | xdr.beginEncoding(udpAddr, port) ;
151 | value_msg.xdrEncode(xdr);
152 | xdr.endEncoding();
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | info.ganglia.gmetric4j
5 | gmetric4j
6 | gmetric4j
7 | bundle
8 | 1.0.10
9 | JVM instrumentation to Ganglia
10 | http://github.com/ganglia/gmetric4j
11 |
12 |
13 | The MIT License
14 | http://www.opensource.org/licenses/mit-license.php
15 | repo
16 |
17 |
18 |
19 | scm:git:git@github.com:ganglia/gmetric4j.git
20 | scm:git:git@github.com:ganglia/gmetric4j.git
21 | scm:git:git@github.com:ganglia/gmetric4j.git
22 |
23 |
24 |
25 | humphrej
26 | Jasper Humphrey
27 | jasper521@googlemail.com
28 |
29 |
30 | pocock
31 | Daniel Pocock
32 | daniel@pocock.pro
33 | http://danielpocock.com
34 |
35 |
36 |
37 |
38 | junit
39 | junit
40 | 4.1
41 | jar
42 | test
43 |
44 |
45 | org.acplt.remotetea
46 | remotetea-oncrpc
47 | 1.1.2
48 |
49 |
50 |
51 | org.sonatype.oss
52 | oss-parent
53 | 7
54 |
55 |
56 |
57 |
58 | org.apache.maven.plugins
59 | maven-compiler-plugin
60 | 2.5.1
61 |
62 | 1.5
63 | 1.5
64 |
65 |
66 |
67 | org.apache.maven.plugins
68 | maven-jar-plugin
69 | 2.4
70 |
71 |
72 | src/main/resources/META-INF/MANIFEST.MF
73 |
74 |
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-jar-plugin
79 | 2.4
80 |
81 |
82 |
83 | test-jar
84 |
85 |
86 |
87 |
88 |
89 | org.apache.maven.plugins
90 | maven-source-plugin
91 |
92 |
93 | attach-sources
94 |
95 | jar
96 |
97 |
98 |
99 |
100 |
101 | org.apache.maven.plugins
102 | maven-javadoc-plugin
103 |
104 |
105 | attach-javadocs
106 |
107 | jar
108 |
109 |
110 |
111 |
112 |
113 | org.apache.maven.plugins
114 | maven-assembly-plugin
115 | 2.3
116 |
117 |
118 | src/main/assembly/bin.xml
119 |
120 |
121 |
122 |
123 | org.apache.felix
124 | maven-bundle-plugin
125 | 2.3.7
126 | true
127 |
128 |
129 | ${project.artifactId}
130 | ${project.groupId}.${project.artifactId}
131 | info.ganglia.gmetric4j.*
132 |
133 | *
134 |
135 | gmetric4j
136 | ${project.version}
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | org.codehaus.mojo
146 | findbugs-maven-plugin
147 | 2.5.2
148 |
149 |
150 | org.apache.maven.plugins
151 | maven-javadoc-plugin
152 |
153 |
154 |
155 |
156 |
157 | release-sign-artifacts
158 |
159 |
160 | performRelease
161 | true
162 |
163 |
164 |
165 |
166 |
167 | org.apache.maven.plugins
168 | maven-gpg-plugin
169 | 1.4
170 |
171 |
172 | sign-artifacts
173 | verify
174 |
175 | sign
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/xdr/v30x/Ganglia_message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Automatically generated by jrpcgen 1.0.5 on 3/30/08 8:06 PM
3 | * jrpcgen is part of the "Remote Tea" ONC/RPC package for Java
4 | * See http://remotetea.sourceforge.net for details
5 | */
6 | package info.ganglia.gmetric4j.xdr.v30x;
7 | import org.acplt.oncrpc.*;
8 | import java.io.IOException;
9 |
10 | public class Ganglia_message implements XdrAble {
11 | public int id;
12 | public Ganglia_gmetric_message gmetric;
13 | public Ganglia_spoof_message spmetric;
14 | public Ganglia_spoof_header spheader;
15 | public short u_short1;
16 | public int u_int1;
17 | public String str;
18 | public float f;
19 | public double d;
20 |
21 | public Ganglia_message() {
22 | }
23 |
24 | public Ganglia_message(XdrDecodingStream xdr)
25 | throws OncRpcException, IOException {
26 | xdrDecode(xdr);
27 | }
28 |
29 | public void xdrEncode(XdrEncodingStream xdr)
30 | throws OncRpcException, IOException {
31 | xdr.xdrEncodeInt(id);
32 | switch ( id ) {
33 | case Ganglia_message_formats.metric_user_defined:
34 | gmetric.xdrEncode(xdr);
35 | break;
36 | case Ganglia_message_formats.spoof_metric:
37 | spmetric.xdrEncode(xdr);
38 | break;
39 | case Ganglia_message_formats.spoof_heartbeat:
40 | spheader.xdrEncode(xdr);
41 | break;
42 | case Ganglia_message_formats.metric_cpu_num:
43 | xdr.xdrEncodeShort(u_short1);
44 | break;
45 | case Ganglia_message_formats.metric_cpu_speed:
46 | case Ganglia_message_formats.metric_mem_total:
47 | case Ganglia_message_formats.metric_swap_total:
48 | case Ganglia_message_formats.metric_boottime:
49 | case Ganglia_message_formats.metric_sys_clock:
50 | case Ganglia_message_formats.metric_proc_run:
51 | case Ganglia_message_formats.metric_proc_total:
52 | case Ganglia_message_formats.metric_mem_free:
53 | case Ganglia_message_formats.metric_mem_shared:
54 | case Ganglia_message_formats.metric_mem_buffers:
55 | case Ganglia_message_formats.metric_mem_cached:
56 | case Ganglia_message_formats.metric_swap_free:
57 | case Ganglia_message_formats.metric_heartbeat:
58 | case Ganglia_message_formats.metric_mtu:
59 | case Ganglia_message_formats.metric_mem_arm:
60 | case Ganglia_message_formats.metric_mem_rm:
61 | case Ganglia_message_formats.metric_mem_avm:
62 | case Ganglia_message_formats.metric_mem_vm:
63 | xdr.xdrEncodeInt(u_int1);
64 | break;
65 | case Ganglia_message_formats.metric_machine_type:
66 | case Ganglia_message_formats.metric_os_name:
67 | case Ganglia_message_formats.metric_os_release:
68 | case Ganglia_message_formats.metric_gexec:
69 | case Ganglia_message_formats.metric_location:
70 | xdr.xdrEncodeString(str);
71 | break;
72 | case Ganglia_message_formats.metric_cpu_user:
73 | case Ganglia_message_formats.metric_cpu_nice:
74 | case Ganglia_message_formats.metric_cpu_system:
75 | case Ganglia_message_formats.metric_cpu_idle:
76 | case Ganglia_message_formats.metric_cpu_aidle:
77 | case Ganglia_message_formats.metric_load_one:
78 | case Ganglia_message_formats.metric_load_five:
79 | case Ganglia_message_formats.metric_load_fifteen:
80 | case Ganglia_message_formats.metric_bytes_in:
81 | case Ganglia_message_formats.metric_bytes_out:
82 | case Ganglia_message_formats.metric_pkts_in:
83 | case Ganglia_message_formats.metric_pkts_out:
84 | case Ganglia_message_formats.metric_part_max_used:
85 | case Ganglia_message_formats.metric_cpu_wio:
86 | case Ganglia_message_formats.metric_bread_sec:
87 | case Ganglia_message_formats.metric_bwrite_sec:
88 | case Ganglia_message_formats.metric_lread_sec:
89 | case Ganglia_message_formats.metric_lwrite_sec:
90 | case Ganglia_message_formats.metric_rcache:
91 | case Ganglia_message_formats.metric_wcache:
92 | case Ganglia_message_formats.metric_phread_sec:
93 | case Ganglia_message_formats.metric_phwrite_sec:
94 | case Ganglia_message_formats.metric_cpu_intr:
95 | case Ganglia_message_formats.metric_cpu_sintr:
96 | xdr.xdrEncodeFloat(f);
97 | break;
98 | case Ganglia_message_formats.metric_disk_total:
99 | case Ganglia_message_formats.metric_disk_free:
100 | xdr.xdrEncodeDouble(d);
101 | break;
102 | default:
103 | break;
104 | }
105 | }
106 |
107 | public void xdrDecode(XdrDecodingStream xdr)
108 | throws OncRpcException, IOException {
109 | id = xdr.xdrDecodeInt();
110 | switch ( id ) {
111 | case Ganglia_message_formats.metric_user_defined:
112 | gmetric = new Ganglia_gmetric_message(xdr);
113 | break;
114 | case Ganglia_message_formats.spoof_metric:
115 | spmetric = new Ganglia_spoof_message(xdr);
116 | break;
117 | case Ganglia_message_formats.spoof_heartbeat:
118 | spheader = new Ganglia_spoof_header(xdr);
119 | break;
120 | case Ganglia_message_formats.metric_cpu_num:
121 | u_short1 = xdr.xdrDecodeShort();
122 | break;
123 | case Ganglia_message_formats.metric_cpu_speed:
124 | case Ganglia_message_formats.metric_mem_total:
125 | case Ganglia_message_formats.metric_swap_total:
126 | case Ganglia_message_formats.metric_boottime:
127 | case Ganglia_message_formats.metric_sys_clock:
128 | case Ganglia_message_formats.metric_proc_run:
129 | case Ganglia_message_formats.metric_proc_total:
130 | case Ganglia_message_formats.metric_mem_free:
131 | case Ganglia_message_formats.metric_mem_shared:
132 | case Ganglia_message_formats.metric_mem_buffers:
133 | case Ganglia_message_formats.metric_mem_cached:
134 | case Ganglia_message_formats.metric_swap_free:
135 | case Ganglia_message_formats.metric_heartbeat:
136 | case Ganglia_message_formats.metric_mtu:
137 | case Ganglia_message_formats.metric_mem_arm:
138 | case Ganglia_message_formats.metric_mem_rm:
139 | case Ganglia_message_formats.metric_mem_avm:
140 | case Ganglia_message_formats.metric_mem_vm:
141 | u_int1 = xdr.xdrDecodeInt();
142 | break;
143 | case Ganglia_message_formats.metric_machine_type:
144 | case Ganglia_message_formats.metric_os_name:
145 | case Ganglia_message_formats.metric_os_release:
146 | case Ganglia_message_formats.metric_gexec:
147 | case Ganglia_message_formats.metric_location:
148 | str = xdr.xdrDecodeString();
149 | break;
150 | case Ganglia_message_formats.metric_cpu_user:
151 | case Ganglia_message_formats.metric_cpu_nice:
152 | case Ganglia_message_formats.metric_cpu_system:
153 | case Ganglia_message_formats.metric_cpu_idle:
154 | case Ganglia_message_formats.metric_cpu_aidle:
155 | case Ganglia_message_formats.metric_load_one:
156 | case Ganglia_message_formats.metric_load_five:
157 | case Ganglia_message_formats.metric_load_fifteen:
158 | case Ganglia_message_formats.metric_bytes_in:
159 | case Ganglia_message_formats.metric_bytes_out:
160 | case Ganglia_message_formats.metric_pkts_in:
161 | case Ganglia_message_formats.metric_pkts_out:
162 | case Ganglia_message_formats.metric_part_max_used:
163 | case Ganglia_message_formats.metric_cpu_wio:
164 | case Ganglia_message_formats.metric_bread_sec:
165 | case Ganglia_message_formats.metric_bwrite_sec:
166 | case Ganglia_message_formats.metric_lread_sec:
167 | case Ganglia_message_formats.metric_lwrite_sec:
168 | case Ganglia_message_formats.metric_rcache:
169 | case Ganglia_message_formats.metric_wcache:
170 | case Ganglia_message_formats.metric_phread_sec:
171 | case Ganglia_message_formats.metric_phwrite_sec:
172 | case Ganglia_message_formats.metric_cpu_intr:
173 | case Ganglia_message_formats.metric_cpu_sintr:
174 | f = xdr.xdrDecodeFloat();
175 | break;
176 | case Ganglia_message_formats.metric_disk_total:
177 | case Ganglia_message_formats.metric_disk_free:
178 | d = xdr.xdrDecodeDouble();
179 | break;
180 | default:
181 | break;
182 | }
183 | }
184 |
185 | }
186 | // End of Ganglia_message.java
187 |
--------------------------------------------------------------------------------
/src/main/java/info/ganglia/gmetric4j/gmetric/GMetric.java:
--------------------------------------------------------------------------------
1 | package info.ganglia.gmetric4j.gmetric;
2 |
3 | import java.io.Closeable;
4 | import java.io.IOException;
5 | import java.net.InetAddress;
6 | import java.util.UUID;
7 |
8 | /**
9 | * Implements the Ganglia gmetric command in java
10 | */
11 | public class GMetric implements Closeable {
12 | public enum UDPAddressingMode {
13 | MULTICAST, UNICAST;
14 |
15 | public static UDPAddressingMode getModeForAddress(String addr) throws IOException {
16 | InetAddress _addr = InetAddress.getByName(addr);
17 |
18 | if (_addr.isMulticastAddress())
19 | return MULTICAST;
20 |
21 | return UNICAST;
22 | }
23 | };
24 |
25 | private Protocol protocol;
26 |
27 | /**
28 | * Constructs a GMetric
29 | *
30 | * @param group
31 | * the host/group to send the event to
32 | * @param port
33 | * the port to send the event to
34 | * @param mode
35 | * the mode
36 | * @param ttl
37 | * time to live value
38 | */
39 | public GMetric(String group, int port, UDPAddressingMode mode, int ttl) throws IOException {
40 | this(group, port, mode, ttl, true);
41 | }
42 |
43 | /**
44 | * Constructs a GMetric
45 | *
46 | * @param group
47 | * the host/group to send the event to
48 | * @param port
49 | * the port to send the event to
50 | * @param mode
51 | * adressing mode to be used (UNICAST/MULTICAST)
52 | * @param ttl
53 | * time to live value
54 | * @param ganglia311
55 | * protocol version true=v3.1, false=v3.0
56 | */
57 | public GMetric(String group, int port, UDPAddressingMode mode, int ttl, boolean ganglia311) throws IOException {
58 | this(group, port, mode, ttl, ganglia311, null);
59 | }
60 |
61 | /**
62 | * Constructs a GMetric
63 | *
64 | * @param group
65 | * the host/group to send the event to
66 | * @param port
67 | * the port to send the event to
68 | * @param mode
69 | * adressing mode to be used (UNICAST/MULTICAST)
70 | * @param ttl
71 | * time to live value
72 | * @param ganglia311
73 | * protocol version true=v3.1, false=v3.0
74 | * @param uuid
75 | * uuid for the host
76 | */
77 | public GMetric(String group, int port, UDPAddressingMode mode, int ttl, boolean ganglia311, UUID uuid)
78 | throws IOException {
79 | if (!ganglia311)
80 | this.protocol = new Protocolv30x(group, port, mode, ttl);
81 | else
82 | this.protocol = new Protocolv31x(group, port, mode, ttl, 5, uuid, null);
83 | }
84 |
85 | /**
86 | * Constructs a GMetric
87 | *
88 | * @param group
89 | * the host/group to send the event to
90 | * @param port
91 | * the port to send the event to
92 | * @param mode
93 | * adressing mode to be used (UNICAST/MULTICAST)
94 | * @param ttl
95 | * time to live value
96 | * @param ganglia311
97 | * protocol version true=v3.1, false=v3.0
98 | * @param uuid
99 | * uuid for the host
100 | * @param spoof
101 | * spoofing information IP:hostname
102 | */
103 | public GMetric(String group, int port, UDPAddressingMode mode, int ttl, boolean ganglia311, UUID uuid, String spoof)
104 | throws IOException {
105 | if (!ganglia311)
106 | this.protocol = new Protocolv30x(group, port, mode, ttl);
107 | else
108 | this.protocol = new Protocolv31x(group, port, mode, ttl, 5, uuid, spoof);
109 | }
110 |
111 | /**
112 | * The Ganglia Metric Client (gmetric) announces a metric
113 | *
114 | * @param name
115 | * Name of the metric
116 | * @param value
117 | * Value of the metric
118 | * @param type
119 | * Type of the metric. Either
120 | * string|int8|uint8|int16|uint16|int32|uint32|float|double
121 | * @param units
122 | * Unit of measure for the value
123 | * @param slope
124 | * Either zero|positive|negative|both
125 | * @param tmax
126 | * The maximum time in seconds between gmetric calls
127 | * @param dmax
128 | * The lifetime in seconds of this metric
129 | * @param group
130 | * Group Name of the metric
131 | * @throws java.lang.Exception
132 | */
133 | public void announce(String name, String value, GMetricType type, String units, GMetricSlope slope, int tmax,
134 | int dmax, String group) throws GangliaException {
135 | try {
136 | protocol.announce(name, value, type, units, slope, tmax, dmax, group);
137 | } catch (Exception ex) {
138 | throw new GangliaException("Exception announcing metric", ex);
139 | }
140 | }
141 |
142 | /**
143 | * Announces a metric
144 | *
145 | * @param name
146 | * Name of the metric
147 | * @param value
148 | * Value of the metric
149 | * @param group
150 | * Group Name of the metric
151 | * @throws ganglia.GangliaException
152 | */
153 | public void announce(String name, int value, String group) throws GangliaException {
154 | this.announce(name, Integer.toString(value), GMetricType.INT32, "", GMetricSlope.BOTH, 60, 0, group);
155 | }
156 |
157 | /**
158 | * Announces a metric
159 | *
160 | * @param name
161 | * Name of the metric
162 | * @param value
163 | * Value of the metric
164 | * @param group
165 | * Group Name of the metric
166 | * @throws ganglia.GangliaException
167 | */
168 | public void announce(String name, long value, String group) throws GangliaException {
169 | this.announce(name, Long.toString(value), GMetricType.DOUBLE, "", GMetricSlope.BOTH, 60, 0, group);
170 | }
171 |
172 | /**
173 | * Announces a metric
174 | *
175 | * @param name
176 | * Name of the metric
177 | * @param value
178 | * Value of the metric
179 | * @param group
180 | * Group Name of the metric
181 | * @throws ganglia.GangliaException
182 | */
183 | public void announce(String name, float value, String group) throws GangliaException {
184 | this.announce(name, Float.toString(value), GMetricType.FLOAT, "", GMetricSlope.BOTH, 60, 0, group);
185 | }
186 |
187 | /**
188 | * Announces a metric
189 | *
190 | * @param name
191 | * Name of the metric
192 | * @param value
193 | * Value of the metric
194 | * @param group
195 | * Group Name of the metric
196 | * @throws ganglia.GangliaException
197 | */
198 | public void announce(String name, double value, String group) throws GangliaException {
199 | this.announce(name, Double.toString(value), GMetricType.DOUBLE, "", GMetricSlope.BOTH, 60, 0, group);
200 | }
201 |
202 | /**
203 | * Closes the underlying protocol.
204 | *
205 | * @throws IOException
206 | */
207 | public void close() throws IOException {
208 | if (this.protocol != null) {
209 | this.protocol.close();
210 | }
211 | }
212 |
213 | /**
214 | * @see java.lang.Object#finalize()
215 | */
216 | @Override
217 | protected void finalize() throws Throwable {
218 | // help gc out here a bit to prevent socket leaks
219 | close();
220 | }
221 |
222 | /**
223 | * Main method that sends a test metric
224 | *
225 | * @param args
226 | * @throws IOException
227 | */
228 | public static void main(String[] args) throws IOException {
229 | GMetric gm = null;
230 | try {
231 | gm = new GMetric("239.2.11.71", 8649, UDPAddressingMode.MULTICAST, 1);
232 | // gm.announce("heartbeat", "0", GMetricType.UINT32, "",
233 | // GMetricSlope.ZERO, 0, 0, "core");
234 | gm.announce("BOILINGPOINT", "100", GMetricType.STRING, "CELSIUS", GMetricSlope.BOTH, 0, 0, "TESTGROUP");
235 | gm.announce("INTTEST", (int) Integer.MAX_VALUE, "TESTGROUP");
236 | gm.announce("LONGTEST", (long) Long.MAX_VALUE, "TESTGROUP");
237 | gm.announce("FLOATTEST", (float) Float.MAX_VALUE, "TESTGROUP");
238 | gm.announce("DOUBLETEST", (double) Double.MAX_VALUE, "TESTGROUP");
239 | } catch (Exception ex) {
240 | ex.printStackTrace();
241 | } finally {
242 | gm.close();
243 | }
244 | }
245 | }
246 |
--------------------------------------------------------------------------------