Logstash notes of Distributed log collection (i)

Source: Internet
Author: User
Tags solr apache log kibana logstash



(a) What is Logstash? 

Logstash is a distributed Log collection framework, the development language is JRuby, of course, is to interface with the Java platform, but with Ruby syntax is good, very concise and powerful, often with Elasticsearch,kibana configuration, composed of the famous Elk technology stack, Ideal for analysis of log data.

Of course it can appear alone, as the log collection software, you can collect logs to a variety of storage systems or temporary transit systems, such as MYSQL,REDIS,KAKFA,HDFS, LUCENE,SOLR, etc. is not necessarily elasticsearch.

Official website: Https://www.elastic.co/downloads/logstash 
Official Document Address: https://www.elastic.co/guide/en/logstash/current/index.html 


(ii) installation of the Logstash 

The current version of Logstash is 2.0.0, which is recommended to install on the Linux platform, although it also supports Windows platforms, but there may be problems 
Download: 
wget https://download.elastic.co/logstash/logstash/logstash-2.0.0.tar.gz 

Extract: 
TAR-ZXVF logstash-2.0.0.tar.gz 

Go to the root directory and execute bin/logstash-h to view Help documents 
The parameters are described as follows: 

To use a command template: 
/bin/logstash Command parameter options 

Options: 
-F, specifies that a Logstash configuration module with a suffix of. conf file is loaded 
-E, command line specifying parameters, typically used to debug 
-W, specifying the number of worker threads for Logstash 
-L, specifies that the default log for Logstash is written to a file, and if not specified, the default is standard output 
--quiet silent mode, only error level information output 
--verbose Info-level log output 
--debug the log output of the debug level. 
-V,--version view version of Logstash 
-P,--pluginpath PATH loads the custom Logstash plugin 
-T,--configtest Check if the Logstash configuration is valid 
-H,--help printing help 


(iii) Data processing model of Logstash 

(1) input = "Output" 
(2) input = "Filter =" Output 

Input sources commonly used are: File,syslog,redis,log4j,apache log or Nginx log, or some other custom log format, business log, search log, order Log, etc.

The common options for filter are: 
Grok: Supports regular extraction of any unstructured or structured data, with more than 120 regular logstash built-in, such as common time, IP, username, and so on, to support custom regular parsing 
Mutate: Modify field name, delete, update etc., convert field type, etc. 
Drop: Delete some time, such as debug 
Clone: Copy a copy of the event to add or remove fields 
GeoIP: Get geo-location information via IP, kibana area charts are awesome 
Ruby: Supports native ruby code, operates events, and implements powerful other functions 

Output common outputs are: 
Elasticsearch more commonly used 
File: Writing Files 
Redis: Write queue 
HDFs: Write HDFs, plug-in support required 
Zabbix:zabbix Monitoring 
MongoDB: Writing to the MongoDB library 

Besides, there's a code plugin codecs is also more commonly used 
Often used to process JSON data or multiple rows of data sources 



(iv) Logstash some simple examples 

(1) Debug with command-line commands: 
[Java]  View Plain Copy
  1. [Search@h3 logstash-2.0. 0 ]$ bin/logstash-e "input{stdin{}} output{stdout{}}"
  2. Default Settings Used:filter workers: 1
  3. Logstash Startup completed
  4. Hello
  5. --04t15:747Z h3 Hello
  6. Test
  7. --04t15:108Z h3 test

(2) command-line parameters are only suitable for simple configuration, if the configuration is more, we will generally write to a. conf end of the configuration file , and then use
The-f command loads the configuration in (1) and writes the hello.conf

And then use Bin/logstash-f hello.conf to perform the load to achieve the same effect


(3) Common data modules
[Java]  View Plain Copy
  1. <pre name="code" class="java">input{
  2. .....     
  3. }     
  4. filter{
  5. ......     
  6. }     
  7. output{
  8. .......     
  9. }    
(4) Listen file, support wildcard character, write file [Java]  View Plain Copy
  1. input{
  2.     
  3. file = ["/var/log/file","/var/solr/log/*"]
  4.     
  5. }     
  6.     
  7. output{
  8.     
  9. file = "/sys/collect/log"
  10.     
  11.     
  12. }    
(5) Logstash plug-in support data type [Java]  View Plain Copy
  1. array: path=> ["A","B"]
  2. Boolean: ssl_enable = true
  3. bytes:
  4. my_bytes ="1113"#1113 bytes
  5. my_bytes ="10MiB"#10485760 bytes
  6. my_bytes ="100kib"#102400 bytes
  7. my_bytes ="MB"#180000000 bytes
  8. Code:
  9. codec = "JSON"
  10. Hash Table:
  11. Match + = {
  12.     
  13. "K1" = " v1 "
  14. "K2" = " v2 "
  15. "K3" = " v3 "
  16.     
  17. }     
  18. Value:
  19. port=>
  20. Password:
  21. pwd=> "password"
  22. Path:
  23. path=> "/tmp/logstash"
  24. string:
  25. name = "Hello wordld"
  26. notes:
  27. input{
  28. # starts with a shell script comment
  29. }    

Logstash notes of Distributed log collection (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.