Skip to content
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

Make JMXFetch know about its version number #218

Merged
merged 2 commits into from
Apr 29, 2019
Merged
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
<url>[email protected]:Datadog/jmxfetch.git</url>
</scm>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -118,15 +119,34 @@ public static void main(String[] args) {
System.exit(1);
}

// Display the version and quit
if (config.isVersion() || AppConfig.ACTION_HELP.equals(config.getAction())) {
JCommander.getConsole().println("JMX Fetch " + getVersion());
System.exit(0);
}

// Display the help and quit
if (config.isHelp() || config.getAction().equals(AppConfig.ACTION_HELP)) {
if (config.isHelp() || AppConfig.ACTION_HELP.equals(config.getAction())) {
commander.usage();
System.exit(0);
}

System.exit(run(config));
}

/** Returns our own version number. */
public static String getVersion() {
try {
final Properties properties = new Properties();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
properties.load(classLoader.getResourceAsStream("project.properties"));
return properties.getProperty("version");
} catch (IOException e) {
e.printStackTrace();
return "?.?.?";
}
}

/**
* Main entry point of JMXFetch that returns integer on exit instead of calling {@code
* System#exit}.
Expand Down Expand Up @@ -164,7 +184,7 @@ public static int run(AppConfig config) {
// Set up the shutdown hook to properly close resources
attachShutdownHook();

LOGGER.info("JMX Fetch has started");
LOGGER.info("JMX Fetch " + getVersion() + " has started");

// set up the config status
config.updateStatus();
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class AppConfig {
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 String ACTION_VERSION = "version";
public static final HashSet<String> ACTIONS =
new HashSet<String>(
Arrays.asList(
Expand All @@ -40,10 +41,10 @@ public class AppConfig {
ACTION_LIST_NOT_MATCHING,
ACTION_LIST_LIMITED,
ACTION_HELP,
ACTION_VERSION,
ACTION_LIST_JVMS));

private static final String AD_WIN_PIPE_PATH = "\\\\.\\pipe\\";
private static final String AD_LEGACY_PIPE_NAME = "dd-service_discovery";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛀

private static final String AD_PIPE_NAME = "dd-auto_discovery";
private static final String AD_LAUNCH_FILE = "jmx.launch";

Expand All @@ -57,6 +58,12 @@ public class AppConfig {
help = true)
private boolean help;

@Parameter(
names = {"--version", "-v"},
description = "Display the version number and exit",
help = true)
private boolean version;

@Parameter(
names = {"--log_level", "-L"},
description = "Level of verbosity",
Expand Down Expand Up @@ -216,7 +223,11 @@ public String getStatusLocation() {
return this.statusLocation;
}

/** Returns the action parameter of the app if any, or null otherwise. */
public String getAction() {
if (this.action == null || this.action.isEmpty()) {
return null;
}
return this.action.get(0);
}

Expand All @@ -228,6 +239,10 @@ public boolean isHelp() {
return help;
}

public boolean isVersion() {
return version;
}

public Status getStatus() {
return status;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${project.version}