Last active
October 16, 2018 14:27
-
-
Save EricLondon/9131d4e0ecbd30ffbf36788610e5afd4 to your computer and use it in GitHub Desktop.
Export Elasticsearch spark driver log messages
This file contains hidden or 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
# usage | |
nvm use . | |
npm install | |
chmod +x export-spark-driver-logs.sh | |
./export-spark-driver-logs.sh $ES_IP:$ES_PORT driver-##############-#### |
This file contains hidden or 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
node_modules/ | |
driver-*.json |
This file contains hidden or 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
v8.11.4 |
This file contains hidden or 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
#!/usr/bin/env bash | |
ES_HOST=$1 | |
SPARK_DRIVER=$2 | |
if [ -z "$ES_HOST" ]; then echo "ERROR: ES_HOST required."; exit 1; fi | |
DATE_STRING=$(date '+%Y%m%d%H%M') | |
read -r -d '' JSON_DATA <<EOF | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"message": "error" | |
} | |
} | |
] | |
} | |
}, | |
"sort": [ | |
{ | |
"@timestamp": { | |
"order": "asc" | |
} | |
} | |
] | |
} | |
EOF | |
OUTPUT_FILE="${DATE_STRING}.json" | |
if [ -f $OUTPUT_FILE ]; then | |
echo "Output file already exists, would you like to replace it? (y|n)" | |
read RESPONSE | |
if [ $RESPONSE = "y" ]; then | |
rm $OUTPUT_FILE | |
fi | |
fi | |
./node_modules/elasticdump/bin/elasticdump \ | |
--input="http://${ES_HOST}/filebeat-*" \ | |
--output="${OUTPUT_FILE}" \ | |
--searchBody "$(echo $JSON_DATA)" \ | |
--limit 10000 | |
cat "${OUTPUT_FILE}" | jq '._source.message' |
This file contains hidden or 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
#!/usr/bin/env bash | |
ES_HOST=$1 | |
SPARK_DRIVER=$2 | |
if [ -z "$ES_HOST" ]; then echo "ERROR: ES_HOST required."; exit 1; fi | |
if [ -z "$SPARK_DRIVER" ]; then echo "ERROR: SPARK_DRIVER required."; exit 1; fi | |
read -r -d '' JSON_DATA <<EOF | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"executor": "$SPARK_DRIVER" | |
} | |
} | |
] | |
} | |
}, | |
"sort": [ | |
{ | |
"@timestamp": { | |
"order": "asc" | |
} | |
} | |
] | |
} | |
EOF | |
OUTPUT_FILE="${SPARK_DRIVER}.json" | |
if [ -f $OUTPUT_FILE ]; then | |
echo "Output file already exists, would you like to replace it? (y|n)" | |
read RESPONSE | |
if [ $RESPONSE = "y" ]; then | |
rm $OUTPUT_FILE | |
fi | |
fi | |
./node_modules/elasticdump/bin/elasticdump \ | |
--input="http://${ES_HOST}/filebeat-*" \ | |
--output="${OUTPUT_FILE}" \ | |
--searchBody "$(echo $JSON_DATA)" | |
cat "${OUTPUT_FILE}" | jq '._source.message' |
This file contains hidden or 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
{ | |
"name": "export-spark-driver-logs", | |
"version": "1.0.0", | |
"description": "", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Eric London", | |
"license": "ISC", | |
"dependencies": { | |
"elasticdump": "^3.3.19" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment