healthcheck.sh 441 B

12345678910
  1. #!/bin/bash
  2. curl 127.0.0.1:9200 || exit 1
  3. function purge {
  4. curl -X GET http://127.0.0.1:9200/_cat/indices|grep logstash|sort -k3 > /tmp/clearing.stat
  5. (( $(wc -l /tmp/clearing.stat|cut -f1 -d ' ') > 1 )) \
  6. && curl -X DELETE http://127.0.0.1:9200/$(cat /tmp/clearing.stat|awk '(NR == 1)'|cut -d ' ' -f3)
  7. }
  8. if (( $(df -h --output=pcent,target|grep elasticsearch|cut -f2 -d ' '|rev|cut -c 2-|rev) > 80 ));then purge;fi