原文地址: https://www.tony-yin.site/201...
上一篇文章詳細講解了ElastAlert
這款告警組件,今天咱們聊聊另外一個ES
開源告警組件Sentinl
。javascript
sentinl
是基於javascript
開發的kibana
插件,擁有告警和報表兩大功能,分別做爲X-Pack
的Alert
和Reporting
的替代品,即插即用,它將前端UI
、webserver
和告警邏輯代碼都集成在一個項目中,這一點要比上篇文章提到同爲kibana
插件的elastalert-kibana-plugin
要強大很多,而且能夠說sentinl
的UI
不管是美觀程度仍是操做友好程度都徹底秒殺elastalert-kibana-plugin
。說了這麼可能是不是sentinl
就很完美呢?請看下文慢慢講述。前端
elasticsearch: 6.4.2 kibana: 6.4.2 sentinl: 6.4.2
安裝環節很簡單,只須要進行通用的kibana
安裝插件的方式安裝便可。java
$ /usr/share/kibana/bin/kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/tag-6.4.2-0/sentinl-v6.4.2.zip
安裝完成之後,重啓kibana
服務便可在kibana
頁面上看到sentinl
。node
告警配置環節其實也很簡單,由於sentinl
大部分配置都是經過UI
建立告警的時候配置的,須要手動配置的地方並很少,只有告警方式相關的。python
和上節同樣,衆多告警方式咱們就選擇最廣泛的郵件告警進行講解linux
$ vim /etc/kibana/kibana.yml
在文件最下方添加如下配置:git
sentinl: settings: email: active: true // 開啓email方式 host: 'smtp.163.com' // smtp server user: 'xxx@163.com' // 發送郵箱帳號 password: 'xxx' //發送郵箱客戶端受權碼或密碼 timeout: 10000 // 鏈接smtp server的最大timeout
配置完成須要重啓kibana
服務才能夠生效。這裏須要注意的是host
、user
和password
三個選項,host
表示smtp
主機地址,user
表示發送郵箱的帳號,password
表示客戶端受權碼,若是沒有受權碼纔是密碼。github
若是這樣配置了,仍是沒法發送郵件成功,能夠經過查看kibana
的日誌定位緣由,大部分狀況都是因爲smtp server
鏈接失敗致使,能夠經過本地郵件客戶端進行測試:web
$ mailx -S smtp=<smtp-server-address> -r <from-address> -s <subject> -v <to-address> < body.txt
sentinl
除了提供告警功能,還提供了一個相似X-Pack Reporting
的報表功能。chrome
一樣這個功能須要開啓和配置,不得不說這個功能和相關文檔仍是存在着很多的問題,好比儘管文檔聲稱默認engine
是horseman
,可是如今默認的是puppeteer
。
官方文檔提供的配置例子是這樣的:
sentinl: settings: report: active: true executable_path: '/usr/bin/chromium' # path to Chrome v59+ or Chromium v59+
chromium
環境中不存在的話,手動下載後同步配置中對應的路徑:
sentinl: settings: active: true engine: 'puppeteer' executable_path: '/usr/bin/chromium-browser'
運用上述配置會有如下報錯:
Option "report.executable_path" was deprecated. The path is handled automatically!
報錯中顯示executable_path
這個選項已經被棄用,這個路徑會被自動解析,一臉懵逼,文檔中絲毫沒說起。。。
當時筆者也很奇怪,如何自動解析?如何知曉chromium
的路徑呢?這個下面再講,而後就先註釋掉該選項配置:
sentinl: settings: active: true engine: 'puppeteer' # executable_path: '/usr/bin/chromium-browser'
頁面換了個報錯:
ActionError: report action: execute: run 'puppeteer' report: puppeteer work
以下圖所示:
<center></center>
這個時候筆者就經過關鍵字谷歌搜索,發現sentinl
裏面有一個issue 535,裏面提到查看日誌裏面是否存在相似下面信息:
.... server log [07:52:27.332] [info][Sentinl][init] Chrome bin found at: /media/trex/safe1/Development/siren/kibi-internal/plugins/sentinl/node_modules/puppeteer/.local-chromium/linux-564778/chrome-linux/chrome ... server log [07:52:27.428] [info][Sentinl][init] PhantomJS bin found at: /media/trex/safe1/Development/siren/kibi-internal/plugins/sentinl/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ...
筆者去日誌裏面查了查,還真發現相似信息:
{"type":"log","@timestamp":"2018-11-23T10:27:44Z","tags":["error","Sentinl","init"],"pid":8219,"message":"setting puppeteer report engine: Error: user has no permissions to make file executable: /usr/share/kibana/plugins/sentinl/node_modules/puppeteer/.local-chromium/linux-564778/chrome-linux/chrome"}
以下圖所示
這就是爲何能夠自動解析chrome
路徑了,由於sentinl
內置了chrome
,因此sentinl
默認解析的是其內置chrome
路徑而非其餘第三方下載的,因此文檔中的/usr/bin/chromium
也有點誤導的感受。
這一段日誌提示chrome
沒有執行權限,因而查看權限:
$ ll /usr/share/kibana/plugins/sentinl/node_modules/puppeteer/.local-chromium/linux-564778/chrome-linux/chrome -rw-r--r-- 1 root root 206915904 Nov 22 10:16 /usr/share/kibana/plugins/sentinl/node_modules/puppeteer/.local-chromium/linux-564778/chrome-linux/chrome
果真是不存在執行權限,而後手動添加權限:
$ chmod +x /usr/share/kibana/plugins/sentinl/node_modules/puppeteer/.local-chromium/linux-564778/chrome-linux/chrome
更改以後這個報錯沒有了,可是又有了新的報錯(真是醉了):
Failed to load url
以下圖所示
而後繼續谷歌大法,在 issue 495 中看到了相關信息:
for the error "Failed to load url" I just replaced the action's url with a valide link from a chosen dashboard
因而返回告警配置界面,發現有一個url
選項,筆者也沒填(由於當時也不知道這個url
是幹嗎的)。結合上面這哥們描述的,該url
應該是kibana
上面dashbord
模塊中某個已經存在的dashbord
的連接,而後根據該dashbord
生成報表。
因而手動建立了一個dashbord
,而後將該dashbord
的url
更新至配置中的url
。
此次沒報錯了,report
也發送到了指定郵箱,可是report
是空的,這是由於新建立的dashbord
並無導入任何可視化圖表,因此將url
切換成了已經存在可視化圖表的dashbord
的url
,這下能夠發現發送的report
是存在圖表的。
結合以前monitoring
的瞭解,忽然想到這個url
可能不是dashbord
直接顯示的url
,而應該是經過share
功能提供的link
。
上面engine
選擇puppeteer
,筆者又嘗試將engine
切換成horseman
:
sentinl: settings: report: active: true engine: 'horseman'
換了engine
,依然報錯不停:
ActionError: report action: execute: run 'horseman' report: spawn EACCES
以下圖所示
其實這個問題,上文提到的 issue 535 中也給出了答案,horseman engine
依賴的是phantomjs
庫,puppeteer
依賴的是chrome
庫,問題2
是chrome
缺乏可執行權限,而spawn EACCES
這樣的關鍵字則表示phantomjs
庫沒法使用,根據上文chrome
的路徑筆者找到phantomjs
的路徑並檢查權限:
$ ll /usr/share/kibana/plugins/sentinl/node_modules/phantomjs-prebuilt/bin/phantomjs -rw-r--r-- 1 root root 1050 Nov 22 10:15 /usr/share/kibana/plugins/sentinl/node_modules/phantomjs-prebuilt/bin/phantomjs
發現phantomjs
也缺乏可執行權限,添加權限:
$ chmod +x /usr/share/kibana/plugins/sentinl/node_modules/phantomjs-prebuilt/bin/phantomjs
可是UI
上仍是有相同的報錯,只能繼續查看日誌,發現報錯:
{"type":"log","@timestamp":"2018-11-22T02:27:28Z","tags":["info","Sentinl","init"],"pid":21134,"message":"PhantomJS bin found at: /usr/share/kibana/plugins/sentinl/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs"}
原來sentinl
解析庫不是上面node_modules
目錄的那個路徑,而是在phantomjs
這個目錄下,查看權限狀況:
$ ls -lh /usr/share/kibana/plugins/sentinl/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs -rw-r--r-- 1 root root 65M Nov 22 10:15 /usr/share/kibana/plugins/sentinl/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
果真仍是缺乏執行權限,添加權限:
$ chmod +x /usr/share/kibana/plugins/sentinl/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
終於不報錯了。。。
這一系列問題,筆者也給sentinl
提了 issue,做者也表示了這個權限問題以後會經過腳本等方式自動處理,而後表示這個文檔沒有同步更新,能夠看最新同步文檔。
與elastalert
相比較,就告警功能而言的話,若是要求不高,推薦使用sentinl
,由於安裝容易而且配置簡單;但若是有複雜的告警場景或獨立的告警方式,那推薦選擇elastalert
。
整理一個對比表格,想必這樣看起來更直觀:
比較 | Sentinl | ElastAlert |
---|---|---|
安裝 | 簡單 | 通常複雜 |
配置 | 簡單 | 通常複雜 |
UI | 簡單美觀 | 不友好 |
告警規則數量 | 1個 | 11個 |
告警方式數量 | 6個 | 11個 |
告警方式隔離 | 不獨立 | 獨立 |
開發語言 | javascript | python |
後端配置透明度 | 不透明 | 透明 |
成熟度 | 700+ star | 5000+ start |
開發者數量 | 28 | 160 |
commit數 | 1500+ | 1800+ |
開發週期 | 2016/08 | 2015/11 |
根據上述表格,咱們能夠看出各有各的優點,sentinl
更加偏向於集成進kibana
的一種頁面展現插件,而elastalert
則是更偏向與後端告警功能的打磨。單從告警功能來看,elastalert
看起來更強大一些,可是sentinl
也有它的優點,UI
很是地棒,其次還支持report
功能,雖然如今還存在不少問題,但相信以後確定愈來愈好,並且目前經過開發者數量和代碼提交量能夠看出有後來居上的感受。就筆者而言,喜好sentinl
的UI
,喜好elastalert
的告警rule
。
sentinl
做爲一個開源組件,提供了X-Pack
兩款收費組件:Alert
和Reporting
的替代功能,着實不錯,告警功能配置簡單、頁面美觀、操做友好;可是Report
功能就顯得問題較多,而且生成的報表也有不少瑕疵。但願以後能夠不斷優化和強大吧!