2012-04-23 19 views
10

nagiosを使用してelasticsearchを監視したいと思います。 basiclly、私はelasticsearchがアップしているかどうかを知りたい。nagiosを使用してelasticsearchを監視する方法

は私がelasticsearchクラスタ健康API(see here

を使用して、私は(黄または赤、緑、)取り戻すのステータス 'を使用することができると思うが、私はまだのnagiosを使用する方法がわかりません(nagiosはあるサーバーにあり、elasticsearcは別のサーバーにあります)。

これを行う別の方法はありますか?

編集: 私はちょうどその - check_http_jsonを見つけました。私はそれを試してみると思う。

答えて

12

しばらくしてから、nrpeを使ってelasticsearchを監視することができました。 elasticsearch Cluster Health APIを使用したかったのですが、セキュリティ上の問題のために別のマシンから使用できませんでした... 監視サーバーで、check_commandがcheck_command check_nrpe!check_elasticの新しいサービスを作成しました。そして今elasticsearchがあるリモートサーバで、私はとnrpe.cfgファイルをedittedました次:このコマンドは、リモートサーバから実行されていないため、許可されている

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つの異なるディレクトリにあります。このメソッドを使用すると、チェックを実行できますが、ローカルマシンにプラグインパスを管理させることができます。再度、感謝します! –

6

私はこのポストの提案を使い遊んだ後、簡単なcheck_elasticsearchスクリプトを書いた。クラスタの正常性応答(「緑」、「黄」、「赤」)の「status」パラメータに対応するOKWARNING、およびCRITICALというステータスを返します。

他のすべてのパラメータをヘルスページから取得し、標準のNagios形式でダンプします。

お楽しみください!

+1

はうまく動作し、愚かな依存関係はありません。ありがとう! –

2

恥知らずなプラグ:https://github.com/jersten/check-es

クラスタ健康、データ指標、および個々のノードのヒープの使用状況を監視するためにZenOSS/Nagiosでそれを使用することができます。

+0

これでunassigned_shardsをチェックすることはできますか? – flickerfly

1

この素晴らしいPythonスクリプトを使用して、Elasticsearchクラスタを監視できます。このスクリプトはIP:portでElasticsearchのステータスを確認します。 Elasticsearchを監視するためのこの1つ以上の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() 
関連する問題