-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added list_jvms option to list available JVMs (that this process can … #100
Changes from all commits
4ddf9fa
4a83168
100c26f
6715343
0b44718
60f3744
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.ParameterException; | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
public class App { | ||
private final static Logger LOGGER = Logger.getLogger(App.class.getName()); | ||
|
@@ -81,6 +82,15 @@ public static void main(String[] args) { | |
System.exit(1); | ||
} | ||
|
||
if( config.getAction().equals( AppConfig.ACTION_LIST_JVMS )) { | ||
List<com.sun.tools.attach.VirtualMachineDescriptor> descriptors = com.sun.tools.attach.VirtualMachine.list(); | ||
System.out.println("List of JVMs for user " + System.getProperty("user.name") ); | ||
for( com.sun.tools.attach.VirtualMachineDescriptor descriptor : descriptors ) { | ||
System.out.println( "\tJVM id " + descriptor.id() + ": '" + descriptor.displayName() + "'" ); | ||
} | ||
System.exit(0); | ||
} | ||
|
||
// Set up the shutdown hook to properly close resources | ||
attachShutdownHook(); | ||
|
||
|
@@ -320,8 +330,10 @@ public void init(boolean forceNewConnection) { | |
clearInstances(instances); | ||
clearInstances(brokenInstances); | ||
|
||
|
||
Reporter reporter = appConfig.getReporter(); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this whole block should be moved to the |
||
Iterator<Entry<String, YamlParser>> it = configs.entrySet().iterator(); | ||
while (it.hasNext()) { | ||
Map.Entry<String, YamlParser> entry = it.next(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,15 @@ | |
@Parameters(separators = "=") | ||
class AppConfig { | ||
public static final String ACTION_COLLECT = "collect"; | ||
public static final String ACTION_LIST_JVMS = "list_jvms"; | ||
public static final String ACTION_LIST_EVERYTHING = "list_everything"; | ||
public static final String ACTION_LIST_COLLECTED = "list_collected_attributes"; | ||
public static final String ACTION_LIST_MATCHING = "list_matching_attributes"; | ||
public static final String ACTION_LIST_NOT_MATCHING = "list_not_matching_attributes"; | ||
public static final String ACTION_LIST_LIMITED = "list_limited_attributes"; | ||
public static final String ACTION_HELP = "help"; | ||
public static final HashSet<String> ACTIONS = new HashSet<String>(Arrays.asList(ACTION_COLLECT, ACTION_LIST_EVERYTHING, | ||
ACTION_LIST_COLLECTED, ACTION_LIST_MATCHING, ACTION_LIST_NOT_MATCHING, ACTION_LIST_LIMITED, ACTION_HELP)); | ||
ACTION_LIST_COLLECTED, ACTION_LIST_MATCHING, ACTION_LIST_NOT_MATCHING, ACTION_LIST_LIMITED, ACTION_HELP, ACTION_LIST_JVMS)); | ||
|
||
@Parameter(names = {"--help", "-h"}, | ||
description = "Display this help page", | ||
|
@@ -81,7 +82,7 @@ class AppConfig { | |
|
||
@Parameter(description = "Action to take, should be in [help, collect, " + | ||
"list_everything, list_collected_attributes, list_matching_attributes, " + | ||
"list_not_matching_attributes, list_limited_attributes]", | ||
"list_not_matching_attributes, list_limited_attributes, list_jvms]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
required = true) | ||
private List<String> action = null; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
import javax.management.remote.JMXServiceURL; | ||
|
||
|
@@ -29,13 +31,15 @@ private JMXServiceURL getAddress(LinkedHashMap<String, Object> connectionParams) | |
throw new IOException("Unnable to attach to process regex: "+ processRegex, e); | ||
} | ||
return address; | ||
|
||
} | ||
|
||
private String getJMXUrlForProcessRegex(String processRegex) throws com.sun.tools.attach.AttachNotSupportedException, IOException { | ||
List<String> jvms = new ArrayList<String>(); | ||
for (com.sun.tools.attach.VirtualMachineDescriptor vmd : com.sun.tools.attach.VirtualMachine.list()) { | ||
if (vmd.displayName().matches(processRegex)) { | ||
com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(vmd); | ||
LOGGER.info("Matched JVM '" + vmd.displayName() + "' against regex '" + processRegex + "'"); | ||
String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); | ||
//If jmx agent is not running in VM, load it and return the connector url | ||
if (connectorAddress == null) { | ||
|
@@ -48,8 +52,10 @@ private String getJMXUrlForProcessRegex(String processRegex) throws com.sun.tool | |
|
||
return connectorAddress; | ||
} | ||
jvms.add( vmd.displayName() ); | ||
} | ||
throw new IOException("Cannot find JVM matching regex: " + processRegex); | ||
|
||
throw new IOException("Cannot find JVM matching regex: '" + processRegex + "'; available JVMs (for this user account): " + jvms ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this test requires the same update https://github.com/DataDog/jmxfetch/blob/master/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java#L116 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log line is directly forwarded to the
I think it's difficult to understand what it means when being agnostic to the code. What do you think about keeping the old message ? Alternatively the message could invite the user to run the |
||
} | ||
|
||
private void loadJMXAgent(com.sun.tools.attach.VirtualMachine vm) throws IOException { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block can potentially lead to
java.lang.NoClassDefFoundError
when notools_jar_path
is defined in the YAML configuration file.Can we catch it ad prompt a more comprehensive error message when this happens ?