2012-04-23 29 views
10

我想監測使用nagios的elasticsearch。 Basiclly,我想知道elasticsearch是否啓動。如何使用nagios監測elasticsearch

我想我可以使用elasticsearch集羣健康API(see here

,並使用「狀態」那我回去(綠色,黃色或紅色),但我還是不知道如何使用的nagios對於這個問題(nagios在一臺服務器上,而elasticsearc在另一臺服務器上)。

是否有另一種方法來做到這一點?

編輯: 我剛剛發現 - check_http_json。我想我會嘗試一下。

回答

12

過了一段時間 - 我設法使用nrpe監測elasticsearch。 我想使用elasticsearch集羣健康API - 但由於安全問題,我無法在另一臺機器上使用它... 因此,在監控服務器中,我創建了一項新服務 - check_command爲check_command check_nrpe!check_elastic。現在在遠程服務器,其中elasticsearch是,我editted與nrpe.cfg文件執行以下操作:

command[check_elastic]=/usr/local/nagios/libexec/check_http -H localhost -u /_cluster/health -p 9200 -w 2 -c 3 -s green 

這是允許的,因爲該命令從遠程服務器上運行 - 因此沒有安全問題這裏...

它的工作原理! 我仍然會嘗試在我的qeustion中發佈的check_http_json命令 - 但現在,我的解決方案已經足夠好了。

+0

感謝您計算出此!除了跨系統工作以解決安全問題之外,在具有不同目錄結構的計算機上監控羣集非常適用。 check_http插件位於我們各種服務器上的3個不同目錄中。這種方法讓我運行檢查,但讓本地機器管理插件路徑。再次感謝! – 2012-09-14 16:39:19

6

在玩過這篇文章中的建議之後,我寫了一個簡單的check_elasticsearch腳本。它返回對應於羣集運行狀況響應「​​狀態」參數的狀態作爲OKWARNING,和CRITICAL(分別爲「綠色」,「黃色」和「紅色」)。

它還從健康頁面抓取所有其他參數,並將它們以標準Nagios格式轉儲出來。

享受!

+1

效果很好,並且沒有愚蠢的依賴關係。謝謝! – 2016-09-19 00:26:29

1

您可以使用這個酷酷的Python腳本來監控您的Elasticsearch集羣。該腳本檢查您的IP:端口是否爲Elasticsearch狀態。用於監視Elasticsearch的這一個或多個Python腳本可以在here找到。

#!/usr/bin/python 
from nagioscheck import NagiosCheck, UsageError 
from nagioscheck import PerformanceMetric, Status 
import urllib2 
import optparse 

try: 
    import json 
except ImportError: 
    import simplejson as json 


class ESClusterHealthCheck(NagiosCheck): 

    def __init__(self): 

     NagiosCheck.__init__(self) 

     self.add_option('H', 'host', 'host', 'The cluster to check') 
     self.add_option('P', 'port', 'port', 'The ES port - defaults to 9200') 

    def check(self, opts, args): 
     host = opts.host 
     port = int(opts.port or '9200') 

     try: 
      response = urllib2.urlopen(r'http://%s:%d/_cluster/health' 
             % (host, port)) 
     except urllib2.HTTPError, e: 
      raise Status('unknown', ("API failure", None, 
         "API failure:\n\n%s" % str(e))) 
     except urllib2.URLError, e: 
      raise Status('critical', (e.reason)) 

     response_body = response.read() 

     try: 
      es_cluster_health = json.loads(response_body) 
     except ValueError: 
      raise Status('unknown', ("API returned nonsense",)) 

     cluster_status = es_cluster_health['status'].lower() 

     if cluster_status == 'red': 
      raise Status("CRITICAL", "Cluster status is currently reporting as " 
         "Red") 
     elif cluster_status == 'yellow': 
      raise Status("WARNING", "Cluster status is currently reporting as " 
         "Yellow") 
     else: 
      raise Status("OK", 
         "Cluster status is currently reporting as Green") 

if __name__ == "__main__": 
    ESClusterHealthCheck().run()