简体   繁体   English

从Java管理Logstash

[英]manage logstash from Java

I want to manage starting and stopping of logstash from Java. 我想从Java管理logstash的启动和停止。 Is there any easy/nice way to do this? 有什么简单/不错的方法吗?

so, can anyone give me an example of how to start logstash without needing to my logstash instance started from run.bat manually.? 因此,有人可以给我一个如何启动logstash的示例,而无需手动从run.bat启动我的logstash实例吗?

You can run the batch file as a process in Java like this 您可以像这样在Java中将批处理文件作为进程运行

String cmd = "cmd /c start C:\\path\\to\\run.bat";
Process logstashProcess = Runtime.getRuntime().exec(cmd);

And then kill the process calling destroy() method when needed 然后在需要时终止调用destroy()方法的进程

logstashProcess.destroy();

You can add these as startup and shutdown hooks of your application (the application whose log you will be analyzing using logstash) or you could just write a standalone Java app which will maintain starting and stopping logstash. 您可以将它们添加为应用程序(将使用logstash分析其日志的应用程序)的启动和关闭挂钩,或者可以编写一个独立的Java应用程序来维护logstash的启动和停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM