简体   繁体   中英

manage logstash from Java

I want to manage starting and stopping of logstash from Java. 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.?

You can run the batch file as a process in Java like this

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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