My Question
I need to look at all lines within a log file (see input below) to work out how to organize the hours (
$3
) 00 - 23 (not always there all the time) without using a variable that increments and only print a single line for each hour.
Input file Sample
...
INFO 2016-06-15 00:00:30.065 TelegramDispatcher - --> Complete telegram dispatching took 8.9ms (canHandle(56:TelegramHandlerECHLane) took 0.0ms, handleTelegram took 2.2ms, commit took 5.6ms, doACK took 0.6ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO 2016-06-15 00:00:30.072 TelegramDispatcher - --> Complete telegram dispatching took 7.2ms (canHandle(56:TelegramHandlerECHLane) took 0.0ms, handleTelegram took 2.0ms, commit took 4.1ms, doACK took 0.7ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO 2016-06-15 00:00:30.114 TelegramDispatcher - --> Complete telegram dispatching took 12.4ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 4.3ms, commit took 6.6ms, doACK took 1.0ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.2ms)
INFO 2016-06-15 00:00:30.165 TelegramDispatcher - --> Complete telegram dispatching took 19.6ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 3.6ms, commit took 14.3ms, doACK took 0.9ms, doNAK took -0.0ms performAfterCommit took 0.5ms, failedCanHandle took 0.1ms)
INFO 2016-06-15 00:00:30.271 TelegramDispatcher - --> Complete telegram dispatching took 10.0ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 3.7ms, commit took 4.8ms, doACK took 0.9ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO 2016-06-15 00:00:30.300 TelegramDispatcher - --> Complete telegram dispatching took 18.7ms (canHandle(61:TelegramHandlerPackingOrderBufferHanging) took 0.0ms, handleTelegram took 7.3ms, commit took 10.2ms, doACK took 0.8ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
...
Current Code
#!/usr/bin/gawk -f
BEGIN {
print "-------------------------------------------------------"
print "----------Telegram Processing Time by Hour-------------"
print "-------------------------------------------------------"
} #End of BEGIN
{ #Start of MID
key = substr($12,match($12,":")+1,match($12,")")-15); #Message Extracted 10 Total
key2 = substr($3,1,2) #Hour
MSG_TYPE[key]++ #Distinct Message
MSG_HR[key,key2] += $11 #Tots up Time Took for each MSG by Hour
} #End of MID
END {
for (msg in MSG_TYPE) {
print msg
print "-----------------------------------"
for(msghr in MSG_HR) {
split(msghr,indices,SUBSEP);
hr = indices[2];
print msg #Added this to try and Debug
print hr
print "AVG by Hour: "MSG_HR[msghr]"ms"
}
print "\n"
}
} #End of END
To explain this code a little, the MSG_HR
array is curently adding up $11
which for reference is the ***ms
just after the first took
, key
is returning the msg
and key2
is returning the hour.
Current Output Sample
...
TelegramHandlerECHLane
-----------------------------------
TelegramHandlerECHLane
14
AVG by Hour: 80950.6ms
TelegramHandlerECHLane
08
AVG by Hour: 25.2ms
TelegramHandlerECHLane
01
AVG by Hour: 75053.9ms
...
TelegramHandlerLaneStatusHangingMPA
-----------------------------------
TelegramHandlerLaneStatusHangingMPA
14
AVG by Hour: 80950.6ms
TelegramHandlerLaneStatusHangingMPA
08
AVG by Hour: 25.2ms
TelegramHandlerLaneStatusHangingMPA
01
AVG by Hour: 75053.9ms
...
Desired Output Sample
...
TelegramHandlerECHLane
-----------------------------------
00
AVG by Hour:
01
AVG by Hour:
02
AVG by Hour:
03
AVG by Hour:
04
AVG by Hour:
05
AVG by Hour:
06
AVG by Hour:
...
There are 10 different MSG_TYPES
that I am trying to set out in the format above. I am unable to upgrade to awk
V 4.1.0 as I know this will make thing easier. (True Multidimentional Arrays etc..)
Any and all Help will be greatly appreciated.