首页 文章

如何使用nagios监控elasticsearch

提问于
浏览
10

我想使用nagios来监控elasticsearch . 基本上,我想知道弹性搜索是否已经完成 .

我想我可以使用elasticsearch Cluster Health API(see here

并使用我得到的“状态”(绿色,黄色或红色),但我仍然不知道如何使用nagios(nagios在一台服务器上,而elasticsearc在另一台服务器上) .

还有另一种方法吗?

EDIT : 我刚刚发现 - check_http_json . 我想我会试一试 .

4 回答

  • 13

    过了一会儿 - 我在另一台机器上使用它 - 由于安全问题......所以,在监控服务器中我创建了一个新服务 - check_command是 check_command check_nrpe!check_elastic . 现在在弹性搜索所在的远程服务器中,我使用以下内容编辑了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命令 - 但是现在,我的解决方案已经足够了 .

  • 2

    在玩完这篇文章中的建议之后,我写了一个简单的check_elasticsearch脚本 . 它返回状态为 OKWARNINGCRITICAL ,对应于群集运行状况响应中的"status"参数(分别为"green","yellow"和"red") .

    它还从 Health 页面获取所有其他参数,并以标准Nagios格式转储它们 .

    请享用!

  • 6

    无耻插头:https://github.com/jersten/check-es

    您可以将它与ZenOSS / Nagios一起使用,以监视群集运行状况,数据索引和单个节点堆使用情况 .

  • 1

    您可以使用这个很酷的Python脚本来监视您的Elasticsearch集群 . 此脚本检查您的IP:端口以获取Elasticsearch状态 . 可以在here找到这个用于监视Elasticsearch的一个或多个Python脚本 .

    #!/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()
    

相关问题