ES告警詳解之Sentinl

原文地址: https://www.tony-yin.site/201...

sentinl

上一篇文章詳細講解了ElastAlert這款告警組件,今天咱們聊聊另外一個ES開源告警組件Sentinljavascript

概述

sentinl是基於javascript開發的kibana插件,擁有告警和報表兩大功能,分別做爲X-PackAlertReporting的替代品,即插即用,它將前端UIwebserver和告警邏輯代碼都集成在一個項目中,這一點要比上篇文章提到同爲kibana插件的elastalert-kibana-plugin要強大很多,而且能夠說sentinlUI不管是美觀程度仍是操做友好程度都徹底秒殺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頁面上看到sentinlnode

Alert配置

告警配置環節其實也很簡單,由於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服務才能夠生效。這裏須要注意的是hostuserpassword三個選項,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

Report配置

sentinl除了提供告警功能,還提供了一個相似X-Pack Reporting的報表功能。chrome

一樣這個功能須要開啓和配置,不得不說這個功能和相關文檔仍是存在着很多的問題,好比儘管文檔聲稱默認enginehorseman,可是如今默認的是puppeteer

問題1

官方文檔提供的配置例子是這樣的:

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這個選項已經被棄用,這個路徑會被自動解析,一臉懵逼,文檔中絲毫沒說起。。。

問題2

當時筆者也很奇怪,如何自動解析?如何知曉chromium的路徑呢?這個下面再講,而後就先註釋掉該選項配置:

sentinl:
  settings:
    active: true
      engine: 'puppeteer'
      # executable_path: '/usr/bin/chromium-browser'

頁面換了個報錯:

ActionError: report action: execute: run 'puppeteer' report: puppeteer work

以下圖所示:

<center>error1</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"}

以下圖所示

puppeteer permission

這就是爲何能夠自動解析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

問題3

更改以後這個報錯沒有了,可是又有了新的報錯(真是醉了):

Failed to load url

以下圖所示

load url error

而後繼續谷歌大法,在 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,而後將該dashbordurl更新至配置中的url

問題4

此次沒報錯了,report也發送到了指定郵箱,可是report是空的,這是由於新建立的dashbord並無導入任何可視化圖表,因此將url切換成了已經存在可視化圖表的dashbordurl,這下能夠發現發送的report是存在圖表的。

結合以前monitoring的瞭解,忽然想到這個url可能不是dashbord直接顯示的url,而應該是經過share功能提供的link

問題5

上面engine選擇puppeteer,筆者又嘗試將engine切換成horseman

sentinl:
  settings:
    report:
      active: true
      engine: 'horseman'

換了engine,依然報錯不停:

ActionError: report action: execute: run 'horseman' report: spawn EACCES

以下圖所示

eacces error

其實這個問題,上文提到的 issue 535 中也給出了答案,horseman engine依賴的是phantomjs庫,puppeteer依賴的是chrome庫,問題2chrome缺乏可執行權限,而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,做者也表示了這個權限問題以後會經過腳本等方式自動處理,而後表示這個文檔沒有同步更新,能夠看最新同步文檔

Sentinl & ElastAlert

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功能,雖然如今還存在不少問題,但相信以後確定愈來愈好,並且目前經過開發者數量和代碼提交量能夠看出有後來居上的感受。就筆者而言,喜好sentinlUI,喜好elastalert的告警rule

總結

sentinl做爲一個開源組件,提供了X-Pack兩款收費組件:AlertReporting的替代功能,着實不錯,告警功能配置簡單、頁面美觀、操做友好;可是Report功能就顯得問題較多,而且生成的報表也有不少瑕疵。但願以後能夠不斷優化和強大吧!

相關文章
相關標籤/搜索