Skip to content

Commit

Permalink
[auto-discovery] set jmx launch file on boot-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed Jul 17, 2017
1 parent 91f65ee commit b5eeefd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.commons.lang3.CharEncoding;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.util.CustomLogger;
import org.datadog.jmxfetch.util.FileHelper;


import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
Expand Down Expand Up @@ -234,6 +236,12 @@ void start() {
if(appConfig.getAutoDiscoveryEnabled()) {
LOGGER.info("Auto Discovery enabled");
adPipe = newAutoDiscoveryPipe();
try {
FileHelper.touch(new File(appConfig.getJMXLaunchFile()));
} catch (IOException e) {
LOGGER.warn("Unable to create launch file"
+ " - Auto-Discovery configs will not be automatically resubmitted.");
}
}

while (true) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AppConfig {
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";

@Parameter(names = {"--help", "-h"},
description = "Display this help page",
Expand Down Expand Up @@ -167,4 +168,8 @@ public String getAutoDiscoveryPipe() {
}
return pipePath;
}

public String getJMXLaunchFile() {
return getTmpDirectory() + "/" + AD_LAUNCH_FILE;
}
}
21 changes: 21 additions & 0 deletions src/main/java/org/datadog/jmxfetch/util/FileHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.datadog.jmxfetch.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class FileHelper {
public static void touch(File file) throws IOException{
long timestamp = System.currentTimeMillis();
touch(file, timestamp);
}

public static void touch(File file, long timestamp) throws IOException{
if (!file.exists()) {
new FileOutputStream(file).close();
}

file.setLastModified(timestamp);
}
}

0 comments on commit b5eeefd

Please sign in to comment.