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

[auto-discovery] set jmx launch file on boot-up. #143

Merged
merged 1 commit into from
Jul 20, 2017
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
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);
}
}