博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Logstash的配置文件中对日志事件进行区分
阅读量:4357 次
发布时间:2019-06-07

本文共 2135 字,大约阅读时间需要 7 分钟。

1、多个日志文件作为输入源

input {    # 通过给日志事件定义类型来区分    file {        path => ["/var/log/nginx/access.log"]        type => "nginx_access"        start_position => "beginning"    }        # 通过给日志事件定义类型来区分    file {        path => ["/var/log/nginx/error.log"]        type => "nginx_error"        start_position => "beginning"    }    # 通过给日志事件新增字段来区分    file {        path => ["/var/log/nginx/api.log"]        add_field => {
"myid" => "api"} start_position => "beginning" }}filter { # 判断类型后,分别对事件做相应处理 if [type] == "nginx_access" { grok { match => { "message" => "" } } } if [type] == "nginx_error" { grok { match => { "message" => "" } } } if [myid] == "api" { grok { match => { "message" => "" } } }}output { # 根据类型的不同,分别存储到不同的索引名称中 if [type] == 'nginx_access' { elasticsearch { hosts => ["127.0.0.1:9200"] index => "logstash_access-%{+YYYY.MM.dd}" } } if [type] == 'nginx_error' { elasticsearch { hosts => ["127.0.0.1:9200"] index => "logstash_error-%{+YYYY.MM.dd}" } } if [myid] == "api" { elasticsearch { hosts => ["127.0.0.1:9200"] index => "logstash_api-%{+YYYY.MM.dd}" } }}

 

2、以redis作为输入源

input {    redis {        host => '10.105.199.10'        type => 'web_error'        port => '8000'        data_type => 'list'        key => 'web_error'        password => "E1e7ed7eF437416165597b956fac004e"        db => 0    }}output {    if [type] == "web_error" {        elasticsearch {            hosts => ["127.0.0.1:9200"]            index => "logstash_web_error-%{+YYYY.MM.dd}"        }    }}

 

 3、以kafka作为输入源

input {    kafka {        bootstrap_servers => "10.105.199.10:9092"        topics => ["www.example.com"]        codec => "json"    }}filter {    grok {        match => {            "message" => "正则表达式匹配nginx日志"        }    }}output {    elasticsearch {        hosts => ["127.0.0.1:9200"]        index => "logstash-www.example.com_%{+YYYY.MM.dd}"    }}

转载于:https://www.cnblogs.com/t-road/p/11274751.html

你可能感兴趣的文章
加班与效率
查看>>
MyEclipse下SpringBoot+JSP整合过程及踩坑
查看>>
重定向和管道
查看>>
实验五
查看>>
STL学习笔记(第二章 C++及其标准程序库简介)
查看>>
Operator_countByValue
查看>>
Java 日期往后推迟n天
查看>>
Web应用漏洞评估工具Paros
查看>>
Git 和 Github 使用指南
查看>>
20180925-4 单元测试
查看>>
mysql的数据存储
查看>>
[转载] Activiti Tenant Id 字段释疑
查看>>
[Java 8] (8) Lambda表达式对递归的优化(上) - 使用尾递归 .
查看>>
SQL Server-聚焦移除Bookmark Lookup、RID Lookup、Key Lookup提高SQL查询性能
查看>>
最小权限的挑战
查看>>
jquery 视觉特效(水平滚动图片)
查看>>
SVG笔记
查看>>
linux下使用dd命令写入镜像文件到u盘
查看>>
物联网架构成长之路(8)-EMQ-Hook了解、连接Kafka发送消息
查看>>
2018-2019-1 20165234 20165236 实验二 固件程序设计
查看>>