Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
.settings
.project
.classpath
.external*
.DS_Store
.springBeans
Thumbs.db
target
.idea
*.iml
*.iml
bin
logs
**/.settings
**/.project
**/.classpath
**/.external*
**/.DS_Store
**/.springBeans
**/Thumbs.db
**/target
**/bin
**/logs
**/.idea
**/*.iml
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ or
You can also specify the arguments with spaces before the ports, like this:
- `mvn exec:java -Dexec.args="-pr 2222 -ph 2223 -pv 2224"`

Build and test on Mac OSX
```bash
JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home" mvn -Dmaven.test.skip=true help:active-profiles clean package

JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home" MAVEN_OPTS="--add-modules jdk.jstatd,jdk.internal.jvmstat" mvn clean package exec:java -Dexec.args="-pr 2222 -ph 2223 -pv 2224"

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home" MAVEN_OPTS="--add-modules jdk.jstatd,jdk.internal.jvmstat" mvn -Dmaven.test.skip=true help:active-profiles clean package exec:java -Dexec.args="-pr 2222 -ph 2223 -pv 2224"

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home" MAVEN_OPTS="--add-modules jdk.jstatd,jdk.internal.jvmstat" mvn -Dmaven.test.skip=true help:active-profiles clean package exec:java -Dexec.args="-pr 2222 -ph 2223 -pv 2224"

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home" mvn -Dmaven.test.skip=true help:active-profiles clean package exec:java -Dexec.args="-pr 2222 -ph 2223 -pv 2224"
```

# Usage in Docker
In this section we will consider using those 3 ports as example, don't forget to replace them with yours: `2222` for `pr`, `2223` for `ph` and `2224` for `pv`.

Expand All @@ -37,11 +50,24 @@ And inside the Docker image `myimage`, `ejstatd` should be launched from a scrip

Then you could access this `ejstatd` using JVisualVM running on your Desktop PC for example adding a "Remote Host" specifying your Docker hostname as "Host name" and adding a "Custom jstatd Connections" (in the "Advanced Settings") by setting "2222" to "Port".

# Usage with Openshift (Production case, assuming that you cannot restart POD)
1. Download `ejstatd` & corresponding `tools.jar` (from java folder) to the machine. (You can use [Droppy Tool](https://github.com/stackp/Droopy) or even wget if you have public facing storage ) for that.
2. Run it:
```bash
java -Djava.rmi.server.hostname=localhost -cp "ejstatd-1.0.0.jar:tools1.8.jar" com.github.anthony_o.ejstatd.EJstatd -pr2222 -ph2223 -pv2224
```
3. On the VisualVm machine - login to openshift & enable port forwarding:
```bash
oc login <address> --token=<token>
oc port-forward <POD ID> 2222 2223 2224
```
4. Open VisualVm & connect jstat to local machine port 2222

# Prerequisites
1. Install a [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
1. [Install Maven](http://maven.apache.org/install.html) (make sure its `bin` folder is in the `PATH`)
1. Clone this Github project
1. `cd` into the project and create the package using `mvn package` command

# Thanks
This program is based on JDK 7's `jstatd` (using sources from its [Mercurial repository](http://hg.openjdk.java.net/jdk7u/jdk7u/jdk)) and highly inspired by [jdonofrio728](https://github.com/jdonofrio728/)'s [JakestatD](https://github.com/jdonofrio728/jakestatd).
This program is based on JDK 7's `jstatd` (using sources from its [Mercurial repository](http://hg.openjdk.java.net/jdk7u/jdk7u/jdk)) and highly inspired by [jdonofrio728](https://github.com/jdonofrio728/)'s [JakestatD](https://github.com/jdonofrio728/jakestatd).
143 changes: 116 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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>
<groupId>com.github.anthony-o</groupId>
<artifactId>ejstatd</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<description>Enhanced jstatd</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.5</java.version>
</properties>

<dependencies>
<dependency>
<!-- add JDK tools.jar as maven dependency thanks to http://stackoverflow.com/q/3080437/535203 -->
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<groupId>com.github.anthony-o</groupId>
<packaging>jar</packaging>
<version>1.0.0</version>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand All @@ -37,7 +19,6 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
Expand All @@ -46,18 +27,31 @@
<classpathPrefix>lib</classpathPrefix>
<mainClass>com.github.anthony_o.ejstatd.EJstatd</mainClass>
</manifest>
<!--manifestEntries><Class-Path>${tools.path}</Class-Path></manifestEntries-->
</archive>
<classifier>java${java.version}</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source-of-specific-java-version</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources><source>src/main/java${java.version}</source></sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
Expand All @@ -67,5 +61,100 @@
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin><artifactId>build-helper-maven-plugin</artifactId><groupId>org.codehaus.mojo</groupId><version>3.0.0</version></plugin>
<plugin><artifactId>exec-maven-plugin</artifactId><groupId>org.codehaus.mojo</groupId><version>1.6.0</version></plugin>
<plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin>
<plugin><artifactId>maven-jar-plugin</artifactId><version>3.1.1</version></plugin>
</plugins>
</pluginManagement>
</build>

<!-- add JDK tools.jar as maven dependency thanks to http://stackoverflow.com/q/3080437/535203 -->
<profiles>
<profile>
<id>ejstatd-default-java8</id>
<activation>
<jdk>[1.8,9)</jdk>
<file><exists>${java.home}/../lib/tools.jar</exists></file>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<properties>
<java.version>8</java.version>
</properties>
</profile>
<profile>
<id>ejstatd-java9-to-10</id>
<activation>
<jdk>[9,10]</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Xdiags:verbose</arg>
<arg>-Xlint:deprecation</arg>
<!---->
<arg>--add-modules=jdk.jstatd,jdk.internal.jvmstat</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.jstatd/sun.jvmstat.monitor.remote=ALL-UNNAMED</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.internal.jvmstat/sun.jvmstat.monitor.event=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>9</java.version>
</properties>
</profile>
<profile>
<id>ejstatd-java11-and-newer</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Xdiags:verbose</arg>
<arg>-Xlint:deprecation</arg>
<!---->
<arg>--add-modules=jdk.jstatd,jdk.internal.jvmstat</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.jstatd/sun.jvmstat.monitor.remote=ALL-UNNAMED</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED</arg>
<!---->
<arg>--add-exports</arg><arg>jdk.internal.jvmstat/sun.jvmstat.monitor.event=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>11</java.version>
</properties>
</profile>
</profiles>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
14 changes: 11 additions & 3 deletions src/main/java/com/github/anthony_o/ejstatd/EJstatd.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
Expand All @@ -47,7 +49,7 @@
* provided through an RMI interface.
*
* @author Brian Doherty
* @since 1.5
* @since 1.7+
*/
public class EJstatd {

Expand All @@ -59,7 +61,7 @@ private static void printUsage() {
System.err.println("usage: ejstatd [-nr] [-pr port] [-ph port] [-pv port] [-n rminame]");
}

static void bind(String name, RemoteHostImpl remoteHost)
static void bind(final String name, final RemoteHostImpl remoteHost)
throws RemoteException, MalformedURLException, Exception {

try {
Expand All @@ -85,7 +87,7 @@ static void bind(String name, RemoteHostImpl remoteHost)
}
}

public static void main(String[] args) throws IOException, URISyntaxException, ClassNotFoundException {
public static void main(final String[] args) throws IOException, URISyntaxException, ClassNotFoundException {
String rminame = null;
int argc = 0;
int remoteHostPort = Integer.parseInt(System.getProperty("ejstatd.remoteHost.port", "0"));
Expand Down Expand Up @@ -199,9 +201,13 @@ public static void main(String[] args) throws IOException, URISyntaxException, C
for (Class<?> klass : classesToAllow) {
CodeSource codeSource = klass.getProtectionDomain().getCodeSource();
if (codeSource != null) {
// System.err.println("allow " + codeSource.getLocation().toURI().toString());
codebasesToAllow.add(codeSource.getLocation().toURI().toString());
}
}
if (!codebasesToAllow.contains("jrt:/jdk.internal.jvmstat") && codebasesToAllow.contains("jrt:/jdk.jstatd")) {
codebasesToAllow.add("jrt:/jdk.internal.jvmstat");
}

FileOutputStream policyOutputStream = new FileOutputStream(policyFile);
try {
Expand All @@ -215,6 +221,8 @@ public static void main(String[] args) throws IOException, URISyntaxException, C
policyOutputStream.close();
}
System.setProperty("java.security.policy", policyFile.toString());
System.err.println("java.security.policy=" + policyFile.toString());
System.err.println(new String(Files.readAllBytes(Paths.get(policyFile.toString()))));
}

if (System.getSecurityManager() == null) {
Expand Down
Loading