Logstash很強大,之前使用過input中的beat插件,現(xiàn)改成用http插件出皇,在這里又跳坑了,留個紀念哗戈。
- 配置http
input {
http {
codec => plain {
charset=>"GB2312"
}
}
}
特別注意郊艘,在python代碼中 data數(shù)據(jù) 通過encode('utf8')后,傳入logstash唯咬,即使在解碼回纱注,還是回不到原來的。所以這里用了GB2312胆胰。
啟動logstash狞贱,開啟8080端口
python中代碼調用
post_url = 'http://192.168.220.123:8080/'
#以上地址為logstash的訪問地址
postData ={'test': '2017-08-15 18:25:22|20.63.150.241|上海|23124@etest'}
data = urllib.parse.urlencode(postData)
data = data.encode('utf8')
req = urllib.request.Request(post_url, data)
response = urllib.request.urlopen(req)
page = response.read()
status = response.getcode()
result = post_url + '|' + str(status) + '\n'
print (result)
- 在通過http接口吐出數(shù)據(jù)
http {
http_method => "post"
url => "http://192.168.220.123:6070/report/playstatus?log="
#接數(shù)據(jù)的地址
format => "message"
headers => ["X-My-Header", "%{host}"]
message => "%{message}"
}
特別注意,logstash的output的http怎么帶參數(shù)的問題蜀涨,在之前嘗試時將參數(shù)直接在寫log=后面瞎嬉,當參數(shù)中存在空格或其他特殊字符時 到接口應用中就會到500錯誤。
而http流是將body轉成event厚柳,可以將參數(shù)信息放在body中氧枣,接口應用去讀body的內容即可。
關于其他Logstash配置可以參考logstash配置文件常用參數(shù)