[Demo Code] Watch the witness node latency in docker

in witness •  15 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})
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!