-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a606295
commit f37f408
Showing
23 changed files
with
2,097 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2010-2013 the original author or authors | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This product includes/uses software JUnit (http://junit.org) | ||
License: Common Public License - v 1.0 (http://junit.sourceforge.net/cpl-v10.html) | ||
|
||
This product includes/uses software Hamcrest (http://www.hamcrest.org) | ||
developped by Harmcrest (www.hamcrest.org) | ||
New BSD License http://opensource.org/licenses/BSD-3-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,146 @@ | ||
jmxtrans-agent | ||
============== | ||
# Jmxtrans Agent | ||
|
||
|
||
## What is JmxTrans Agent ? | ||
|
||
JmxTrans Agent is a version of [jmxtrans](http://jmxtrans.org/) intended to be used as a java agent. JmxTrans Agent has zero dependencies to ease integration. | ||
|
||
## Java Agent Declaration | ||
|
||
Download [jmxtrans-agent-1.0.0-20130417.130310-1.jar](https://repository-jmxtrans.forge.cloudbees.com/snapshot/org/jmxtrans/agent/jmxtrans-agent/1.0.0-SNAPSHOT/jmxtrans-agent-1.0.0-20130417.130310-1.jar) | ||
|
||
Sample `setenv.sh` | ||
|
||
``` | ||
export JAVA_OPTS="$JAVA_OPTS | ||
-javaagent:/path/to/jmxtrans-agent-1.0.0-SNAPSHOT.jar=jmxtrans-agent.xml" | ||
``` | ||
|
||
* java agent jar path can be relative to the working dir | ||
* `jmxtrans-agent.xml` is the configuration file, can be classpath relative (`classpath:…`), http(s) (`http(s)://...`) or file system system based (relative to the working dir) | ||
|
||
|
||
## Sample configuration file | ||
|
||
Sample `jmxtrans-agent.xml` configuration file for Tomcat: | ||
|
||
```xml | ||
<jmxtrans-agent> | ||
<queries> | ||
<!-- OS --> | ||
<query objectName="java.lang:type=OperatingSystem" attribute="SystemLoadAverage" resultAlias="os.systemLoadAverage"/> | ||
|
||
<!-- JVM --> | ||
<query objectName="java.lang:type=Memory" attribute="HeapMemoryUsage" key="used" | ||
resultAlias="jvm.heapMemoryUsage.used"/> | ||
<query objectName="java.lang:type=Memory" attribute="HeapMemoryUsage" key="committed" | ||
resultAlias="jvm.heapMemoryUsage.committed"/> | ||
<query objectName="java.lang:type=Memory" attribute="NonHeapMemoryUsage" key="used" | ||
resultAlias="jvm.nonHeapMemoryUsage.used"/> | ||
<query objectName="java.lang:type=Memory" attribute="NonHeapMemoryUsage" key="committed" | ||
resultAlias="jvm.nonHeapMemoryUsage.committed"/> | ||
<query objectName="java.lang:type=ClassLoading" attribute="LoadedClassCount" resultAlias="jvm.loadedClasses"/> | ||
|
||
<query objectName="java.lang:type=Threading" attribute="ThreadCount" resultAlias="jvm.thread"/> | ||
|
||
<!-- TOMCAT --> | ||
<query objectName="Catalina:type=GlobalRequestProcessor,name=*" attribute="requestCount" | ||
resultAlias="tomcat.requestCount"/> | ||
<query objectName="Catalina:type=GlobalRequestProcessor,name=*" attribute="errorCount" | ||
resultAlias="tomcat.errorCount"/> | ||
<query objectName="Catalina:type=GlobalRequestProcessor,name=*" attribute="processingTime" | ||
resultAlias="tomcat.processingTime"/> | ||
<query objectName="Catalina:type=GlobalRequestProcessor,name=*" attribute="bytesSent" | ||
resultAlias="tomcat.bytesSent"/> | ||
<query objectName="Catalina:type=GlobalRequestProcessor,name=*" attribute="bytesReceived" | ||
resultAlias="tomcat.bytesReceived"/> | ||
|
||
<!-- APPLICATION --> | ||
<query objectName="Catalina:type=Manager,context=/,host=localhost" attribute="activeSessions" | ||
resultAlias="application.activeSessions"/> | ||
</queries> | ||
<outputWriter class="org.jmxtrans.agent.GraphitePlainTextTcpOutputWriter"> | ||
<host>localhost</host> | ||
<port>2003</port> | ||
<namePrefix>app_123456.servers.i876543.</namePrefix> | ||
</outputWriter> | ||
<outputWriter class="org.jmxtrans.agent.ConsoleOutputWriter"/> | ||
</jmxtrans-agent> | ||
``` | ||
|
||
**Note** why xml and not json ? because XML parsing is out of the box in the JVM when json requires additional libraries. | ||
|
||
|
||
## OutputWriters | ||
|
||
OutputWriters are very simple to develop, you just have to extend [AbstractOutputWriter.java](https://github.com/jmxtrans/jmxtrans-agent/blob/master/src/main/java/org/jmxtrans/agent/AbstractOutputWriter.java) or to implement [OutputWriter.java](https://github.com/jmxtrans/jmxtrans-agent/blob/master/src/main/java/org/jmxtrans/agent/OutputWriter.java). | ||
|
||
Out of the box output writers | ||
|
||
* [ConsoleOutputWriter](https://github.com/jmxtrans/jmxtrans-agent/blob/master/src/main/java/org/jmxtrans/agent/ConsoleOutputWriter.java): output metric values to `stdout` | ||
* [GraphitePlainTextTcpOutputWriter](https://github.com/jmxtrans/jmxtrans-agent/blob/master/src/main/java/org/jmxtrans/agent/GraphitePlainTextTcpOutputWriter.java): output to Graphite Carbon plain text protocol on TCP. Configuration parameters: | ||
* `enabled`: to enable/disable the output writer. Optional, default value `true` | ||
* `host`: Graphite Carbon listener host | ||
* `port`: Graphite Carbon Plain Text TCP listener port. Optional, default value `2003` | ||
* `namePrefix`; prefix of the metric name. Optional, default values `servers.#hostname#.` where `#hostname#` is the auto discovered hostname of computer with `.` escpaed as `_` (`InetAddress.getLocalHost().getHostName()`). | ||
* [FileOverwriterOutputWriter](https://github.com/jmxtrans/jmxtrans-agent/blob/master/src/main/java/org/jmxtrans/agent/FileOverwriterOutputWriter.java): store the last collection of metrics in a file. Configuration parameters: | ||
* `fileName`: name of the file in which the collected metrics are stored. Optional, default value `jmxtrans-agent.data` (in JVM working dir, for example `$TOMCAT_HOME/bin`) | ||
|
||
Output writers configuration support an expression language based on property placeholders with the `{prop-name[:default-value]} syntax (e.g. "`${graphite.host:2003}`"). | ||
|
||
The `default-value` is optional. An exception is raised if no default value is defined and the property placeholder is not found. | ||
|
||
Environment variables are looked-up in the following order: | ||
|
||
1. JVM system properties (```System.getProperty("graphite.host")```) | ||
1. JVM environment variables (```System.getenv("graphite.host")```) | ||
1. JVM environment variables after a "to-upper-case + dot-to-underscore" transformation (```System.getenv("GRAPHITE_HOST")```) | ||
|
||
## Sample of ConsoleOutputWriter | ||
|
||
``` | ||
os.systemLoadAverage 1.80419921875 1366199958 | ||
jvm.heapMemoryUsage.used 20438792 1366199958 | ||
jvm.heapMemoryUsage.committed 119668736 1366199958 | ||
jvm.nonHeapMemoryUsage.used 15953560 1366199958 | ||
jvm.nonHeapMemoryUsage.committed 24313856 1366199958 | ||
jvm.loadedClasses 2162 1366199958 | ||
jvm.thread 13 1366199958 | ||
tomcat.requestCount 0 1366199958 | ||
tomcat.requestCount 0 1366199958 | ||
tomcat.errorCount 0 1366199958 | ||
tomcat.errorCount 0 1366199958 | ||
tomcat.processingTime 0 1366199958 | ||
tomcat.processingTime 0 1366199958 | ||
tomcat.bytesSent 0 1366199958 | ||
tomcat.bytesSent 0 1366199958 | ||
tomcat.bytesReceived 0 1366199958 | ||
tomcat.bytesReceived 0 1366199958 | ||
application.activeSessions 0 1366199958 | ||
``` | ||
|
||
## Sample of jmxtrans-agent.data | ||
|
||
Content of `$ cat jmxtrans-agent.data` | ||
|
||
``` | ||
os.systemLoadAverage 1.27734375 | ||
jvm.heapMemoryUsage.used 33436016 | ||
jvm.heapMemoryUsage.committed 133365760 | ||
jvm.nonHeapMemoryUsage.used 23623096 | ||
jvm.nonHeapMemoryUsage.committed 24707072 | ||
jvm.loadedClasses 3002 | ||
jvm.thread 21 | ||
tomcat.requestCount 27 | ||
tomcat.requestCount 0 | ||
tomcat.errorCount 0 | ||
tomcat.errorCount 0 | ||
tomcat.processingTime 881 | ||
tomcat.processingTime 0 | ||
tomcat.bytesSent 135816 | ||
tomcat.bytesSent 0 | ||
tomcat.bytesReceived 0 | ||
tomcat.bytesReceived 0 | ||
application.activeSessions 0 | ||
``` | ||
|
||
Java Agent based JMX metrics exporter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!-- | ||
~ Copyright (c) 2010-2013 the original author or authors | ||
~ | ||
~ 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. | ||
~ | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.sonatype.oss</groupId> | ||
<artifactId>oss-parent</artifactId> | ||
<version>7</version> | ||
</parent> | ||
<groupId>org.jmxtrans.embedded</groupId> | ||
<artifactId>jmxtrans-agent</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>JMX metrics exporter agent</name> | ||
<url>https://github.com/jmxtrans/jmxtrans-agent</url> | ||
<scm> | ||
<connection>scm:git:[email protected]:jmxtrans/jmxtrans-agent.git</connection> | ||
<developerConnection>scm:git:[email protected]:jmxtrans/jmxtrans-agent.git</developerConnection> | ||
<url>https://github.com/jmxtrans/jmxtrans-agent</url> | ||
</scm> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.4</version> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Premain-Class>org.jmxtrans.agent.JmxTransAgent</Premain-Class> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
|
||
</plugin> | ||
</plugins> | ||
</build> | ||
<developers> | ||
<developer> | ||
<id>1</id> | ||
<name>Cyrille Le Clerc</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
</project> |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/jmxtrans/agent/AbstractOutputWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2010-2013 the original author or authors | ||
* | ||
* 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. | ||
* | ||
*/ | ||
package org.jmxtrans.agent; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a> | ||
*/ | ||
public abstract class AbstractOutputWriter implements OutputWriter { | ||
|
||
protected final Logger logger = Logger.getLogger(getClass().getName()); | ||
|
||
@Override | ||
public void postConstruct(Map<String, String> settings) { | ||
} | ||
|
||
@Override | ||
public void preDestroy() { | ||
} | ||
|
||
@Override | ||
public void postCollect() throws IOException { | ||
} | ||
|
||
@Override | ||
public void preCollect() throws IOException { | ||
} | ||
|
||
@Override | ||
public abstract void write(String metricName, Object value) throws IOException; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2010-2013 the original author or authors | ||
* | ||
* 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. | ||
* | ||
*/ | ||
package org.jmxtrans.agent; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a> | ||
*/ | ||
public class ConsoleOutputWriter extends AbstractOutputWriter implements OutputWriter { | ||
@Override | ||
public void write(String metricName, Object value) { | ||
System.out.println(metricName + " " + value + " " + TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS)); | ||
} | ||
} |
Oops, something went wrong.