-
Notifications
You must be signed in to change notification settings - Fork 70
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 1 commit
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.ParameterException; | ||
import com.sun.tools.attach.VirtualMachineDescriptor; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class App { | ||
|
@@ -320,8 +321,19 @@ public void init(boolean forceNewConnection) { | |
clearInstances(instances); | ||
clearInstances(brokenInstances); | ||
|
||
|
||
Reporter reporter = appConfig.getReporter(); | ||
|
||
String action = appConfig.getAction(); | ||
|
||
if( action.equals( AppConfig.ACTION_LIST_JVMS )) { | ||
List<VirtualMachineDescriptor> descriptors = com.sun.tools.attach.VirtualMachine.list(); | ||
for( VirtualMachineDescriptor descriptor : descriptors ) { | ||
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. What do you think about adding a top message before listing alls JVMs to emphasize that only the ones associated to the user are listed. Something like,
|
||
System.out.println( "\tJVM id " + descriptor.id() + ": '" + descriptor.displayName() + "'" ); | ||
} | ||
return; | ||
} | ||
|
||
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; | ||
|
||
|
@@ -35,6 +37,7 @@ private JMXServiceURL getAddress(LinkedHashMap<String, Object> connectionParams) | |
private String getJMXUrlForProcessRegex(String processRegex) throws com.sun.tools.attach.AttachNotSupportedException, IOException { | ||
for (com.sun.tools.attach.VirtualMachineDescriptor vmd : com.sun.tools.attach.VirtualMachine.list()) { | ||
if (vmd.displayName().matches(processRegex)) { | ||
LOGGER.info("Matched JVM '" + vmd.displayName() + "' against regex '" + processRegex + "'"); | ||
com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(vmd); | ||
String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); | ||
//If jmx agent is not running in VM, load it and return the connector url | ||
|
@@ -49,7 +52,12 @@ private String getJMXUrlForProcessRegex(String processRegex) throws com.sun.tool | |
return connectorAddress; | ||
} | ||
} | ||
throw new IOException("Cannot find JVM matching regex: " + processRegex); | ||
|
||
List<String> jvms = new ArrayList<String>(); | ||
for (com.sun.tools.attach.VirtualMachineDescriptor vmd : com.sun.tools.attach.VirtualMachine.list()) { | ||
jvms.add( vmd.displayName() ); | ||
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 could be done within the previous loop |
||
} | ||
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.
Can we import
com.sun.tools.attach.VirtualMachine
along withcom.sun.tools.attach.VirtualMachineDescriptor
in the header ?