Kibana 可視化監控報警插件 KAAE 的介紹與使用
- Kibaba
- Kaae
最近在學習 ELK 時發現個 Kibana 的插件 Kaae,主要是用來監控和報警,有可視化的操作界面,配置簡單。百度和谷歌都沒有找到相關的使用資料,所以在這裏總結一下。
介紹
github地址:https://github.com/sirensolutions/kaae
安裝略過,github已經有了
實現監控併發報警郵件
實現的目標:監控 nginx 請求時間大於 0.01 秒的時候,發送報警郵件到郵箱。
將 kaae 下的 kaae.json 文件拷貝到 /etc/kaae.json,kaae 啓動會自動先讀取 /etc/kaae.json 文件
{
"es": {
"timefield": "@timestamp",
"default_index": "watcher",
"type": "watch",
"alarm_index": "watcher_alarms"
},
"kaae": {
"history": 20,
"results": 50
},
"settings" : {
"email" : {
"user": "phachon", //郵箱賬號
"password": "****", // 郵箱密碼
"host": "smtp.163.com", // 郵箱smtp 服務器地址
"ssl": true, // 是否 ssl 驗證
"active": true // 這裏要注意,默認的配置文件是 false,要改成 true,纔會發送郵件成功
},
"slack" : {
"username": "KAAE",
"hook": "https://hooks.slack.com/services/<token>",
"channel": "#kaae",
"active": false
},
"report" : {
"tmp_path" : "/tmp/",
"active": false
},
"pushapps" : {
"api_key" : "<pushapps API Key>",
"active": false
}
}
}
然後打開 kibana 的頁面
點擊 Kaae
點擊右上角的 + 號,添加一個 watcher
需要修改下面的配置文件
{
"_index": "watcher",
"_type": "watch",
"_id": "new_watcher_knuutw2ho",
"_score": 1,
"_source": {
"trigger": {
"schedule": {
"later": "every 1 minutes" // 每一分鐘執行
}
},
"input": {
"search": {
"request": {
"index": [
"nginx-log" // 索引名字
],
"body": {}
}
}
},
"condition": {
"script": {
"script": "payload.hits.hits[0]._source.responsetime > 0.01" // 檢索條件 響應時間大於 0.01秒
}
},
"transform": {},
"actions": {
"email_admin": {
"throttle_period": "15m",
"email": {
"to": "*****@***.com", //要發送到的郵件
"from": "[email protected]", //發送方的郵件
"subject": "Nginx 報警", //郵件主題
"priority": "high", //級別
"body": "nginx 應用響應時間超過 0.01秒" //郵件正文
}
}
}
}
}
這是很簡單的配置文件,主要是能實現發送郵件的功能。
這裏 condition 條件有好幾種設置方法,script 只是其中的一種。具體可以看官方的 wiki
payload.hits.hits[0]._source 裏面就是你日誌裏自定義的字段。
查看 kibana 的打印log:
log [17:20:00.004] [info][status][KaaE] Executing watch: new_watcher_knuutw2ho
log [17:20:00.016] [info][status][KaaE] Executing watch: new_watcher_4khg6v0oz
log [17:20:00.071] [info][status][KaaE] Action Report requires Email Settings! Reports Disabled.
log [17:20:00.074] [info][status][KaaE] Processing action: email_admin
log [17:20:00.078] [info][status][KaaE][email] Subject: KaaE Alarm TEST, Body: Found 585794 Events
log [17:20:00.078] [info][status][Kaae][email] Delivering to Mail Server
log [17:20:00.098] [info][status][KaaE] Storing Alarm to ES with type:email_admin
log [17:20:02.592] [info][status][Kaae][email] { attachments: [],
alternative: null,
header:
{ 'message-id': '<1480584000079.0.31566@bj05-ic-gvs01>',
date: 'Thu, 01 Dec 2016 17:20:00 +0800',
from: '[email protected]',
to: '******@**.com',
subject: '=?UTF-8?Q?Nginx 報警?=' },
content: 'text/plain; charset=utf-8',
text: 'nginx 應用響應時間超過 0.01秒' }
證明郵件已經發生成功。