diff --git a/pom.xml b/pom.xml
index 324bcc088..35f64757f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -164,6 +164,12 @@
git@github.com:Datadog/jmxfetch.git
+
+
+ src/main/resources
+ true
+
+
org.apache.maven.plugins
diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java
index 9f657a348..814a19480 100644
--- a/src/main/java/org/datadog/jmxfetch/App.java
+++ b/src/main/java/org/datadog/jmxfetch/App.java
@@ -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;
@@ -118,8 +119,14 @@ 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);
}
@@ -127,6 +134,19 @@ public static void main(String[] args) {
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}.
@@ -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();
diff --git a/src/main/java/org/datadog/jmxfetch/AppConfig.java b/src/main/java/org/datadog/jmxfetch/AppConfig.java
index 13d156125..eeae07f1a 100644
--- a/src/main/java/org/datadog/jmxfetch/AppConfig.java
+++ b/src/main/java/org/datadog/jmxfetch/AppConfig.java
@@ -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 ACTIONS =
new HashSet(
Arrays.asList(
@@ -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";
private static final String AD_PIPE_NAME = "dd-auto_discovery";
private static final String AD_LAUNCH_FILE = "jmx.launch";
@@ -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",
@@ -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);
}
@@ -228,6 +239,10 @@ public boolean isHelp() {
return help;
}
+ public boolean isVersion() {
+ return version;
+ }
+
public Status getStatus() {
return status;
}
diff --git a/src/main/resources/project.properties b/src/main/resources/project.properties
new file mode 100644
index 000000000..defbd4820
--- /dev/null
+++ b/src/main/resources/project.properties
@@ -0,0 +1 @@
+version=${project.version}