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

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.

主站蜘蛛池模板: 丁青县| 游戏| 洛宁县| 保定市| 邵东县| 临武县| 永靖县| 嘉荫县| 毕节市| 德庆县| 奎屯市| 龙南县| 周宁县| 滨海县| 夏河县| 茂名市| 汶上县| 剑河县| 肇庆市| 思茅市| 卓尼县| 宁陵县| 阜康市| 延寿县| 东兰县| 临澧县| 乌拉特后旗| 台湾省| 湄潭县| 丰城市| 都江堰市| 旅游| 年辖:市辖区| 武冈市| 汝阳县| 宜宾县| 郓城县| 清原| 华亭县| 彰化县| 平凉市|