pax_global_header 0000666 0000000 0000000 00000000064 12305130526 0014507 g ustar 00root root 0000000 0000000 52 comment=417ef73d4dea2c11a7f022df0995af68997a0dcf
jmxetric-1.0.6/ 0000775 0000000 0000000 00000000000 12305130526 0013340 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/.classpath 0000664 0000000 0000000 00000003233 12305130526 0015324 0 ustar 00root root 0000000 0000000
jmxetric-1.0.6/.gitignore 0000664 0000000 0000000 00000000022 12305130526 0015322 0 ustar 00root root 0000000 0000000 target
/.settings
jmxetric-1.0.6/.project 0000664 0000000 0000000 00000001305 12305130526 0015006 0 ustar 00root root 0000000 0000000
jmxetricorg.eclipse.jdt.core.javabuilderorg.maven.ide.eclipse.maven2Builderorg.eclipse.m2e.core.maven2Builderorg.eclipse.m2e.core.maven2Natureorg.maven.ide.eclipse.maven2Natureorg.eclipse.jdt.core.javanature
jmxetric-1.0.6/.travis.yml 0000664 0000000 0000000 00000000060 12305130526 0015445 0 ustar 00root root 0000000 0000000 language: java
jdk:
- oraclejdk7
- openjdk6
jmxetric-1.0.6/CHANGES 0000664 0000000 0000000 00000002452 12305130526 0014336 0 ustar 00root root 0000000 0000000 Changes in version 1.0.0
* Tweak dependencies to include gmetric4j (not yet in maven central)
* Update docs to refer to new home on github
* rename package from jmxetric -> info.ganglia.jmxetric
Changes in version 0.0.5
#23 Publishing JMXetric jar file to a public Maven repo
Changes in version 0.0.4
#10 Attributes with composite values are not published correctly
#11 If an attribute value is null, an exception is thrown as MBeanSampler attempts to publish it.
Changes in version 0.0.3
Please note that the config file format has changed to support mbeans with a dot in the name. See the README or example file.
* Built using Maven
* #2 Compiled to target JVM 1.5 for legacy support
* #3 NPE if element has no "pname" attribute specified
* #4 Attributes with embedded "."s improperly parsed
* #5 Uninitialised mbeans cause exception on startup
* #7 Incorrect javaagent option sample in README
* #6 Slope is not defined in the config file so cannot use ganglia/rrd counter attributes
* Suppress exception (keep warning) in the event the mbean is slow to initialise on startup, also add initial delay parameter to config file
Changes in version 0.0.2
* Added support for the ganglia 3.1.* wire format.
* Added support for UDP unicast.
Thanks to Sam Tunnicliffe and Malcolm Landon for the patch.
jmxetric-1.0.6/COPYING 0000664 0000000 0000000 00000002050 12305130526 0014370 0 ustar 00root root 0000000 0000000 Copyright (c) 2008-2011 Jasper Humphrey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
jmxetric-1.0.6/README 0000664 0000000 0000000 00000014612 12305130526 0014224 0 ustar 00root root 0000000 0000000 Name
jmxetric - jvm instrumentation to ganglia
Version
jmxetric 1.0.4
The latest version of this software and document will always be found at
https://github.com/ganglia/jmxetric
Synopsis
JMXetric is a 100% java, configurable JVM agent that periodically polls
MBean attributes and reports their values to Ganglia.
Project goals are that JMXetric should be
* configurable (xml)
* lightweight (small memory and cpu footprint)
* standalone (not depend on third party libraries)
The gmetric protocol implementation uses classes generated by the LGPL
remotetea project (http://remotetea.sf.net).
Installation
Unzip the archive
Add the following to your JVM
java -javaagent:/jmxetric.jar=host="",port="",config="",process="" usual.java.main.class
Demo / Quickstart
1) Ensure you have a gmond running on localhost:8649
2) Download jmxetric-1.0.4.jar, gmetric4j-1.0.3.jar and oncrpc-1.0.7.jar
all into the same directory.
3) cd into the directory
2) In bash do:
$ export config="host=localhost,port=8649,wireformat31x=true,config=etc/jmxetric.xml"
$ java -Djava.util.logging.config.file=etc/logging.properties \
-javaagent:jmxetric-1.0.4.jar=$config jmxetric.JMXetricAgent
Configuration
The configuration of JMXetric is loaded from an xml file in the working
directory of the shell, or specified as an argument to the JVM agent
("config"). The JVM agent arguments can also be used to specify the
following:
host, port The multicast address that is used to publish metrics to the
ganglia gmond process
config The full path to the config file (jmxetric.xml)
mode The UDP addressing mode, either multicast or unicast (default multicast)
wireformat31x True if the ganglia v3.1.x wire format should be used (default false)
spoof An IP:hostname pair that will be used to spoof the metric host information.
(default: no spoofing, i.e., local hostname reported by OS)
process A name that is prefixed to the metric name before publication
(so that metrics from different JVMs on the same host can be
determined)
XML Configuation File
JMXetric schedules a number of "samples", that queries a list of "mbeans",
that have "attributes".
Element/Attribute Description
mbean/name The name of the mbean to query
mbean/pname The metric name for this mbean. This should always be
used as ganglia/rrdtool misbehaves if the filename is
"unusual".
attribute/nam The name of the attribute. This can have two levels
for the case of a composite key see below example for
attribute "HeapMemoryUsage", key "used"
attribute/type The type used for the metric in ganglia
attribute/units The units used for the metric in ganglia
attribute/pname The metric name for this attribute
An example file:
]>
Support/Queries
I'm sure there are bugs and I'm sure there are some mbeans that can't be
sampled currently. If you find some, then let me know jasper521 at gmail
If you are using this at all, then I'd love to know!
Copyright
Copyright (C) 2008-2011 Jasper Humphrey
Copyright (C) 2011-2013 Daniel Pocock http://danielpocock.com
Authors
Jasper Humphrey jasper521 at gmail Developer
jmxetric-1.0.6/etc/ 0000775 0000000 0000000 00000000000 12305130526 0014113 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/etc/jmxetric.xml 0000664 0000000 0000000 00000005707 12305130526 0016473 0 ustar 00root root 0000000 0000000
]>
jmxetric-1.0.6/etc/logging.properties 0000664 0000000 0000000 00000001111 12305130526 0017651 0 ustar 00root root 0000000 0000000 ############################################################
# Default Logging Configuration File
#
# You can use a different file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
############################################################
handlers= java.util.logging.ConsoleHandler
.level=INFO
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
info.ganglia.jmxetric.level=ALL
info.ganglia.gmetric4j.level=ALL
jmxetric-1.0.6/pom.xml 0000664 0000000 0000000 00000012205 12305130526 0014655 0 ustar 00root root 0000000 0000000
4.0.0info.ganglia.jmxetricjmxetricJMXetricjar1.0.6JVM instrumentation to Gangliahttp://github.com/ganglia/jmxetricThe MIT Licensehttp://www.opensource.org/licenses/mit-license.phpreposcm:git:git@github.com:ganglia/jmxetric.gitscm:git:git@github.com:ganglia/jmxetric.gitscm:git:git@github.com:ganglia/jmxetric.githumphrejJasper Humphreyjasper521@googlemail.compocockDaniel Pocockdaniel@pocock.com.au1.0.41.0.7info.ganglia.gmetric4jgmetric4j${gmetric4j.version}jarinfo.ganglia.gmetric4jgmetric4j${gmetric4j.version}test-jartestjunitjunit4.1jartestorg.acpltoncrpc${oncrpc.version}org.sonatype.ossoss-parent7src/main/resourcestrueorg.apache.maven.pluginsmaven-compiler-plugin2.5.11.51.5org.apache.maven.pluginsmaven-jar-plugin2.4target/classes/META-INF/MANIFEST.MForg.apache.maven.pluginsmaven-source-pluginattach-sourcesjarorg.apache.maven.pluginsmaven-javadoc-pluginattach-javadocsjarorg.apache.maven.pluginsmaven-assembly-plugin2.3src/main/assembly/bin.xmlorg.codehaus.mojofindbugs-maven-plugin2.5.2org.apache.maven.pluginsmaven-javadoc-pluginrelease-sign-artifactsperformReleasetrueorg.apache.maven.pluginsmaven-gpg-plugin1.4sign-artifactsverifysign
jmxetric-1.0.6/src/ 0000775 0000000 0000000 00000000000 12305130526 0014127 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/ 0000775 0000000 0000000 00000000000 12305130526 0015053 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/assembly/ 0000775 0000000 0000000 00000000000 12305130526 0016672 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/assembly/bin.xml 0000664 0000000 0000000 00000001215 12305130526 0020163 0 ustar 00root root 0000000 0000000 binziptruefalseetc/*README*LICENSE*NOTICE*COPYING*CHANGES*
jmxetric-1.0.6/src/main/java/ 0000775 0000000 0000000 00000000000 12305130526 0015774 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/java/info/ 0000775 0000000 0000000 00000000000 12305130526 0016727 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/java/info/ganglia/ 0000775 0000000 0000000 00000000000 12305130526 0020331 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/ 0000775 0000000 0000000 00000000000 12305130526 0022156 5 ustar 00root root 0000000 0000000 jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/JMXetricAgent.java 0000664 0000000 0000000 00000003732 12305130526 0025472 0 ustar 00root root 0000000 0000000 package info.ganglia.jmxetric;
import info.ganglia.gmetric4j.GMonitor;
import java.lang.instrument.Instrumentation;
// import java.util.logging.Logger;
/**
* JMXetricAgent is a JVM agent that will sample MBean attributes on a periodic basis,
* publishing the value of those attributes to the Ganglia gmond process.
*
* Use:
* java -javaagent:path/jmxetric.jar=args yourmainclass
*
* Example:
* java -javaagent:/opt/jmxetric_0_1/jmxetric.jar=host="localhost",port="8649",config=/opt/jmxetric_0_1/jmxetric.xml yourmainclass
*
* Arguments can be:
*
*
Argument
Default
Description
*
host
Host address for ganglia
*
port
Port for ganglia
*
config
jmxetric.xml
Config file path
*
*/
public class JMXetricAgent extends GMonitor {
// private static Logger log =
// Logger.getLogger(JMXetricAgent.class.getName());
/**
* A log running, trivial main method for test purposes
* premain method
* @param args Not used
*/
public static void main(String[] args) throws Exception {
while( true ) {
Thread.sleep(1000*60*5);
System.out.println("Test wakeup");
}
}
/**
* The JVM agent entry point
* @param agentArgs
* @param inst
*/
public static void premain(String agentArgs, Instrumentation inst) {
System.out.println(STARTUP_NOTICE) ;
JMXetricAgent a = null ;
try {
a = new JMXetricAgent();
XMLConfigurationService.configure(a, agentArgs);
a.start();
} catch ( Exception ex ) {
// log.severe("Exception starting JMXetricAgent");
ex.printStackTrace();
}
}
private static final String STARTUP_NOTICE="JMXetricAgent instrumented JVM, see https://github.com/ganglia/jmxetric";
}
jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/MBeanSampler.java 0000664 0000000 0000000 00000021057 12305130526 0025334 0 ustar 00root root 0000000 0000000 package info.ganglia.jmxetric;
import info.ganglia.gmetric4j.GSampler;
import info.ganglia.gmetric4j.Publisher;
import info.ganglia.gmetric4j.gmetric.GMetricSlope;
import info.ganglia.gmetric4j.gmetric.GMetricType;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
// import java.util.logging.Level;
// import java.util.logging.Logger;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
/**
* A class that samples MBeans and publishes attributes to Ganglia. This
* classes' run method will be called periodically to sample the mbeans.
*/
public class MBeanSampler extends GSampler {
//private static Logger log =
// Logger.getLogger(JMXetricAgent.class.getName());
/*
* The internal data structure is a hashmap of key=mbean name
*/
private Map mbeanMap = new HashMap();
private MBeanServer mbs = null;
/**
* Creates an MBeanSampler
* @param delay the sample interval in seconds
* @param process the process name that is appended to metrics
*/
public MBeanSampler(int initialDelay, int delay, String process ) {
super(initialDelay, delay, process);
}
/**
* Adds a mbean name/attribute pair to be sampled
* @param mbean the name of the mbean
* @param attribute the name of the attribute
* @param composite the name of the composite
* @param publishName the name to publish this attribute on
* @throws java.lang.Exception
*/
public void addMBeanAttribute(String mbean, String attribute, String composite,
GMetricType type, String units, GMetricSlope slope,
String publishName ) throws Exception {
MBeanHolder mbeanHolder = mbeanMap.get(mbean);
if (mbeanHolder == null) {
mbeanHolder = new MBeanHolder(mbean);
mbeanMap.put(mbean, mbeanHolder);
}
mbeanHolder.addAttribute(attribute, composite, type, slope, units, publishName);
}
/**
* Adds a mbean name/attribute pair to be sampled
* @param mbean the name of the mbean
* @param attribute the name of the attribute
* @param publishName the name to publish this attribute on
* @throws java.lang.Exception
*/
public void addMBeanAttribute(String mbean, String attribute,
GMetricType type, String units, GMetricSlope slope,
String publishName ) throws Exception {
addMBeanAttribute( mbean, attribute, null, type, units, slope, publishName );
}
/**
* Called by the JMXAgent periodically to sample the mbeans
*/
public void run() {
try {
for (String mbean : mbeanMap.keySet()) {
MBeanHolder h = mbeanMap.get(mbean);
h.publish();
}
} catch ( Exception ex ) {
// Robust exception to prevent thread death
//log.warning("Exception thrown sampling Mbeans");
//log.throwing( this.getClass().getName(), "Exception thrown sampling Mbeans:", ex) ;
}
}
/**
* Data structure used to sample one attribute
*/
private class MBeanAttribute {
private String attributeName;
private String key;
private String canonicalName;
private String units ;
private GMetricType type ;
private GMetricSlope slope ;
private String publishName ;
public MBeanAttribute(String attributeName, String compositeKey, GMetricType type,
String units, GMetricSlope slope, String publishName ) {
this.key = compositeKey ;
this.canonicalName = attributeName + "." + compositeKey ;
this.attributeName = attributeName;
this.units = units ;
this.type = type ;
this.slope = slope ;
this.publishName = publishName ;
}
public MBeanAttribute(String attributeName, GMetricType type, GMetricSlope slope,
String units, String publishName ) {
this(attributeName, null, type, units, slope, publishName);
}
public void publish(ObjectName objectName) {
try {
String value = null;
if(mbs == null) {
mbs = ManagementFactory.getPlatformMBeanServer();
}
Object o = mbs.getAttribute(objectName, attributeName);
if (o instanceof CompositeData) {
CompositeData cd = (CompositeData) o;
if (key != null) {
Object val = cd.get(key);
// log.fine("Sampling " + objectName +
// " attribute " + canonicalName + ":" + val);
value = val.toString();
}
} else {
if (null != o){
value = o.toString();
// log.fine("Sampling " + objectName +
// " attribute " + canonicalName + ":" + o);
}else{
// log.fine("Not sampling " + objectName +
// " attribute " + canonicalName +
// " as value is null");
}
}
if (null != value){
Publisher gm = getPublisher();
// log.finer("Announcing metric " + this.toString() + " value=" + value );
gm.publish(process, publishName, value, getType(), getSlope(), getUnits());
}
} catch ( javax.management.InstanceNotFoundException ex ) {
// log.warning("Exception when getting " + objectName + " " + canonicalName);
} catch (Exception ex) {
// log.log(Level.WARNING,
// "Exception when getting " + objectName + " " + canonicalName,
// ex);
}
}
public String getAttributeName() {
return attributeName;
}
public String getCanonicalName() {
return canonicalName;
}
public String getUnits() {
return units;
}
public GMetricType getType() {
return type;
}
public GMetricSlope getSlope() {
return slope;
}
public String getKey() {
return key;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder() ;
buf.append("attributeName=").append(attributeName);
buf.append(" canonicalName=").append(canonicalName);
buf.append(" units=").append(units);
buf.append(" type=").append(type);
buf.append(" slope=").append(slope);
buf.append(" publishName=").append(publishName);
return buf.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (this.getClass() != obj.getClass()) return false;
MBeanAttribute attribute = (MBeanAttribute)obj ;
return canonicalName.equals(attribute.getCanonicalName());
// return attributeName.equals(attribute.getAttributeName());
}
@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + (this.canonicalName != null ? this.canonicalName.hashCode() : 0);
// hash = 79 * hash + (this.attributeName != null ? this.attributeName.hashCode() : 0);
return hash;
}
}
/**
* Data structure to hold and query mbean
*/
private class MBeanHolder {
private ObjectName objectName;
private Set attributes = new HashSet();
public MBeanHolder(String name) throws Exception {
objectName = new ObjectName(name);
}
public void addAttribute(String attributeName, String compositeName,
GMetricType type, GMetricSlope slope, String units, String publishName ) {
attributes.add(new MBeanAttribute(attributeName, compositeName,
type, units, slope, publishName));
}
public void publish() {
for (MBeanAttribute attr : attributes) {
try {
attr.publish(objectName);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
}
jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/Publisher.java 0000664 0000000 0000000 00000000574 12305130526 0024764 0 ustar 00root root 0000000 0000000 package info.ganglia.jmxetric;
import info.ganglia.gmetric4j.gmetric.GMetricSlope;
import info.ganglia.gmetric4j.gmetric.GMetricType;
import info.ganglia.gmetric4j.gmetric.GangliaException;
public interface Publisher {
void publish( String processName, String attributeName,
String value, GMetricType type, GMetricSlope slope, String units )
throws GangliaException;
}
jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/XMLConfigurationService.java 0000664 0000000 0000000 00000031175 12305130526 0027541 0 ustar 00root root 0000000 0000000 package info.ganglia.jmxetric;
import info.ganglia.gmetric4j.gmetric.GMetric;
import info.ganglia.gmetric4j.gmetric.GMetricSlope;
import info.ganglia.gmetric4j.gmetric.GMetricType;
import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
//import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
* Configures the JMXetricAgent based on the XML config file
*/
public class XMLConfigurationService {
// private static Logger log =
// Logger.getLogger(JMXetricAgent.class.getName());
private final static XPath xpath = XPathFactory.newInstance().newXPath();
private static final String DEFAULT_CONFIG="jmxetric.xml";
private static final String DEFAULT_MODE="multicast";
/**
* Configures the JMXetricAgent based on the supplied agent args
* @param agent the agent to configure
* @param agentArgs the agent arg list
* @throws java.lang.Exception
*/
public static void configure(JMXetricAgent agent, String agentArgs) throws Exception {
String host = null ;
String port = null ;
String mode = null ;
String config = DEFAULT_CONFIG ;
String wireformat = null ;
String processName = null ;
String spoof = null;
if ( agentArgs != null ) {
String[] args = agentArgs.split(",");
host = getTagValue( "host", args, null );
port = getTagValue( "port", args, null );
config = getTagValue( "config", args, DEFAULT_CONFIG );
mode = getTagValue( "mode", args, DEFAULT_MODE );
wireformat = getTagValue( "wireformat31x", args, "false");
processName = getTagValue( "process", args, null );
spoof = getTagValue( "spoof", args, null );
}
// log.config("Command line argument found: host=" + host );
// log.config("Command line args: port=" + port );
// log.config("Command line args: config=" + config );
// log.config("Command line args: mode=" + mode );
// log.config("Command line args: wireformat31x=" + wireformat );
// log.config("Command line args: process=" + processName );
// log.config("Command line args: spoof=" + spoof );
InputSource inputSource = new InputSource(config);
configureGangliaFromXML( agent, inputSource, host, port, mode,
wireformat, spoof );
configureJMXetricFromXML( agent, inputSource, config, processName );
}
private final static Pattern argPattern = Pattern.compile( "(\\S+?)\\=(\\S*)" );
// Default multicast TTL = 5 (same site)
private static final int DEFAULT_TTL = 5;
/**
* Parses the string array, input, looking for a pattern tag=value
* @param tag the tag to search for
* @param input the array list
* @param defaultValue the default value if tag is not found
* @return tha value
*/
private static String getTagValue(String tag, String[] input, String defaultValue) {
for( String arg: input) {
Matcher matcher = argPattern.matcher(arg);
// Get tagname and contents of tag
if ( matcher.find() ) {
String tagname = matcher.group(1);
if ( tag.equals( tagname )) {
return matcher.group(2);
}
}
}
return defaultValue ;
}
private static String selectParameterFromNode( Node ganglia,
String attributeName, String defaultValue ) {
return selectParameterFromNode( (String)null, ganglia, attributeName, defaultValue);
}
private static String selectParameterFromNode( String cmdLine,
Node ganglia, String attributeName,
String defaultValue ) {
String ret = defaultValue ;
if ( cmdLine != null )
ret = cmdLine ;
else if ( ganglia != null ) {
Node node = ganglia.getAttributes().getNamedItem(attributeName);
if ( node != null ) {
String value = node.getNodeValue();
if ( value != null )
ret = value ;
}
}
return ret ;
}
/**
* Creates a GMetric attribute on the JMXetricAgent from the XML config
* @param agent the agent to configure
* @param inputSource the input xml
* @param cmdLineHost the host found on the agent arg list
* @param cmdLinePort the port found on the agent arg list
* @param cmdLineMode the mode found on the agent arg list
* @param v31x true if the ganglia v31x wire format should be used
* @param cmdLineSpoof the spoof value found on the agent arg list
* @throws java.lang.Exception
*/
private static void configureGangliaFromXML(JMXetricAgent agent,
InputSource inputSource, String cmdLineHost,
String cmdLinePort, String cmdLineMode, String cmdLinev31x, String cmdLineSpoof)
throws Exception {
// Gets the config for ganglia
// Note that the ganglia config needs to be found before the samplers
// are created.
//
String gangliaExpr = "/jmxetric-config/ganglia";
Node g = (Node) xpath.evaluate(gangliaExpr, inputSource,
XPathConstants.NODE);
String hostname = selectParameterFromNode( cmdLineHost,
g, "hostname", "localhost");
String port = selectParameterFromNode( cmdLinePort,
g, "port", "8649");
int iport = Integer.parseInt(port);
String mode = selectParameterFromNode( cmdLineMode,
g, "mode","multicast");
UDPAddressingMode addressingMode = UDPAddressingMode.MULTICAST;
if ( mode.toLowerCase().equals("unicast")) {
addressingMode = UDPAddressingMode.UNICAST;
}
String stringv31x = selectParameterFromNode( cmdLinev31x,
g, "wireformat31x", "false");
boolean v31x = Boolean.parseBoolean(stringv31x) ;
String spoof = selectParameterFromNode( cmdLineSpoof,
g, "spoof", null);
StringBuilder buf = new StringBuilder() ;
buf.append("GMetric host=").append( hostname );
buf.append(" port=").append( port );
buf.append(" mode=").append( mode );
buf.append(" v31x=").append( v31x );
buf.append(" spoof=").append( spoof );
// log.fine(buf.toString());
GMetric gmetric = new GMetric(hostname, iport, addressingMode, DEFAULT_TTL, v31x, null, spoof );
agent.setGmetric(gmetric);
}
/**
* Creates managed attributed on the JMXetricAgent from the XML config
* @param agent the agent to configure
* @param inputSource the input xml
* @param file the config file from trom the agent arg list
* @throws java.lang.Exception
*/
private static void configureJMXetricFromXML(JMXetricAgent agent,
InputSource inputSource, String file, String processName) throws Exception {
// if the processName supplied from the agent arg list is null, see if
// it's in the xml
if ( processName == null ) {
Node jvm = (Node) xpath.evaluate("/jmxetric-config/jvm", inputSource,
XPathConstants.NODE);
if ( jvm != null )
processName = jvm.getAttributes().getNamedItem("process").getNodeValue();
}
// Gets the config for the samplers
//
String expression = "/jmxetric-config/sample";
NodeList samples = (NodeList) xpath.evaluate(expression, inputSource,
XPathConstants.NODESET);
// for every sample
for (int i = 0; i < samples.getLength(); i++) {
Node sample = samples.item(i);
//log.finer("Sample is " + sample);
/*
* String port = selectParameterFromNode( cmdLinePort,
g, "port", "8649");
int iport = Integer.parseInt(port);
*/
String delayString = selectParameterFromNode( sample, "delay", "60");
int delay = Integer.parseInt(delayString);
String initialDelayString = selectParameterFromNode( sample, "initialdelay", "0");
int initialDelay = Integer.parseInt(initialDelayString);
MBeanSampler mbSampler = new MBeanSampler(initialDelay, delay, processName);
NodeList mbeans = (NodeList) xpath.evaluate("mbean", sample,
XPathConstants.NODESET);
// for every mbean
for (int j = 0; j < mbeans.getLength(); j++) {
Node mbean = mbeans.item(j);
String mbeanName = selectParameterFromNode( mbean, "name", null );
String mbeanPublishName = selectParameterFromNode( mbean, "pname", "NULL" );
// log.finer("Mbean is " + mbeanName);
NodeList attrs = (NodeList) xpath.evaluate("attribute", mbean,
XPathConstants.NODESET);
//for every attribute
for (int k = 0; k < attrs.getLength(); k++) {
Node attr = attrs.item(k);
String attrName = selectParameterFromNode(attr, "name","NULL");
String type = selectParameterFromNode(attr, "type", "");
String units = selectParameterFromNode(attr, "units", "" );
String pname = selectParameterFromNode(attr, "pname", "");
String slope = selectParameterFromNode(attr, "slope", "" );
if ( "".equals(type)) {
//assume that there is a composite attribute to follow
NodeList composites = (NodeList) xpath.evaluate("composite", attr,
XPathConstants.NODESET);
//for every composite
for (int l = 0; l < composites.getLength(); l++) {
Node composite = composites.item(l);
String compositeName = selectParameterFromNode(composite, "name", "NULL");
String compositeType = selectParameterFromNode(composite, "type", "");
String compositeUnits = selectParameterFromNode(composite, "units", "");
String compositePname = selectParameterFromNode(composite, "pname", "");
String compositeSlope = selectParameterFromNode(composite, "slope", "");
String metricName = buildMetricName( processName, mbeanName,
mbeanPublishName, compositeName, compositePname );
//log.finer("Attr is " + compositeName);
mbSampler.addMBeanAttribute(mbeanName, attrName, compositeName,
GMetricType.valueOf(compositeType.toUpperCase()), compositeUnits,
GMetricSlope.valueOf(compositeSlope.toUpperCase()), metricName);
}
} else {
// It's a non composite attribute
//log.finer("Attr is " + attrName);
String metricName = buildMetricName( processName, mbeanName,
mbeanPublishName, attrName, pname );
mbSampler.addMBeanAttribute(mbeanName, attrName, null,
GMetricType.valueOf(type.toUpperCase()), units,
GMetricSlope.valueOf(slope.toUpperCase()), metricName);
}
}
}
agent.addSampler(mbSampler);
}
}
/**
* Builds the metric name in ganglia
* @param process the process name, or null if not used
* @param mbeanName the mbean name
* @param mbeanPublishName the mbean publish name, or null if not used
* @param attribute the mbean attribute name
* @param attrPublishName the mbean attribute publish name
* @return the metric name
*/
private static String buildMetricName( String process,
String mbeanName, String mbeanPublishName,
String attribute, String attrPublishName ) {
StringBuilder buf = new StringBuilder() ;
if ( process != null ) {
buf.append( process );
buf.append("_");
}
if ( mbeanPublishName != null ) {
buf.append( mbeanPublishName);
} else {
buf.append( mbeanName );
}
buf.append("_");
if ( ! "".equals( attrPublishName ) ) {
buf.append( attrPublishName );
} else {
buf.append( attribute );
}
return buf.toString() ;
}
}
jmxetric-1.0.6/src/main/java/info/ganglia/jmxetric/package.html 0000664 0000000 0000000 00000000607 12305130526 0024442 0 ustar 00root root 0000000 0000000
Provides a JVM agent that polls MBeans periodically and publishes the results to Ganglia