logstash 介绍

2017-07-31  本文已影响1121人  bdslinux

logstash

它一个有jruby语言编写的运行在java虚拟机上的具有收集
分析转发数据流功能的工具

安装logstash

logstash运行参数

配置语法

语法格式

logstash插件

logstash-plugins

logstash inputs 配置

input {
    stdin {
    } 
}
outpu {
    stdout {
    } 
}

stdin

stdin {
    add_field => { "a" => "b" }
    codec => "json"
    tags => "["a","b"]"
    type => "my_type"

} 

file

input {
    file {
        path => ["/var/log/nginx/access.log"] 
        type => "nginx-log"  
        start_position => 'beginning'
    } 
} 
output {
    stdout {} 
}


tcp/udp

input {
    tcp {
        port => 9090 
        mode => "server"
        ssl_enable => false 
        
    }
}
output {
    stdout {} 
    
} 
nc 127.0.0.1:9090 < data

input {
    udp {
        host => "127.0.0.1" 
        port => 5050        
    }   
} 
output {
    stdout {} 
    
} 

#python udp客户端
import socket 
port = 5050
host = "127.0.0.1"
file_input = raw_input("\033[32;1mPlease input: \033[0m")
s = socket.socket(socket.AF_INET,socket_SOCK_DGRAM) 
s.sendto(file_input,(host,port))

rsyslog

input {
    syslog {
        host => "127.0.0.1" 
        type => "syslog" 
        port => 518 
        
    } 

} 
output {
    stdout { } 

} 
###
vim /etc/rsyslog.conf 
*.* @@127.0.0.1:518
### 
logger 命令模拟发送日志

编码

# plain
input {
    stdin {
        codec => 'plain'
    } 
} 
output {
    stdout { }  
} 
# json
input {
    stdin {} 

} 
output {
    stdout {
        codec => "json" 
    }

} 
#json_lines
input {
    tcp {
        port => 12345
        host => '127.0.0.1'
        codec => json_lines 
    
    }
}
output {
    stdout { } 
}
#rubydebug 
input {
    stdin {
        codec => json 
    }
} 
output {
    stdout {
        codec => rubydebug 
    }
} 

multiline

input {
    stdin {
        codec => multiline {
            charset => ""     #字符编码
            max_bytes =>        #最大字节数
            max_lines =>      #最大行数,默认500
            multiline_tag =>  #设置一个事件标签,默认multiline
            pattern =>          #string匹配规则
            patterns_dir =>    #array多个匹配规则
            negate => false   #设置正向匹配还是反向匹配
            what   => next    #匹配的内容后,后面多行的日志是向前靠拢还是向后靠拢,previous,next
        }
    
    
    }
}
input {
    stdin {
        codec = multiline {
            pattern => "^\["
            negate => true
            what => previous
        
        }
    
    }
} 
output {
    stdout {
        codec => rubydebug 
    
    } 
} 

logstash filter 配置

grok filter

kv filter

logstash output 配置

output file

output {
    file {
        path => "/root/access_result"
        #message_format => "%{ip}" 
        #path => "/root/access_%{+YYYY.MM.DD}_%{host}.txt"  
        #gzip => true 
    
    }
    stdout {
        codec => rebydebug 
        
    }
}
output {
    tcp {
        codec => json_lines 
        host => "127.0.0.1"
        port => "4050"
        mode => "server"
    }

}

output {
        udp {
            host => "127.0.0.1"
            port => 4050
        }
} 
output {
    elasticsearch {
        host => "127.0.0.1" 
        protocol => "http" 
        index => "test_output-%{type}-%{+YYYY.MM.dd}"
        document_type => "nginx" 
        workers => 5

    }
}
上一篇 下一篇

猜你喜欢

热点阅读