在Java程序中运行Logstash [英] Run Logstash in Java Program
本文介绍了在Java程序中运行Logstash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下命令成功运行Logstash配置文件以将数据从MySQL数据库表添加到ElasticSearch中:
bin / logstash -f [路径登录配置文件] -v
我需要从我的Java源代码。如何从Java代码运行此logstash配置文件?
解决方案
import java.io 。*;
class UserTest {
public static void main(String [] args)
{
try
{
String s =;
String [] cmd = new String [] {/ bin / sh,./logstash\",\"-f\",\"loggingConfFile.conf};
进程进程= Runtime.getRuntime()。exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(processes.getInputStream()));
while((s = stdInput.readLine())!= null)
{
System.out.println(s);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
I have created indexes and fields in ElasticSearch. I could successfully run Logstash config file to add data from MySQL database table into ElasticSearch using the following command :
bin/logstash -f [PATH TO LOGSTASH CONFIG FILE] -v
I need to run this command from my Java source code. How do I run this logstash config file from Java code?
解决方案
import java.io.*;
class UserTest{
public static void main(String[] args)
{
try
{
String s = "";
String[] cmd = new String[]{"/bin/sh", "./logstash","-f","loggingConfFile.conf"};
Process processes = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(processes.getInputStream()));
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
这篇关于在Java程序中运行Logstash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文