Bạn có thể sử dụng tập lệnh Python thú vị này để theo dõi cụm Elasticsearch của mình. Tập lệnh này kiểm tra cổng IP: của bạn cho trạng thái Elasticsearch. Một kịch bản Python này để theo dõi Elasticsearch có thể được tìm thấy 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()
Cảm ơn bạn đã tìm hiểu điều này! Ngoài việc làm việc trên các hệ thống để giải quyết các vấn đề an ninh, nó là rất tốt cho việc giám sát các cụm trên máy với cấu trúc thư mục khác nhau. Plugin check_http nằm trong 3 thư mục khác nhau trên các máy chủ khác nhau của chúng tôi. Phương pháp này cho phép tôi chạy kiểm tra, nhưng hãy để máy cục bộ quản lý đường dẫn plugin. Cảm ơn một lần nữa! –