Created
March 20, 2015 06:27
-
-
Save ChinaXing/f0a41d18140636a38a9a to your computer and use it in GitHub Desktop.
calculator the RT from netty log, use bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/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