Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Last active October 16, 2018 14:27
Show Gist options
  • Save EricLondon/9131d4e0ecbd30ffbf36788610e5afd4 to your computer and use it in GitHub Desktop.
Save EricLondon/9131d4e0ecbd30ffbf36788610e5afd4 to your computer and use it in GitHub Desktop.
Export Elasticsearch spark driver log messages
# usage
nvm use .
npm install
chmod +x export-spark-driver-logs.sh
./export-spark-driver-logs.sh $ES_IP:$ES_PORT driver-##############-####
node_modules/
driver-*.json
#!/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'
#!/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'
{
"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