Skip to content

Instantly share code, notes, and snippets.

@RickyCook
Last active December 31, 2015 04:39
Show Gist options
  • Save RickyCook/7936070 to your computer and use it in GitHub Desktop.
Save RickyCook/7936070 to your computer and use it in GitHub Desktop.
Record free RAM and number of docs in an index for ElasticSearch over time
#!/bin/bash
########
ELASTIC_URL="<host>:9200/<index>/"
SLEEP=5
########
# AHAHHAHAHAHAHHAHAHH awwwwwful
PYTHON_CODE='
import fileinput,json
whole = ""
for line in fileinput.input():
whole += line
j = json.loads(whole)
print j["_all"]["total"]["docs"]["count"]
'
while true; do
cat /proc/meminfo | grep MemFree | grep -oE '[0-9]+' >> mem.txt
curl -s "$ELASTIC_URL/_stats" | python -c "$PYTHON_CODE" >> es.txt
echo "MEM: $(tail -n 1 mem.txt)"
echo "DOC: $(tail -n 1 es.txt)"
sleep $SLEEP
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment