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": "phachon@163.com", //发送方的邮件
"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: 'phachon@163.com',
to: '******@**.com',
subject: '=?UTF-8?Q?Nginx 报警?=' },
content: 'text/plain; charset=utf-8',
text: 'nginx 应用响应时间超过 0.01秒' }
证明邮件已经发生成功。