Reputation: 895
I need to create a java program for generating logstash output accouding to some configurations (conf file). But here my problem is i have the configurations in a Properties object also i need the output as a Json String object. But in examples i found from internet it will do like, need to run the command following through console and the output become appear on the console
logstash -f config.conf
But i need a java program instead of the above. Is it possible?
Upvotes: 2
Views: 5891
Reputation: 17155
You do not need to use logstash at all to insert data into elasticsearch. You can do it directly from java API and use the index API.
Upvotes: 4
Reputation: 11
You can create a Java program in a following way.
Create your logstash configuration file and place it anywhere in your file system.
Ensure that you can execute this file using logstash -f yourfile.conf.
Now write a java program to execute this logstsah file.
Sample code to execute linux command from java code :
public void executeLinux(String command) {
System.out.println("Executing linux command "+command);
try{
Runtime run = Runtime.getRuntime();
Process pr = run.exec(command);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 1
Reputation: 166
ok,the logstash2.x has supported read config file from http , ftp and so on.
for example :
java
bin/logstash -f http://xx.xx.xx/xx.config --auto-reload --reload-interval 2
click here ""The Logstash Lines: 2.2 Release, Dynamic Config Reloading
and here Apply changes from configuration file without restarting
you can dynamically create config file in java project,and put redis,and the logstash load config file from springmvc's controller.
Upvotes: 0