-
-
Save ekristen/e4ea09e0003df03a6cd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# esdiagdump | |
# | |
# Usage: esdiagdump [-h <hostname/IP>:<port>] [-o <output filename>] | |
# hostname defaults to localhost | |
# output file defaults to current directory/esdiagdump.out.<timestamp> | |
# | |
# TODO: | |
# - Support for collecting marvel indices for export | |
# - more system data | |
# - Collect JVM stats | |
# - Add facility to automatically post to ZD or S3 | |
timestamp=$(date +"%Y%m%d-%H%M%S") | |
# set defaults | |
outputdir="esdiagdump.$timestamp.$(hostname)" | |
eshost="localhost:9200" | |
# pick up command line options | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
-h) eshost=$2;; | |
-o) outputdir=$2;; | |
-nc) nocompression=true;; | |
esac | |
shift | |
done | |
# check dump file | |
mkdir $outputdir/ | |
if [ ! -e $outputdir ] | |
then | |
echo "Cannot write output file." | |
exit | |
fi | |
# Cribbed from ES startup script. Only works if we place this script in the elasticsearch/bin | |
CDPATH="" | |
SCRIPT="$0" | |
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | |
while [ -h "$SCRIPT" ] ; do | |
ls=`ls -ld "$SCRIPT"` | |
# Drop everything prior to -> | |
link=`expr "$ls" : '.*-> \(.*\)$'` | |
if expr "$link" : '/.*' > /dev/null; then | |
SCRIPT="$link" | |
else | |
SCRIPT=`dirname "$SCRIPT"`/"$link" | |
fi | |
done | |
# determine elasticsearch home | |
ES_HOME=`dirname "$SCRIPT"`/.. | |
# make ELASTICSEARCH_HOME absolute | |
eslogs=$ES_HOME/logs | |
if [ ! -e $eslogs ] | |
then | |
eslogs=/var/log/elasticsearch/ | |
echo "Logs not found in ESHOME/logs. Trying /var/log/elasticsearch." | |
fi | |
if [ ! -e $eslogs ] | |
then | |
echo "Logs not found. Skipping..." | |
else | |
mkdir $outputdir/logs | |
cp $eslogs/*.log $outputdir/logs/ | |
fi | |
echo "Getting _mapping" | |
curl -XGET $eshost/_mapping?pretty >> $outputdir/mapping.json 2> /dev/null | |
echo "Getting _settings" | |
curl -XGET $eshost/_settings?pretty >> $outputdir/settings.json 2> /dev/null | |
echo "Getting _cluster/settings" | |
curl -XGET $eshost/_cluster/settings?pretty >> $outputdir/cluster_settings.json 2> /dev/null | |
echo "Getting _cluster/state" | |
curl -XGET $eshost/_cluster/state?pretty >> $outputdir/cluster_state.json 2> /dev/null | |
echo "Getting _cluster/stats" | |
curl -XGET "$eshost/_cluster/stats?pretty&human" >> $outputdir/cluster_stats.json 2> /dev/null | |
echo "Getting _nodes/stats" | |
curl -XGET "$eshost/_nodes/stats?pretty&human" >> $outputdir/nodes_stats.json 2> /dev/null | |
echo "Getting _cat/recovery" | |
curl -XGET $eshost/_cat/recovery?v >> $outputdir/cat_recovery.json 2> /dev/null | |
echo "Getting _nodes/hot_threads" | |
curl -XGET $eshost/_nodes/hot_threads?threads=10 >> $outputdir/nodes_hot_threads.out 2> /dev/null | |
echo "Getting field data" | |
curl -XGET "$eshost/_nodes/stats/_all?fields=*&pretty&human" >> $outputdir/nodes_fields.json 2> /dev/null | |
curl -XGET "$eshose/_stats/_all?fields=*&pretty&human" >> $outputdir/stats_fields.json 2> /dev/null | |
echo "Running netstat" | |
if [ "$(uname)" == "Darwin" ]; then | |
netstat -an >> $outputdir/netstat.out | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
netstat -anp >> $outputdir/netstat.out | |
fi | |
echo "Running top" | |
if [ "$(uname)" == "Darwin" ]; then | |
top -l 1 >> $outputdir/top.out | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
top -b -n1 >> $outputdir/top.out | |
fi | |
echo "Running top with threads (Linux only)" | |
if [ "$(uname)" == "Darwin" ]; then | |
echo "This is a Mac. Not running top -H." | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
top -b -n1 -H >> $outputdir/top_threads.out | |
fi | |
echo "Output complete. Creating tarball." | |
tarfile=$outputdir.tar | |
tar cf $tarfile $outputdir/* | |
if [ ! $nocompression ]; then | |
gzip $tarfile | |
fi | |
rm -rf $outputdir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment