官术网_书友最值得收藏!

  • Mastering Kibana 6.x
  • Anurag Srivastava
  • 313字
  • 2021-07-16 18:20:06

Logstash

Logstash is basically used for data pipelining, through which we can take input from different sources and output to different data sources. Using Logstash, we can clean the data through filter options and mutate the input data before sending it to the output source. Logstash has different adapters to handle different applications, such as for MySQL or any other relational database connection. We have a JDBC input plugin through which we can connect to MySQL server, run queries, and take the table data as the input in Logstash. For Elasticsearch, there is a connector in Logstash that gives us the option to seamlessly transfer data from Logstash to Elasticsearch.

To run Logstash, we need to install Logstash and edit the configuration file logstash.conf, which consists of an input, output, and filter sections. We need to tell Logstash where it should get the input from through the input block, what it should do with the input through the filter block, and where it should send the output through the output block. In the following example, I am reading an Apache Access Log and sending the output to Elasticsearch:

input {
file {
path => "/var/log/apache2/access.log"
}
}

filter {
grok {
match => { message => "%{COMBINEDAPACHELOG}" }
}
}

output {
elasticsearch {
hosts => "http://127.0.0.1:9200"
index => "logs_apache"
document_type => "logs"
}
}

The input block is showing a file key that is set to /var/log/apache2/access.log. This means that we are getting the file input and path of the file, /var/log/apache2/access.log, which is Apache's log file. The filter block is showing the grok filter, which converts unstructured data into structured data by parsing it.

There are different patterns that we can apply for the Logstash filter. Here, we are parsing the Apache logs, but we can filter different things, such as email, IP addresses, and dates.

主站蜘蛛池模板: 巫溪县| 齐河县| 淳安县| 海宁市| 平乐县| 多伦县| 乐陵市| 安平县| 义马市| 蕉岭县| 苗栗市| 镇雄县| 江北区| 望江县| 陇西县| 广水市| 石台县| 辽阳市| 黎城县| 白朗县| 皮山县| 绩溪县| 汨罗市| 华坪县| 宿松县| 色达县| 青神县| 呼玛县| 梁平县| 惠州市| 大悟县| 正安县| 大化| 东阿县| 宣威市| 郓城县| 长丰县| 鄱阳县| 雷波县| 彰化市| 桃园市|