Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created March 20, 2015 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChinaXing/f0a41d18140636a38a9a to your computer and use it in GitHub Desktop.
Save ChinaXing/f0a41d18140636a38a9a to your computer and use it in GitHub Desktop.
calculator the RT from netty log, use bash
!/bin/bash
# ******************************************
#
# A function which calculator the Rt of log
#
# ******************************************
function getEpochMillionSecond
{
ret=$(date +%s%N -d "$1" | cut -b -13)
eval $2=$ret
}
function map_put
{
eval map_$1=$2
}
function map_get
{
eval $2=\$map_$1
}
function map_remove
{
eval $2=\$map_$1
eval unset map_$1
}
while read line
do
dv=$(echo "$line" | awk -F[][] '{print $3}')
c=$(echo "$line" |awk -F[][] '{print $4}' | awk -F[:,] '{print $2}')
d=$(echo "$dv" | cut -b -23)
getEpochMillionSecond "$d" dm
t=$(echo "$dv" | cut -b 25)
if [ $t = "d" ]
then
map_put $c $dm
continue
fi
if [ $t = "e" ]
then
map_remove $c start
if [ -n "$start" ]
then
echo "$c => " $((dm - start))
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment