加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

你头疼的ELK难题,本文几乎都解决了

发布时间:2019-03-23 04:12:43 所属栏目:Windows 来源:alonghub
导读:副标题#e# 一、ELK实用知识点总结 1、编码转换问题 这个问题,主要就是中文乱码。 input中的codec=plain转码: codec=plain{ charset=GB2312 } 将GB2312的文本编码,转为UTF-8的编码。 也可以在filebeat中实现编码的转换(推荐): filebeat.prospectors: -in

不推荐的原因:

  • filter设置multiline后,pipline worker会自动降为1;
  • 5.5 版本官方把multiline 去除了,要使用的话需下载,下载命令如下:
  1. /usr/share/logstash/bin/logstash-plugin install logstash-filter-multiline 

示例:

  1. filter { 
  2.   multiline { 
  3.     pattern => "^20.*" 
  4.     negate => true 
  5.     what => "previous" 
  6.   } 
  7. }  

5、logstash filter中的date使用

日志示例:

  1. 2018-03-20 10:44:01 [33]DEBUG Debug - task request,task Id:1cbb72f1-a5ea-4e73-957c-6d20e9e12a7a,start time:2018-03-20 10:43:59 

date使用:

  1. date { 
  2.                 match => ["InsertTime","YYYY-MM-dd HH:mm:ss "] 
  3.                 remove_field => "InsertTime" 
  4.         } 

注:match => ["timestamp" ,"dd/MMM/YYYY H:m:s Z"]

匹配这个字段,字段的格式为:日日/月月月/年年年年 时/分/秒 时区,也可以写为:match => ["timestamp","ISO8601"](推荐)

date介绍:

就是将匹配日志中时间的key替换为@timestamp的时间,因为@timestamp的时间是日志送到logstash的时间,并不是日志中真正的时间。

6、对多类日志分类处理(重点)

在filebeat的配置中添加type分类:

  1. filebeat: 
  2.   prospectors: 
  3.     - 
  4.       paths: 
  5.         #- /mnt/data/WebApiDebugLog.txt* 
  6.         - /mnt/data_total/WebApiDebugLog.txt* 
  7.       fields: 
  8.         type: WebApiDebugLog_total 
  9.     - 
  10.       paths: 
  11.         - /mnt/data_request/WebApiDebugLog.txt* 
  12.         #- /mnt/data/WebApiDebugLog.txt* 
  13.       fields: 
  14.         type: WebApiDebugLog_request 
  15.     - 
  16.       paths: 
  17.         - /mnt/data_report/WebApiDebugLog.txt* 
  18.         #- /mnt/data/WebApiDebugLog.txt* 
  19.       fields: 
  20.         type: WebApiDebugLog_report 

在logstash filter中使用if,可进行对不同类进行不同处理:

  1. filter { 
  2.    if [fields][type] == "WebApiDebugLog_request" {   #对request 类日志 
  3.         if ([message] =~ "^20.*- task report,.*,start time.*") {   #删除report 行 
  4.                 drop {} 
  5.         } 
  6.     grok { 
  7.         match => {"... ..."} 
  8.         } 

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读