Anish Antony
Anish Antony

Reputation: 895

Logstash - Is it possible to create a java program for logstash

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

Answers (3)

Alcanzar
Alcanzar

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

Ankur Khandelwal
Ankur Khandelwal

Reputation: 11

You can create a Java program in a following way.

  1. Create your logstash configuration file and place it anywhere in your file system.

  2. Ensure that you can execute this file using logstash -f yourfile.conf.

  3. 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

Stephen.lin
Stephen.lin

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

Related Questions