【问题标题】:How to monitor elasticsearch using nagios如何使用 nagios 监控 elasticsearch
【发布时间】:2012-04-23 08:10:34
【问题描述】:

我想使用 nagios 监控 elasticsearch。 基本上,我想知道 elasticsearch 是否启动。

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

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

还有其他方法吗?

编辑: 我刚刚发现-check_http_json。我想我会试试的。

【问题讨论】:

    标签: monitoring elasticsearch nagios


    【解决方案1】:

    过了一会儿 - 我已经设法使用 nrpe 监控弹性搜索。 我想使用 elasticsearch Cluster Health API - 但由于安全问题,我无法在另一台机器上使用它...... 所以,在监控服务器中,我创建了一个新服务——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 命令 - 但就目前而言,我的解决方案已经足够好了。

    【讨论】:

    • 感谢您解决这个问题!除了跨系统工作以解决安全问题外,它还非常适合监控具有不同目录结构的机器上的集群。 check_http 插件位于我们各种服务器上的 3 个不同目录中。这种方法让我运行检查,但让本地机器管理插件路径。再次感谢!
    【解决方案2】:

    在尝试了这篇文章中的建议后,我编写了一个简单的check_elasticsearch 脚本。它返回的状态为OKWARNINGCRITICAL,对应于集群健康响应中的“status”参数(分别为“green”、“yellow”和“red”)。

    它还从健康页面获取所有其他参数,并以标准 Nagios 格式将它们转储出来。

    享受吧!

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 我可以用这个检查 unassigned_shards 吗?
      【解决方案4】:

      您可以使用这个很酷的 Python 脚本来监控您的 Elasticsearch 集群。此脚本检查您的 IP:port 以了解 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()
      

      【讨论】:

      • 第 23 行应改为,host = opts.host 或 'localhost'
      【解决方案5】:

      这是我在一百万年前写的,它可能仍然有用:https://github.com/radu-gheorghe/check-es

      但这实际上取决于您要监控的内容。以上措施:

      • 如果 Elasticsearch 响应 HTTP
      • 如果摄取率下降到定义的水平以下
      • 如果文档总数下降到定义的水平

      当然还有更多有趣的东西。从查询时间到 JVM 堆使用情况。我们在这里写了一篇关于最重要的博客文章:https://sematext.com/blog/top-10-elasticsearch-metrics-to-watch/

      Elasticsearch 为所有这些提供了 API,因此您可以使用通用的 check_http_json 来获取所需的指标。或者,您可能想要使用Sematext Monitoring for Elasticsearch 之类的东西,它可以立即使用这些指标,然后是forward threshold/anomaly alerts to Nagios。 (披露:我为 Sematext 工作)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多