[Demo Code] Watch the witness node latency in docker

in #witness15 days ago
#!/bin/bash

container_name=$1
delay_config=$2

if [[ "${container_name}" = "" ]]; then
        container_name=witness
fi

if [[ "${delay_config}" = "" ]]; then
        delay_config=300
fi

msg_queue=()
count=0

alert() {
    msg_queue+=("$1")
    ((count++))
    if ((count % 5 == 0)); then
        echo "${msg_queue[@]}"
        msg_queue=()
    fi
}

while read line; do
        username=`echo $line | awk '{print $12}'`
        delay=`echo $line | awk '{print $17}'`
        # If the delay is higher than delay_config, it will report.
        if (( delay > ${delay_config} )); then
                alert "$username, $delay"
        fi
done < <(docker logs -f --tail 1 ${container_name})