ELK的環境搭建好之后,如何利用收集到的數據進行數據告警呢?在破解ELK之后,它本身提供一個監視器功能,配置偏向編寫腳本。有一個更加方便的插件sentiel。
一、下載並安裝sentinl插件
https://github.com/sirensolutions/sentinl/releases/ 上下載對應版本
在對應目錄下執行 kibana/bin/ kibana-plugin install file:///users/xxx/xxx/sentinl.6.4.2.zip(最好先下載在上傳至服務器,避免網絡中斷的情況)
執行完之后,可以在kibana界面左側看到 steninl功能菜單
二、配置郵件發送
1. 在 kibana.yml中最下方配置
sentinl: settings: email: active: true user: abc@qq.com 【注:這里配置的郵箱賬號在配置發送郵件方的時候需要用,如果與它不一致會發不出去】 password: xxxxx 【注:在qq郵箱處設置三方登錄密碼】 host: smtp.exmail.qq.com ssl: true port: 465 【注:linux系統如果是阿里雲的會禁用默認的25端口,這里需要設置465】 timeout: 10000 report: active: false
2. 點擊Sentinl – watchers – new – watcher wizard【界面友好可】 或者watcher advanced【直接編寫程序,更靈活方便適用】
這是我用watcher advanced 配置的一個簡單的 每5分鍾檢查最近五分鍾產生的異常信息的配置。
{
"actions": { "email_html_alarm_2bb619c8-0d33-4b42-bbaa-38dbf5ca040f": { "name": "5分鍾內日志記錄", "throttle_period": "1m", "email_html": { "stateless": false, "subject": "{{watcher.title}}-最近的Exception信息", "priority": "high", "html": "哈嘍,請認領自己的bug,抓緊處理哦!!!<br>{{#payload.hits.hits}} \n<li style='color:red'><b>source:</b> {{_source.source}} </li><br><li><b>message</b>: {{_source.message}}</li><br><br>{{/payload.hits.hits}} \n", "to": "xxx@qq.com", "from": "abc@qq.com" } } }, "input": { "search": { "request": { "index": [ "filebeat-6.4.2-*" ], "body": { "query": { "bool": { "must": [ { "range": { "@timestamp": { "gte": "now-5m/m", "lte": "now/m", "format": "epoch_millis" } } } ], "filter": [ { "multi_match": { "type": "best_fields", "query": "exception", "lenient": true } } ] } }, "size": 5, "aggs": { "dateAgg": { "date_histogram": { "field": "@timestamp", "time_zone": "Europe/Amsterdam", "interval": "1m", "min_doc_count": 1 } } } } } } }, "condition": { "script": { "script": "payload.aggregations.dateAgg.buckets.some(b => b.doc_count >= 0)" } }, "trigger": { "schedule": { "later": "every 5 minutes" } }, "disable": false, "report": false, "title": "測試環境service2+uic日志錯誤提醒", "save_payload": false, "spy": false, "impersonate": false } } }
3.配置好之后可以在 Watchers中看到
第一個按鈕可以進行測試,即時發送
第二個按鈕可以設置開啟定時按照Interval中的時間進行定時搜索發送
注如果要用上面的配置,需要修改對應的索引名稱,搜索條件等。確保自己的索引有效且能正常搜索數據。
以下是收到的郵件