Skip to content

Instantly share code, notes, and snippets.

@figroc
Last active March 27, 2018 12:06
Show Gist options
  • Save figroc/7e6af04a8d220d4edfd7b90791f12462 to your computer and use it in GitHub Desktop.
Save figroc/7e6af04a8d220d4edfd7b90791f12462 to your computer and use it in GitHub Desktop.
show .filebeat sync status
#!/bin/bash -e
vol="${1}"
if [[ -z "${vol}" ]]; then
echo "usage: sudo ${0} <volume_name>" 1>&2
exit 1
fi
daemon="/etc/docker/daemon.json"
if [[ -f ${daemon} ]]; then
root=$(grep -Eo '"(data-root|graph)"[[:blank:]]*:[[:blank:]]*"[^"]+"' ${daemon})
if [[ -n "${root}" ]]; then
root="${root##*:}"
root="${root#*\"}"
root="${root%\"*}"
fi
fi
if [[ -z "${root}" ]]; then
root="/var/lib/docker"
fi
root="${root}/volumes/${vol}/_data"
if [[ ! -d ${root} ]]; then
echo "${vol} not found" 1>&2
exit 1
fi
beat="${root}/.filebeat"
if [[ ! -f ${beat} ]]; then
echo "${beat} not found" 1>&2
exit 1
fi
files=( $(grep -Eo '"source":"[^"]+",' ${beat}) )
for i in ${!files[@]}; do
files[${i}]=${files[${i}]:9:-2}
files[${i}]=${files[${i}]##*/}
done
sizes=( $(grep -Eo '"offset":[0-9]+,' ${beat}) )
for i in ${!sizes[@]}; do
sizes[${i}]=${sizes[${i}]:9:-1}
done
let expire=$(date +%s)-86400 # 1 day
for i in ${!files[@]}; do
if [[ -f ${root}/${files[${i}]} ]]; then
if (("$(stat -c %s ${root}/${files[${i}]})" == "${sizes[${i}]}")); then
echo -n "syn "
else
echo -n "lag "
fi
if (("$(date -r ${root}/${files[${i}]} +%s)" <= "${expire}")); then
echo -n "due "
else
echo -n "kpt "
fi
else
echo -n "n/a n/a "
fi
echo "${files[${i}]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment