logstash輕鬆過濾海量日誌,研究下logstash的其它插件,能夠輕鬆監控日誌並報警,爽歪歪了,直接附上腳本php
監控說明:redis
一、sonp.php son-server.php 這兩個URL小於100字節,狀態碼非200,報警 二、全部狀態碼非200,報警 三、全部請求超過10S,報警
郵件本機配置postfix或者sendmail,json
監控腳本bash
input { redis { host => "127.0.0.1" port => "6379" data_type => "list" key => "logstash" type => "redis-input" codec => "json" } #我這裏直接是從redis取出日誌,上篇有介紹,固然也能夠直接從日誌文件取 } filter{ mutate { convert => [ "[bytes_read]", "float" ] #爲了輸出編碼一致,咱們這裏將字節轉成float } grok { match => [ "message" ,"sonp\.php|son-server\.php" ] #日誌中匹配的內容, add_tag => [myurl] } } output { if [response] != "200" or [request_time] >= 10 { #監控狀態碼非200 或者 請求時間大於10s exec { command => "echo '%{@timestamp}: %{message}' | mail -s 'Log_error: request time or response' urname@urdomain" } } if [bytes_read] < 100 and [response] != "200"{ #監控字節數小於100和請求非200 exec { tags => [myurl] command => "echo '%{@timestamp}: %{message}' | mail -s 'Log_error: bytes and response' urname@urdomain" } } }
#logstash/bin/logstash agent -f log_monitor.conf &
後臺啓動腳本,靜靜等待郵件報警吧~~dom