我是一名实习生,非常接近于撕掉我所有的头发...我正在研究一个小功能作为程序的一部分,要求是它使用ELK。我现在拥有的当前设置是,当你启动程序时,它会在不同的进程上启动filebeat,logstash,elasticsearch和kibana。我们的程序有一个选项卡,它将打开firefox并导航到用户的kibana。当用户关闭我们的程序时,它将调用一个函数来杀死所有进程以进行干净退出。
出于某种原因,当我启动程序时,一些ELK进程在启动时会失败(exitcode = 1并且在查看进程时hasExited = true)。失败的ELK进程将始终是随机的...当导航kibana时,它经常会挂起,无法加载新页面(我必须完全关闭程序并启动它以使其再次运行)。但是,当独立运行ELK堆栈时,它可以完美运行。 ELK在运行java时只会崩溃并烧毁。
public class ELK_Boot {
private String user;
private String c1, c2, c3, c4;
private Process process1, process2, process3, process4, process5;
public ELK_Boot() {
user = System.getProperty("user.name");
c1 = "/home/" + user + "/filebeat-6.2.3-linux-x86_64";
c2 = "/home/" + user + "/logstash-6.2.2";
c3 = "/home/" + user + "/elasticsearch/bin";
c4 = "/home/" + user + "/kibana-6.2.2-linux-x86_64";
}
public void start() throws IOException {
process1 = Runtime.getRuntime().exec("rm -f" + c1 + "/data/registry");
process2 = Runtime.getRuntime().exec(c1 + "/filebeat -e -c " + c1 + "/filebeat.yml -d \"publish\"");
process3 = Runtime.getRuntime().exec(c2 + "/bin/logstash -f " + c2 + "/logstash-simple.conf --config.reload.automatic");
process4 = Runtime.getRuntime().exec(c3 + "/elasticsearch");
process5 = Runtime.getRuntime().exec(c4 + "/bin/kibana");
}
public void stop() {
process1.destroy();
process2.destroy();
process3.destroy();
process4.destroy();
process5.destroy();
}
}
这是ELK将在程序启动时启动的代码片段:
elastic = new ELK_BOOT();
try {
elastic.start();
} catch (IOException ex) {
Logger.getLogger(XXXXX.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Thread.sleep(5000);
//The sleep is to allow ELK stack to finish spinning up before rest of program loads.
} catch (InterruptedException ex) {
Logger.getLogger(YYYYY.class.getName()).log(Level.SEVERE, null, ex);
}
这是杀死进程的片段:
stage.setOnCloseRequest(WindowEvent t) -> {
elastic.stop();
System.exit(1);
});
最后,这是控制器中打开firefox的代码片段:
@FXML private void onELKMenuClicked() throws IOException {
Runtime rt = Runtime.getRuntime();
rt.exec("/usr/bin/firefox --display=2.0 http://localhost:5601/");
}