监控Elasticsearch的插件【check_es_system】
监控Elasticsearch的插件推荐 强大的shell脚本
#!/bin/bash
################################################################################
# Script: check_es_system.sh #
# Author: Claudio Kuenzler www.claudiokuenzler.com #
# Purpose: Monitor ElasticSearch Store (Disk) Usage #
# Licence: GPLv2 #
# Licence : GNU General Public Licence (GPL) http://www.gnu.org/ #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, see <https://www.gnu.org/licenses/>. #
# #
# Copyright ,, Claudio Kuenzler #
# Copyright Tomas Barton #
# #
# History: #
# : Started programming plugin #
# : Continued programming. Working now as it should =) #
# : Added memory usage check, check types option (-t) #
# : Renamed plugin from check_es_store to check_es_system #
# : Change internal referenced variable name for available size #
# : Output now contains both used and available sizes #
# : Add missing -t in usage output #
# : Fix if statement for authentication (@deric) #
# : Fix authentication when wrong credentials were used #
# : Configure max_time for Elastic to respond (@deric) #
# : Fix alternative subject name in ssl (issue ), direct to auth #
# : Added status check type #
# : Check for mandatory parameter checktype, adjust help #
# : Catch connection refused error #
################################################################################
#Variables and defaults
STATE_OK= # define the exit code if status is OK
STATE_WARNING= # define the exit code if status is Warning
STATE_CRITICAL= # define the exit code if status is Critical
STATE_UNKNOWN= # define the exit code if status is Unknown
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin # Set path
version=1.3
port=
httpscheme=http
unit=G
warning=
critical=
max_time=
################################################################################
#Functions
help () {
echo -e "$0 $version (c) 2016-$(date +%Y) Claudio Kuenzler and contributers (published below GPL licence) Usage: ./check_es_system.sh -H ESNode [-P port] [-S] [-u user] [-p pass] -t checktype [-d int] [-o unit] [-w int] [-c int] [-m int] Options: * -H Hostname or ip address of ElasticSearch Node
-P Port (defaults to )
-S Use https
-u Username if authentication is required
-p Password if authentication is required
* -t Type of check (disk|mem|status)
+ -d Available size of disk or memory (ex. )
-o Disk space unit (K|M|G) (defaults to G)
-w Warning threshold in percent (default: )
-c Critical threshold in percent (default: )
-m Maximum time in seconds to wait for response (default: )
-h Help! *mandatory options
+mandatory options for types disk,mem Requirements: curl, jshon, expr"
exit $STATE_UNKNOWN;
} authlogic () {
if [[ -z $user ]] && [[ -z $pass ]]; then echo "ES SYSTEM UNKNOWN - Authentication required but missing username and password"; exit $STATE_UNKNOWN
elif [[ -n $user ]] && [[ -z $pass ]]; then echo "ES SYSTEM UNKNOWN - Authentication required but missing password"; exit $STATE_UNKNOWN
elif [[ -n $pass ]] && [[ -z $user ]]; then echo "ES SYSTEM UNKNOWN - Missing username"; exit $STATE_UNKNOWN
fi
} unitcalc() {
# ES presents the currently used disk space in Bytes
if [[ -n $unit ]]; then
case $unit in
K) availsize=$(expr $available \* ); outputsize=$(expr ${size} / );;
M) availsize=$(expr $available \* \* ); outputsize=$(expr ${size} / / );;
G) availsize=$(expr $available \* \* \* ); outputsize=$(expr ${size} / / / );;
esac
if [[ -n $warning ]] ; then
warningsize=$(expr $warning \* ${availsize} / )
fi
if [[ -n $critical ]] ; then
criticalsize=$(expr $critical \* ${availsize} / )
fi
usedpercent=$(expr $size \* / $availsize)
else echo "UNKNOWN - Shouldnt exit here. No units given"; exit $STATE_UNKNOWN
fi
} availrequired() {
if [ -z ${available} ]; then echo "UNKNOWN - Missing parameter '-d'"; exit $STATE_UNKNOWN; fi
}
################################################################################
# Check requirements
for cmd in curl jshon expr; do
if ! `which ${cmd} >/dev/null`; then
echo "UNKNOWN: ${cmd} does not exist, please check if command exists and PATH is correct"
exit ${STATE_UNKNOWN}
fi
done
################################################################################
# Check for people who need help - aren't we all nice ;-)
if [ "${1}" = "--help" -o "${#}" = "" ]; then help; exit $STATE_UNKNOWN; fi
################################################################################
# Get user-given variables
while getopts "H:P:Su:p:d:o:w:c:t:m:" Input;
do
case ${Input} in
H) host=${OPTARG};;
P) port=${OPTARG};;
S) httpscheme=https;;
u) user=${OPTARG};;
p) pass=${OPTARG};;
d) available=${OPTARG};;
o) unit=${OPTARG};;
w) warning=${OPTARG};;
c) critical=${OPTARG};;
t) checktype=${OPTARG};;
m) max_time=${OPTARG};;
*) help;;
esac
done # Check for mandatory opts
if [ -z ${host} ]; then help; exit $STATE_UNKNOWN; fi
if [ -z ${checktype} ]; then help; exit $STATE_UNKNOWN; fi
################################################################################
# Retrieve information from Elasticsearch
esurl="${httpscheme}://${host}:${port}/_cluster/stats"
eshealthurl="${httpscheme}://${host}:${port}/_cluster/health"
if [[ -z $user ]]; then
# Without authentication
esstatus=$(curl -k -s --max-time ${max_time} $esurl)
if [[ $? -eq ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
exit $STATE_CRITICAL
elif [[ $? -eq ]]; then
echo "ES SYSTEM CRITICAL - server did not respond within ${max_time} seconds"
exit $STATE_CRITICAL
fi
# Additionally get cluster health infos
if [ $checktype = status ]; then
eshealth=$(curl -k -s --max-time ${max_time} $eshealthurl)
fi
fi if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
# Authentication required
authlogic
esstatus=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} $esurl)
if [[ $? -eq ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
exit $STATE_CRITICAL
elif [[ $? -eq ]]; then
echo "ES SYSTEM CRITICAL - server did not respond within ${max_time} seconds"
exit $STATE_CRITICAL
elif [[ -n $(echo $esstatus | grep -i "unable to authenticate") ]]; then
echo "ES SYSTEM CRITICAL - Unable to authenticate user $user for REST request"
exit $STATE_CRITICAL
fi
# Additionally get cluster health infos
if [[ $checktype = status ]]; then
eshealth=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} $eshealthurl)
fi
fi # Catch empty reply from server (typically happens when ssl port used with http connection)
if [[ -z $esstatus ]] || [[ $esstatus = '' ]]; then
echo "ES SYSTEM UNKNOWN - Empty reply from server (verify ssl settings)"
exit $STATE_UNKNOWN
fi # Do the checks
case $checktype in
disk) # Check disk usage
availrequired
size=$(echo $esstatus | jshon -e indices -e store -e "size_in_bytes")
unitcalc
if [ -n "${warning}" ] || [ -n "${critical}" ]; then
# Handle tresholds
if [ $size -ge $criticalsize ]; then
echo "ES SYSTEM CRITICAL - Disk usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_disk=${size}B;${warningsize};${criticalsize};;"
exit $STATE_CRITICAL
elif [ $size -ge $warningsize ]; then
echo "ES SYSTEM WARNING - Disk usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_disk=${size}B;${warningsize};${criticalsize};;"
exit $STATE_WARNING
else
echo "ES SYSTEM OK - Disk usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_disk=${size}B;${warningsize};${criticalsize};;"
exit $STATE_OK
fi
else
# No thresholds
echo "ES SYSTEM OK - Disk usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_disk=${size}B;;;;"
exit $STATE_OK
fi
;; mem) # Check memory usage
availrequired
size=$(echo $esstatus | jshon -e nodes -e jvm -e mem -e "heap_used_in_bytes")
unitcalc
if [ -n "${warning}" ] || [ -n "${critical}" ]; then
# Handle tresholds
if [ $size -ge $criticalsize ]; then
echo "ES SYSTEM CRITICAL - Memory usage is at ${usedpercent}% ($outputsize $unit) from $available $unit|es_memory=${size}B;${warningsize};${criticalsize};;"
exit $STATE_CRITICAL
elif [ $size -ge $warningsize ]; then
echo "ES SYSTEM WARNING - Memory usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_memory=${size}B;${warningsize};${criticalsize};;"
exit $STATE_WARNING
else
echo "ES SYSTEM OK - Memory usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_memory=${size}B;${warningsize};${criticalsize};;"
exit $STATE_OK
fi
else
# No thresholds
echo "ES SYSTEM OK - Memory usage is at ${usedpercent}% ($outputsize $unit from $available $unit)|es_memory=${size}B;;;;"
exit $STATE_OK
fi
;; status) # Check Elasticsearch status
status=$(echo $esstatus | jshon -e status -u)
shards=$(echo $esstatus | jshon -e indices -e shards -e total -u)
docs=$(echo $esstatus | jshon -e indices -e docs -e count -u)
nodest=$(echo $esstatus | jshon -e nodes -e count -e total -u)
nodesd=$(echo $esstatus | jshon -e nodes -e count -e data -u)
relocating=$(echo $eshealth | jshon -e relocating_shards -u)
init=$(echo $eshealth | jshon -e initializing_shards -u)
unass=$(echo $eshealth | jshon -e unassigned_shards -u)
if [ "$status" = "green" ]; then
echo "ES SYSTEM OK - Elasticsearch Cluster is green (${nodest} nodes, ${nodesd} data nodes, ${shards} shards, ${docs} docs)|total_nodes=${nodest};;;; data_nodes=${nodesd};;;; total_shards=${shards};;;; relocating_shards=${relocating};;;; initializing_shards=${init};;;; unassigned_shards=${unass};;;; docs=${docs};;;;"
exit $STATE_OK
elif [ "$status" = "yellow" ]; then
echo "ES SYSTEM WARNING - Elasticsearch Cluster is yellow (${nodest} nodes, ${nodesd} data nodes, ${shards} shards, ${relocating} relocating shards, ${init} initializing shards, ${unass} unassigned shards, ${docs} docs)|total_nodes=${nodest};;;; data_nodes=${nodesd};;;; total_shards=${shards};;;; relocating_shards=${relocating};;;; initializing_shards=${init};;;; unassigned_shards=${unass};;;; docs=${docs};;;;"
exit $STATE_WARNING
elif [ "$status" = "red" ]; then
echo "ES SYSTEM CRITICAL - Elasticsearch Cluster is red (${nodest} nodes, ${nodesd} data nodes, ${shards} shards, ${relocating} relocating shards, ${init} initializing shards, ${unass} unassigned shards, ${docs} docs)|total_nodes=${nodest};;;; data_nodes=${nodesd};;;; total_shards=${shards};;;; relocating_shards=${relocating};;;; initializing_shards=${init};;;; unassigned_shards=${unass};;;; docs=${docs};;;;"
exit $STATE_CRITICAL
fi
;; *) help
esac
转
https://www.claudiokuenzler.com/monitoring-plugins/check_es_system.php
监控Elasticsearch的插件【check_es_system】的更多相关文章
- Elasticsearch推荐插件篇(head,sense,marvel)
安装head head插件可以用来快速查看elasticsearch中的数据概况以及非全量的数据,也支持控件化查询和rest请求,但是体验都不是很好. 一般就用它来看各个索引的数据量以及分片的状态. ...
- Elasticsearch报警插件Watch安装以及使用
参考:http://blog.csdn.net/ptmozhu/article/details/52296958 http://corejava2008.iteye.com/blog/2214279 ...
- Elasticsearch之插件介绍及安装
ES站点插件(以网页形式展现) 1.BigDesk Plugin (作者 Lukáš Vlček) 简介:监控es状态的插件,推荐![目前不支持2.x] 2.Elasticsearch Head Pl ...
- Elasticsearch之插件扩展
Elasticsearch之插件介绍及安装 Elasticsearch之head插件安装之后的浏览详解 Elasticsearch之kopf插件安装之后的浏览详解 Elasticsearch-2.4. ...
- Elasticsearch入门教程(一):Elasticsearch及插件安装
原文:Elasticsearch入门教程(一):Elasticsearch及插件安装 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:h ...
- ElasticSearch head 插件安装
head 客户端可以很方便在上面创建索引,类型,文档,还有查询,使用它管理elasticsearch 提高效率. 在安装head 客户端之前必须安装node.js 环境,因为它是用node.js 编写 ...
- Elasticsearch.安装插件(head)
Elasticsearch.安装插件(head) 环境: Linux 7.x jdk1.8 目录结构(跟目录多了两个文件) /resources ### 存放软件源 /u01/ ...
- zabbix通过简单命令监控elasticsearch集群状态
简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...
- zabbix通过简单shell命令监控elasticsearch集群状态
简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...
随机推荐
- Windows上MyEclipse2017 CI7 安装、破解以及配置
一.安装环境与安装包 操作系统:win7 MyEclipse2017 CI7下载地址:链接:https://pan.baidu.com/s/1TWkwntF9i5lOys3Z96mpLQ MyEcli ...
- redis哨兵机制一(转)
概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如 master宕机了,Redis本身(包括它的很多客户端) ...
- Qt之美(一):d指针/p指针详解(二进制兼容,不能改变它们的对象布局)
Translated by mznewfacer 2011.11.16 首先,看了Xizhi Zhu 的这篇Qt之美(一):D指针/私有实现,对于很多批评不美的同路人,暂且不去评论,只是想支持 ...
- OneZero第二周第一次站立会议(2016.3.28)
会议时间:2016年3月28日 会议成员:冉华,张敏,王巍,夏一鸣. 会议目的:分配第二周任务. 会议内容:由于老师要求4月1日进行Alpha发布,我们决定最优先完成消息录入功能.工作具体分配如下 1 ...
- UVALive6442_Coins on a Ring
真正的水题,可惜无法当场机智一下. 这样的,在一个圈圈上给你n个黑点,现在要你移动每一个黑点使得所有的点都是等间距的,每个点中最远需要一定的那个点最小可以是多少? 其实是这样来考虑的,我们可以随便设置 ...
- springmvc+mybatis 实现分页查询
为简化分页功能,设计了一个分页的JSP标签,只需要在页面使用分页标签,就可以完成所有页面的分页功能. 1. 项目结构和数据库设计 (1) 项目结构: (2) 数据库设计 2. PageModel.ja ...
- 点击--》java9 新特性 详解
引言: 点击-->java9 新特性 详解 点击-->java8 新特性 详解 正题: 1.局部变量var 将前端思想var关键字引入java后段,自动检测所属于类型,一种情况除外,不能为 ...
- Mysql向数据库插入数据时,判断是否存在,若不存在就插入数据
表中一定要有主键 : select :id,此处的id位置处必须是主键 insert into table_name(id, name, password) select :id, :name, : ...
- 51nod 1376 最长上升子序列的数量 | DP | vector怒刷存在感!
51nod 1376 最长上升子序列的数量 题解 我们设lis[i]为以位置i结尾的最长上升子序列长度,dp[i]为以位置i结尾的最长上升子序列数量. 显然,dp[i]要从前面的一些位置(设为位置j) ...
- Java之NIO,BIO,AIO
Hollis知识星球的一些学习笔记,有兴趣的朋友可以微信搜一下 什么是NIO 什么是IO? 它是指计算机与外部世界或者一个程序与计算机的其余部分的之间的接口.它对于任何计算机系统都非常关键,因而所有 ...