关于logstash的filter过滤完日志向elasticsearch存数据的问题

Edisonnnn 2017-05-08 08:20:26
各位好,有一个问题想请教一下,logstash设置完filter后,确实过滤了我不想要的日志,因为终端输出可以看到,但output写人elasticsearch时,确把过滤的日志也写入了es中,相当于走了一遍过滤器然后原值又直接给了es。。。很是不解

conf如下:
input {
file {
path => "/root/logstash/logstash-1.4.2/mytest/messages"
}
}

filter {
if ([message] =~ "^(?!.*?abc).*$") { //把不包含 “abc”的日志行删掉
drop {}
}
}

output {
elasticsearch {
host => ["localhost"]
protocol => "http"
index => "system-message-%{+YYYY.MM.dd}"

}
stdout { codec => rubydebug}
}
...全文
880 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_40826988 2019-07-24
  • 打赏
  • 举报
回复
windows下上面的path =>路径写磁盘绝对路径吗
Edisonnnn 2017-05-09
  • 打赏
  • 举报
回复
昨天抽风了,今天一早又测一遍好使了~~
通常,日志被分散的储不同的设备上。如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志。这样是不是感觉很繁琐和效率低下。开源实时日志分析ELK平台能够美的解决日志收集和日志检索、分析的问题,ELK就是指ElasticSearchLogstash和Kiabana三个开源工具。 因为ELK是可以跨平台部署,因此非常适用于多平台部署的应用。 二 环境准备 1. 安装JDK1.8环境 2. 下载ELK软件包 logstash: https://artifacts.elastic.co/downloads/logstash/logstash-5.5.0.zip elasticsearch:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.zip kibana: https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-windows-x86.zip 分别解压下载的软件,elasticsearchlogstash,kibana 可以放在一个统一文件夹下 三 部署 1.配置logstashlogstash文件夹的下bin目录创建配置文件logstash.conf ,内容如下: input { # 以文件作为来源 file { # 日志文件路径 path => "F:\test\dp.log" } } filter { #定义数据的格式,正则解析日志(根据实际需要对日志日志过滤、收集) grok { match => { "message" => "%{IPV4:clientIP}|%{GREEDYDATA:request}|%{NUMBER:duration}"} } #根据需要对数据的类型转换 mutate { convert => { "duration" => "integer" }} } # 定义输出 output { elasticsearch { hosts => ["localhost:9200"] #Elasticsearch 默认端口 } }   在bin目录下创建run.bat,写入一下脚本: logstash.bat -f logstash.conf 执行run.bat启动logstash。 2. 配置Elasticsearch elasticsearch.bat即可启动。 启动后浏览器访问 127.0.0.1:9200 ,出现以下的json表示成功。 3.配置kibana Kibana启动时从文件kibana.yml读取属性。默认设置配置Kibana运行localhost:5601。要更改主机或端口号,或者连接到在其他机器上运行的Elasticsearch,需要更新kibana.yml文件。 kibana.bat启动Kibana。
开源实时日志分析ELK平台能够美的解决我们上述的问题,ELK由ElasticSearchLogstash和Kiabana三个开源工具组成。 官方网站:https://www.elastic.co/products Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash是一个全开源的工具,他可以对你的日志进行收集、过滤,并将其储供以后使用(如,搜索)。 Kibana 也是一个开源和免费的工具,它Kibana可以为 LogstashElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ELK下载:https://www.elastic.co/downloads/ ELK工作原理: ElasticSearch 配置ElasticSearch: 1 2 unzip elasticsearch-6.2.4.zip cd elasticsearch-6.2.4 然后编辑ES的配置文件: 1 vi config/elasticsearch.yml 修改以下配置项: 1 2 3 4 5 6 7 cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是node1 network.host=node1 network.port=9200 其他的选项保持默认,然后启动ES: 1 nohup sh elasticsearch > nohup.log & 注意: 1.需要添加用户elk,ES不能以root用户进行启动 2.可能出现的错误: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 1 2 3 vi /etc/security/limits.conf elk soft nofile 819200 elk hard nofile 819200 max number of threads [1024] for user [work] likely too low, increase to at least [2048] 1 2 3 4 vi /etc/security/limits.d/90-nproc.conf * soft nproc 1024 #修改为: * soft nproc 2048 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 1 2 3 4 5 vi /etc/sysctl.conf #增加改行配置: vm.max_map_count=655360 #保退出后,执行: sysctl -p 另外再配置ES的时候,threadpool.bulk.queue_size 已经变成了thread_pool.bulk.queue_size ,ES_HEAP_SIZE,ES_MAX_MEM等配置都变为ES_JAVA_OPTS这一配置项,如限制内最大最小为1G: 1 export ES_JAVA_OPTS="-Xms1g -Xmx1g" 然后可以打开页面http://node1:9200/,将会看到以下内容:(我是通过外部访问虚拟机,因此为了简单没有配置host文件,直接用ip访问) Logstash 配置Logstash: 1 2 tar -zxvf logstash-6.2.4.tar.gz cd logstash-6.2.4 编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log_app.conf): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 vi config/log_app.config #以下为内容 input { file { path => "/usr/local/software/elk/app.log" start_position => "beginning" #从文件开始处读写 } # stdin {} #可以从标准输入读数据 } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "node1:9200" #ElasticSearch host, can be array. index => "applog" #The index to write data to. } } 其他的选项保持默认,然后启动Logstash: 1 2 # -f为指定配置文件 nohup sh ./bin/logstash -f ../config/log_app.config > nohup.log & 日志: Kibana 配置Kibana: 1 2 tar -zxvf kibana-6.2.4-linux-x86_64.tar.gz cd kibana-6.2.4-linux-x86_64 修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示): 1 2 3 4 server.port: 5601 server.host: “node1” elasticsearch.url: http://node1:9200 kibana.index: “.kibana” 启动kibana: 1 nohup sh ./bin/kibana > nohup.log & 启动后界面: 然后需要创建index,步骤如下: ①点击左边iscover出现以下界面 ②按照注释配置,然后点击Next step,在第二页 选择@timestamp点击create创建 ③创建成之后,可以看到以下一个界面,红框内是 自动生成的域,也可以理解为 跟数据库中的字段类似,其中有一个message字段,就是我们想要的日志信息。 ④再次点击Discover出现以下界面,可以看到默认搜索的是最后15分钟的日志,可以通过点击设置搜索的时间范围. ⑤可以点击右侧域的add设置需要显示的字段 添加成之后,日志显示如下:

50,503

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧