logstash filter 学习

案例 读取文本文件 内容:
vi a.cong
input {
stdin{}
}
filter{
mutate{
       split=>["message",","]
   }
   mutate{
       split=>["message",":"]
   }
   mutate{
       add_field=>{
           "id"=>"%{[message][0][1]}"
           "ip"=>"%{[message][1][1]}"
       }
   }
geoip{
source=>"ip"
}
}
output {
 elasticsearch {
   hosts => ["localhost"]
   manage_template => false
   index => "test"
   document_type => "my_type"
 }
 stdout {
                codec => rubydebug
        }
}
执行 ./bin/logstash -f a.conf
输入 192.168.1.12,10

案例2 es 导入 es index
vi b.conf
input {
        elasticsearch {
                hosts => "localhost"
                index=>"test"
        }
}
filter{
geoip{
source=>"ip"
}
}
output {
        elasticsearch {
                hosts => "localhost"
                index=>"test"
        }
        stdout {
                codec => rubydebug
        }
}
案例3 json 格式 处理 :  比如 : {"id":2,"ip":"12x.xx6.xx.6"}
input{
    stdin{}
}
filter{
    mutate{
        replace=>[
            "message",
            "%{message}"
        ]
    }json{
        source=>"message"remove_field=>"message"
    }mutate{
        convert=>[
            "latitude",
            "float"
        ]convert=>[
            "longitude",
            "float"
        ]
    }mutate{
        rename=>[
            "latitude",
            "[location][lat]",
            "longitude",
            "[location][lon]"
        ]
    }mutate{
        add_field=>{
            "new_ip"=>"%{id}"
        }
    }geoip{
        source=>"ip"
    }
}
output{
    stdout{
        codec=>rubydebug
    }

}

继续 学习中,。。。。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值