构建即时日志分析监控系统
filebeat日志收集
filebeat安装
shell
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.1-linux-x86_64.tar.gz
tar -zxvf filebeat-6.2.1-linux-x86_64.tar.gz
配置filebeat.yml
filebeat.prospectors:
- type: log
enabled: true
paths:
- /home/nginx/logs/gc.supsite.work.log
fields: # 增加个字段用来区分来源数据
log_type: log-supsite-work
fields_under_root: true
#setup.kibana:
# host: "localhost:5601"
output.logstash:
hosts: ["192.168.8.165:5044"]
logstash接收格式化并传输给指定目标
logstash安装
https://www.elastic.co/downloads/logstash 下载解压
conf/test.conf 新增配置文件
./bin/logstash -f config/test.conf
基本配置,输出到文件
input {
beats {
port => '5044'
}
}
output {
if [log_type] == "log-supsite-work" { # 根据log_type区分判断下来源,输出到不同的文件
file {
path => "/tmp/logstash_work.log"
codec => line { format => "%{host} %{message}" }
flush_interval => 0
}
}
stdout {
codec => rubydebug
}
}
logstash处理数据会默认新增字段@timestamp, 默认存储logstash接收数据的时间
date插件
date {
match => [ "time_field", "yyyyMMdd HH:mm:ss.SSS" ]
# timezone => "UTC"
target => "end_time"
}
上面的意思是把time_field按照yyyyMMdd HH:mm:ss.SSS的格式解析后存到target指定的字段end_time, end_time必须是已经定义的字段,没有没有指定,默认就是@timestamp字段,所以可以用来修改@timestamp
timezone可以指定时区
https://time-track.cn/modify-attimestamp-field-in-logstash.html
https://blog.csdn.net/qq_33283716/article/details/83055655
https://www.zybuluo.com/StrGlee/note/1179723