By | February 25, 2016

Logstash jdbc plugin example

Let’s say we are storing your logs into some jdbc supportable database like mysql and we need to read logs from the database then below is the example for reading logs from mysql table.

Prerequisite

  1. Logstash – Refer Logstash installation tutorial
  2. Mysql Database

 

Install logstash jdbc plugin

/opt/logstash/bin/plugin install logstash-input-jdbc

 

This will install the jdbc plugin of logstash

Now create a configuration file and add below code in input tab.

 

input {

    jdbc {

       type => "jdbc-demo"
       jdbc_driver_library => "/usr/share/java/mysql-connector-java-5.1.17.jar"
       jdbc_driver_class => "com.mysql.jdbc.Driver"
       jdbc_connection_string => "jdbc:mysql://localhost:3306/logDB"
       jdbc_user => "root"
       jdbc_password => "somePassword"
       schedule => "* * * * *"
       statement => "SELECT id, access_type, request_type from catalina_table”

        }

    }

 

By using this configuration you will able to read logs from catalina_table table.

Now restart the logstash service.

Leave a Reply

Your email address will not be published. Required fields are marked *