Skip to content

Commit

Permalink
Merge pull request #7 from cjs226/cjs226
Browse files Browse the repository at this point in the history
Add ability to output to Graphite
  • Loading branch information
orthecreedence committed Nov 1, 2014
2 parents 6668bd5 + 77348b2 commit eb6c41f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ This will output the standard Nagios format:

`OK` / `WARNING` / `CRITICAL` correspond to the status being "green", "yellow", or "red" respectively.

If you have a Graphite server you can send data to it via:

./check_elasticsearch -H es1.mysite.com -P 9200 -c graphite.foo.com -C 2003

This will output data to the following metric prefix:

system.$cluster_name.cluster.app.elasticsearch.cluster

Script is a modified version of check\_phpfpm by [MAB](https://github.com/mabitt/mab-nagios-plugins).

Enjoy.
54 changes: 39 additions & 15 deletions check_elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
epoch=`date +%s`
hostname="localhost"
port=9200
status_page="/_cluster/health"
Expand Down Expand Up @@ -75,6 +76,14 @@ while test -n "$1"; do
output_dir=$2
shift
;;
--carbon-server|-c)
carbon_server=$2
shift
;;
--carbon-port|-C)
carbon_port=$2
shift
;;
*)
echo "Unknown argument: $1"
print_help
Expand Down Expand Up @@ -104,6 +113,21 @@ get_vals() {
initializing_shards=`grep initializing_shards ${filename} | awk '{print $3}' | sed 's|[",]||g'`
unassigned_shards=`grep unassigned_shards ${filename} | awk '{print $3}' | sed 's|[",]||g'`
rm -f ${filename}

# Determine the Nagios Status and Exit Code
if [ "$status" = "red" ]; then
NAGSTATUS="CRITICAL"
EXST=$ST_CR
elif [ "$status" = "yellow" ]; then
NAGSTATUS="WARNING"
EXST=$ST_WR
elif [ "$status" = "green" ]; then
NAGSTATUS="OK"
EXST=$ST_OK
else
NAGSTATUS="UNKNOWN"
EXST=$ST_UK
fi
}

do_output() {
Expand All @@ -124,6 +148,19 @@ do_perfdata() {
perfdata="'active_primary'=$active_primary_shards 'active'=$active_shards 'relocating'=$relocating_shards 'init'=$initializing_shards 'unass'=$unassigned_shards"
}

do_graphite() {
if [ "$carbon_server" != "" -a "$carbon_port" != "" ]; then
echo "system.$name.cluster.app.elasticsearch.cluster.status $EXST $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.nodes.ttl $number_nodes $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.nodes.data $number_data_nodes $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.shards.active $active_shards $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.shards.active_primary $active_primary_shards $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.shards.initializing $initializing_shards $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.shards.relocating $relocating_shards $epoch" | nc -w 2 $carbon_server $carbon_port
echo "system.$name.cluster.app.elasticsearch.cluster.shards.unassigned $unassigned_shards $epoch" | nc -w 2 $carbon_server $carbon_port
fi
}

# Here we go!
which wget >/dev/null 2>&1
if [ "$?" != "0" ]; then
Expand All @@ -142,24 +179,11 @@ else
else
do_output
do_perfdata
do_graphite
fi
fi

COMPARE=$listql

if [ "$status" = "red" ]; then
echo -n "CRITICAL"
EXST=$ST_CR
elif [ "$status" = "yellow" ]; then
echo -n "WARNING"
EXST=$ST_WR
elif [ "$status" = "green" ]; then
echo -n "OK"
EXST=$ST_OK
else
echo -n "UNKNOWN"
EXST=$ST_UK
fi

echo " - ${output} | ${perfdata}"
echo "${NAGSTATUS} - ${output} | ${perfdata}"
exit $EXST

0 comments on commit eb6c41f

Please sign in to comment.