標籤:elasticsearch nagios
在Nagios社區中上找了下相關用於監控elasticsearch索引的指令碼,再經過修改下,可以在平時用於傳入elasticsearch的監聽ip用於在Nagios中使用監控elasticsearch健康狀態的指令碼
#!/bin/bash#check_elasticsearch_health.sh#Memo for Nagios outputsSTATE_OK=0STATE_WARNING=1STATE_CRITICAL=2STATE_UNKNOWN=3#Position parameter judgmentif [ $# -lt 1 ];then echo "Please enter host address" echo "ex> $0 HOST_ADDRESS" exit $STATE_UNKNOWNfiif [ $# -gt 1 ]; then echo "The input host address are too much" echo "ex> $0 localhost" exit $STATE_UNKNOWNfitype curl >/dev/null 2>&1 || { echo >&2 "This plugin require curl but it‘s not installed."; exit $STATE_UNKNOWN; }#檢查是否有安裝curlHOST=$1STATUS=$(curl -s $HOST:9200/_cluster/health?pretty | grep status | awk ‘{print $3}‘ | cut -d\" -f2)#單節點的健康檢測,平時可以根據需要監控內容來修改api擷取相應的值if [[ $STATUS && "$STATUS" != "green" ]]; thenecho "CRITICAL - Status is $STATUS"exit $STATE_CRITICALfiif [[ "$STATUS" == "green" ]]; thenecho "OK - Status is $STATUS"exit $STATE_OKfiecho "UNKNOW - No data were returned by elastisearch on host $HOST"exit $STATE_UNKNOWN
本文出自 “Jim的技術隨筆” 部落格,謝絕轉載!
用於Nagios中監控elasticsearch健康狀態指令碼