/
webAccessLogParser.sh
1562 lines (1469 loc) · 69.8 KB
/
webAccessLogParser.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright 2017 ppoudel@sysgenius.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author : Purna Poudel
# Date: 27, 2014
# Version: 1.0
# Parses Apache/IBM HTTP Server access_log.
# Produces Alert.log, summary reports and historical reports.
# Execute as:
# ./webAccessLogParser.sh <options>
#
# Execute below command to see all the available options:
# ./webAccessLogParser.sh
# Include usage
source ./usage.sh
echo "==================================================================" 2>&1 | tee -a $parserExeLog
echo "$0 started at: "$(date +"%Y-%m-%dT%H:%M:%S") 2>&1 | tee -a $parserExeLog
echo "Processing logs with the following input command line:" 2>&1 | tee -a $parserExeLog
echo "$cmdln" 2>&1 | tee -a $parserExeLog;
#--------- Input files ---------------#
fWasCloneIdsMap=./WAS_CloneIDs.csv
fBaseLine=./perfBaseLine.csv
fTh=./thresholdValues.csv
#--------- Report/Output files -------#
rptAlertFile="$rptDir/00_Alert.txt";
rptSummaryFile="$rptDir/02_WebAccessLogSummaryRpt.txt";
rptAccessLogAllFile="$rptDir/WebAccessLogRpt_all.csv";
rptDiscardedRecordsFile="$rptDir/WebAccessLog_discardedRpt.csv";
rptSummaryByDomain="$rptDir/WebAccessLogSummaryByDomainRpt.csv";
rptAvgRespTimeByURIFile="$rptDir/WebAccessLogSummaryByTransactionRpt.csv";
rptPerfByUIDFile="$rptDir/WebAccessLogSummaryByUIDRpt.csv";
rptSummaryBy400PlsUrl="$rptDir/WebAccessLogSummaryByRC400PlusURLRpt.csv";
rptSummaryUserSession="$rptDir/WebAccessLogSummaryByUidSessionRpt.csv";
rptUnknowUA="$rptDir/WebAccessLogSummaryUnknowUARpt.csv";
rptDomainUsgByUidByHr="$rptDir/WebHourlyDomainUsageByUid.csv";
rptDomainUsgBySessByHr="$rptDir/WebHourlyDomainUsageBySess.csv";
rptDomainUsgByDay="$rptDir/WebDlyDomainUsage.csv";
#--------- History Report/Output files -------#
# These are historical reports. Each run will append record in existing report file.
rptPerfHistFile="$pDir/WebPerfHistoryRpt.csv";
if [[ ! -e $rptPerfHistFile && $rptType == "daily" ]]; then
echo "===== Summary table contains short heading title. See below for their description =====" > $rptPerfHistFile;
echo "date : Date" >> $rptPerfHistFile;
echo "uuc : unique user count" >> $rptPerfHistFile;
echo "usc : unique jSession count" >> $rptPerfHistFile;
echo "art : average response time in sec" >> $rptPerfHistFile;
echo "<=1 : response time less than or equal to 1 seconds range in percentage" >> $rptPerfHistFile;
echo "<=5 : response time greater than 1 seconds but less than or equal to 5 seconds range in percentage" >> $rptPerfHistFile;
echo "<=10 : response time greater than 5 seconds but less than or equal to 10 seconds range in percentage " >> $rptPerfHistFile;
echo "<=20 : response time greater than 10 seconds but less than or equal to 20 seconds range in percentage" >> $rptPerfHistFile;
echo ">20 : response time greater than 20 seconds range in percentage" >> $rptPerfHistFile;
echo "xrc : Http request/response count excluding static contents like jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml" >> $rptPerfHistFile;
echo "irc : Http request/response count including static contents static contents" >> $rptPerfHistFile;
echo "=====================================================" >> $rptPerfHistFile;
echo "date|uuc|usc|<=1|<=5|<=10|<=20|>20|art|xrc|irc" >> $rptPerfHistFile;
fi
rptHrlyAvgHistFile="$pDir/WebHourlyAvgRespTimeHistoryRpt.csv";
if [[ ! -e $rptHrlyAvgHistFile && $rptType == "daily" ]]; then
echo "date|H0|H1|H2|H3|H4|H5|H6|H7|H8|H9|H10|H11|H12|H13|H14|H15|H16|H17|H18|H19|H20|H21|H22|H23" > $rptHrlyAvgHistFile;
fi
rptUnqUsrHrlyHistFile="$pDir/WebUniqueUsersHourlyHistoryRpt_all.csv";
if [[ ! -e $rptUnqUsrHrlyHistFile && $rptType == "daily" ]]; then
echo "date|H0|H1|H2|H3|H4|H5|H6|H7|H8|H9|H10|H11|H12|H13|H14|H15|H16|H17|H18|H19|H20|H21|H22|H23" > $rptUnqUsrHrlyHistFile;
fi
rptRqstTypeByHostHistFile="$pDir/WebRequestTypeHistoryRpt.csv";
if [[ ! -e $rptRqstTypeByHostHistFile && $rptType == "daily" ]]; then
echo "date|webserver|GET|POST|PUT|HEAD|OPTIONS|CONNECT|DELETE|TRACE|PROFIND|SEARCH|PROPATCH|SECURE|MKCOL" > $rptRqstTypeByHostHistFile;
fi
rptRspByCodeHistFile="$pDir/WebResponseCodeHistoryRpt.csv";
if [[ ! -e $rptRspByCodeHistFile && $rptType == "daily" ]]; then
echo "date|webserver|100|101|102|103|200|201|202|203|204|205|206|207|208|226|300|301|302|303|304|305|306|307|308|400|401|402|403|404|405|406|407|408|409|410|411|412|413|414|415|416|417|418|419|420|421|422|423|424|426|428|429|431|440|444|449|450|451|495|496|497|498|499|500|501|502|503|504|505|506|507|508|509|510|511|520|521|523|524|525|526" > $rptRspByCodeHistFile;
fi
rptStatByIHSHistFile="$pDir/WebStatsByIHSHistoryRpt.csv";
if [[ ! -e $rptStatByIHSHistFile && $rptType == "daily" ]]; then
echo "===== Summary table contains short heading title. See below for their description =====" > $rptStatByIHSHistFile;
echo "date : Date" >> $rptStatByIHSHistFile;
echo "ws : web server" >> $rptStatByIHSHistFile;
echo "uuc : unique user count" >> $rptStatByIHSHistFile;
echo "usc : unique jSession count" >> $rptStatByIHSHistFile;
echo "art : average response time in sec" >> $rptStatByIHSHistFile;
echo "<=1 : response time less than or equal to 1 seconds range in percentage" >> $rptStatByIHSHistFile;
echo "<=5 : response time greater than 1 seconds but less than or equal to 5 seconds range in percentage" >> $rptStatByIHSHistFile;
echo "<=10 : response time greater than 5 seconds but less than or equal to 10 seconds range in percentage " >> $rptStatByIHSHistFile;
echo "<=20 : response time greater than 10 seconds but less than or equal to 20 seconds range in percentage" >> $rptStatByIHSHistFile;
echo ">20 : response time greater than 20 seconds range in percentage" >> $rptStatByIHSHistFile;
echo "xrpc : Http request/response count in percentage excluding static contents like jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml" >> $rptStatByIHSHistFile;
echo "irpc : Http request/response count including static contents static contents in percentage" >> $rptStatByIHSHistFile;
echo "=====================================================" >> $rptStatByIHSHistFile;
echo "date|ws|uuc|usc|art|<=1|<=5|<=10|<=20|>20|xrpc|irpc" >> $rptStatByIHSHistFile;
fi
rptStatByWASHistFile="$pDir/WebStatsByWASHistoryRpt.csv";
if [[ ! -e $rptStatByWASHistFile && $rptType == "daily" ]]; then
echo "===== Summary table contains short heading title. See below for their description =====" > $rptStatByWASHistFile;
echo "date : Date" >> $rptStatByWASHistFile;
echo "was : WebSphere Applicaton Server" >> $rptStatByWASHistFile;
echo "uuc : unique user count" >> $rptStatByWASHistFile;
echo "usc : unique jSession count" >> $rptStatByWASHistFile;
echo "art : average response time in sec" >> $rptStatByWASHistFile;
echo "<=1 : response time less than or equal to 1 seconds range in percentage" >> $rptStatByWASHistFile;
echo "<=5 : response time greater than 1 seconds but less than or equal to 5 seconds range in percentage" >> $rptStatByWASHistFile;
echo "<=10 : response time greater than 5 seconds but less than or equal to 10 seconds range in percentage " >> $rptStatByWASHistFile;
echo "<=20 : response time greater than 10 seconds but less than or equal to 20 seconds range in percentage" >> $rptStatByWASHistFile;
echo ">20 : response time greater than 20 seconds range in percentage" >> $rptStatByWASHistFile;
echo "xrpc : Http request/response count in percentage excluding static contents like jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml" >> $rptStatByWASHistFile;
echo "irpc : Http request/response count including static contents static contents in percentage" >> $rptStatByWASHistFile;
echo "=====================================================" >> $rptStatByWASHistFile;
echo "date|was|uuc|usc|art|<=1|<=5|<=10|<=20|>20|xrpc|irpc" >> $rptStatByWASHistFile;
fi
# performance (response time) range list.
# <=1 : response time less than or equal to 1 seconds .
# <=5 : response time greater than 1 seconds but less than or equal to 5 seconds.
# <=10 : response time greater than 5 seconds but less than or equal to 10 seconds.
# <=20 : response time greater than 10 seconds but less than or equal to 20 seconds.
# >20 : response time greater than 20 seconds.
rangeLst="<=1|<=5|<=10|<=20|>20";
fTempHttp=`mktemp`
if [[ "$currDate" == "$recDate" ]]
then
logFileName=access_log
else
logFileName=access_log.$rec0MM$rec0DD$recYY
fi
echo "" >> $parserExeLog
echo "========== Start of Web Access Log Alert Section ==========" >> $rptAlertFile
files=$(find $rootcontext -name $logFileName -type f);
if [[ "${files}" == "" ]]; then
echo "No log file found to process. exiting ...";
exit 1;
fi
for z in $files; do
echo "Processing file: $z" >> $parserExeLog;
cat $z | grep -F "[$rec0DD/$recLM/$recYYYY"
done | \
awk -vrecDate=$recDate -vrptDir=$rptDir -vpDir=$pDir -vrptType=$rptType -vfWasCloneIdsMap=$fWasCloneIdsMap -vrangeLst=$rangeLst \
-vfBaseLine=$fBaseLine -vfTh=$fTh -vfTempHttp=$fTempHttp \
-valrtF=$rptAlertFile \
-vrptHrlyAvgHistFile=$rptHrlyAvgHistFile -vrptUnqUsrHrlyHistFile=$rptUnqUsrHrlyHistFile -vrptPerfHistFile=$rptPerfHistFile \
-vrptDomainPerfHistFile=$rptDomainPerfHistFile -vrptDiscardedRecordsFile=$rptDiscardedRecordsFile -vrptRqstTypeByHostHistFile=$rptRqstTypeByHostHistFile \
-vrptRspByCodeHistFile=$rptRspByCodeHistFile -vrptStatByIHSHistFile=$rptStatByIHSHistFile -vrptStatByWASHistFile=$rptStatByWASHistFile \
'BEGIN {
FS="( \"|\" )";
OFS="|";
#access log sort command, sort by response time (field 22)
#accslgsortcmd="sort -t\"|\" -k22nr >> fTempHttp\".access_log_all\"";
whuidsrtcmd="sort -k5 >> "fTempHttp".whereuid";
# discarded record count
discRecCnt=0;
# non-discarded record count
rcdCnt=0;
split(rangeLst,arrRangeName,"|");
# temporary work-around to get MM from short month like "Jan"
mntStr="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
split(mntStr,mntStrArr,",");
for(idx in mntStrArr){
mnt=mntStrArr[idx];
mntArr[mnt]=idx;
}
# Get the threshold values
while((getline thln < fTh) > 0){
# first line is heading. Ignore
split(thln,arrThln,"|");
if(arrThln[3] == "http"){
arrTh[arrThln[1]]=arrThln[2];
#print "reading threshold values: " NR, arrThln[1],arrThln[2];
}
}
close(thln);
close(fTh);
# Get the mapping of cloneIDs and WAS Server
while((getline clndln < fWasCloneIdsMap) > 0){
split(clndln,arrWasCloneIDsLn,"|");
arrWasCloneIDs[arrWasCloneIDsLn[1]]=arrWasCloneIDsLn[2];
}
close(clndln);
close(fWasCloneIdsMap);
#Initialize array for User count by Hour
for (i=0; i < 24; i++){
if(i<10){
j=0i;
} else {
j=i;
}
for(rngIdx in arrRangeName){
arrHrlRange[j","arrRangeName[rngIdx]]=0;
}
}
#Initialize the baseline performance
if(fBaseLine != ""){
while((getline bsln < fBaseLine) > 0){
split(bsln,arrBslineLn,"|");
arrBaseLine[arrBslineLn[1]]=arrBslineLn[2];
}
close(bsln);
close(fBaseLine);
}
print "=====================================================" > fTempHttp".summary";
print "===== Http Access log analysis report =====" >> fTempHttp".summary";
print "===== based on access logs dated: " recDate" =====" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "" >> fTempHttp".summary";
print "===== Summary table contains short heading title. See below for their description =====" >> fTempHttp".summary";
print "Note: Hourly statistics excludes the following static contents from calculation:" >> fTempHttp".summary";
print "excludes with these extensions: " >> fTempHttp".summary";
pSFmt="%-5s\t%-70s\n";
printf pSFmt,"hr",": Hour " >> fTempHttp".summary";
printf pSFmt,"date",": Date " >> fTempHttp".summary";
printf pSFmt,"time",": Time " >> fTempHttp".summary";
printf pSFmt,"uid",": User ID" >> fTempHttp".summary";
printf pSFmt,"js",": jSession" >> fTempHttp".summary";
printf pSFmt,"was",": WebSphere Application Server or App Server" >> fTempHttp".summary";
printf pSFmt,"ws",": Web Server like Apache or IBM HTTP Server (IHS)" >> fTempHttp".summary";
printf pSFmt,"jvm",": Java Virtual Machine (JVM)" >> fTempHttp".summary";
printf pSFmt,"req",": HTTP Request like GET, POST etc." >> fTempHttp".summary";
printf pSFmt,"rsp",": HTTP Response code like 200, 400 etc." >> fTempHttp".summary";
printf pSFmt,"sz",": Size - HTTP response size" >> fTempHttp".summary";
printf pSFmt,"uuc",": Unique User Count" >> fTempHttp".summary";
printf pSFmt,"uupc",": Unique User Count in Percentage " >> fTempHttp".summary";
printf pSFmt,"usc",": Unique jSession Count" >> fTempHttp".summary";
printf pSFmt,"uspc",": Unique jSession Count in Percentage" >> fTempHttp".summary";
printf pSFmt,"art",": Average Response Time in Second" >> fTempHttp".summary";
printf pSFmt,"bart",": Baseline Average Response Time in Second" >> fTempHttp".summary";
printf pSFmt,"rt",": (HTTP) Response Time in Second" >> fTempHttp".summary";
printf pSFmt,"mnrt",": Minimum Response Time in Second for the given access request or transaction" >> fTempHttp".summary";
printf pSFmt,"mxrt",": Maximum Response Time in Second for the given access request or Transaction" >> fTempHttp".summary";
printf pSFmt,"rng",": Response Range (second). What range like 1 second, 5 second etc. range the response falls." >> fTempHttp".summary";
printf pSFmt,"<=1",": Less than or eaual to One Second response range in percentage" >> fTempHttp".summary";
printf pSFmt,"<=5",": Greater than One Second and less than or equal to Five Seconds response range in percentage" >> fTempHttp".summary";
printf pSFmt,"<=10",": Greater than Five Seconds and less than or equal to Ten Seconds response range in percentage" >> fTempHttp".summary";
printf pSFmt,"<=20",": Greater than Ten seconds and less than or equal to Twenty Seconds response range in percentage" >> fTempHttp".summary";
printf pSFmt,">20",": More than Twenty Seconds in Percentage" >> fTempHttp".summary";
printf pSFmt,"xrc",": Total Record (Request,Response or Transaction) Count - that excludes static contents like jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml. " >> fTempHttp".summary";
printf pSFmt,"xrpc",": Total Record (Request,Response or Transaction) Count in Percentage - that excludes static contents like jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml. " >> fTempHttp".summary";
printf pSFmt,"irc",": Total Record (Request,Response or Transaction) Count - that includes static contents. " >> fTempHttp".summary";
printf pSFmt,"irpc",": Total Record (Request,Response or Transaction) Count in Percentage - that includes static contents. " >> fTempHttp".summary";
printf pSFmt,"cnt",": (Any) Count like jSession count, User count etc. " >> fTempHttp".summary";
printf pSFmt,"pc",": (Any) Count or measure represented in Percentage" >> fTempHttp".summary";
printf pSFmt,"srv",": Server - like Web Server(IHS), App Server etc." >> fTempHttp".summary";
printf pSFmt,"url",": URL" >> fTempHttp".summary";
printf pSFmt,"bwsr",": Browser" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "Host","Date","Time","tz","Hour","JSession","CloneID","WAS","Domain","Page","Extension","URL","Params","Protocol","Request","Response","Size","ByteRcvd","ByteSent","UID","RespTimeInSec","RangeInSec","Browser","OS","OS Flavor","OS Ver" > fTempHttp".discarded";
}
{
# This particular script is written to parse the access_log in the following format:
#LogFormat "%h %l %u %t \"%r\" %>s %b JSESSIONID=\"%{JSESSIONID}C\" UID=\"%{UID}C\" %D %I %O \"%{User-agent}i\" %v" common
# Apache log format: http://httpd.apache.org/docs/current/mod/mod_log_config.html
# %h: remote client host.
# %l: remote logname from identd, if supplied; requires mod_ident and IdentityCheck set On.
# %u: remote user from auth; may be bogus if return status (%s) is 401.
# %t: time the request was received.
# %r: first line of request
# %>s: the status code sent from the server to the client, e.g. 200, 404 etc.
# %b: the size of the response to the client, in bytes.
# %D: the time taken to serve the request, in microseconds.
# %{JSESSION}C: The contents of cookie JSESSION in the request sent to the server. Only version 0 cookies are fully supported.
# %{UID}C: The contents of cookie UID in request sent to the server.
# %I: bytes received, including request and headers, cannot be zero; requires mod_logio enabled.
# %O: Bytes sent, including headers, cannot be zero; requires mod_logio to use this.
# %{User-agent}i: the content of User-agent: header line in the request sent to the server.
# %v: the (canonical) server name of the server serving the request
#Typical access_log record looks like the following:
#xx.xxx.xxx.xx - - [13/Jun/2015:10:32:04 -0400] "GET /dashBoardScreen/global/images/application-logoen.png HTTP/1.1" 200 66497 JSESSIONID="00006zV1pGhZFY7Gg2P1nzrkjyd:19670enb4" UID="abc.def@xyz.com" 162452 1545 67052 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" srvwebxxxxx0x0
#xx.xxx.xxx.xx - abc.def@xyz.com [13/Jun/2015:10:32:04 -0400] "GET /dashBoardScreen/global/js/devGlobal.js HTTP/1.1" 200 3212 JSESSIONID="00006zV1pGhZFY7Gg2P1nzrkjyd:19670enb4" UID="abc.def@xyz.com" 225677 1534 3649 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" srvwebxxxxx0x0
#---Process 1st field
#xx.xxx.xxx.xx - abc.def@xyz.com [13/Jun/2015:10:32:03 -0400]
fld1=$1;
# Tokenize first field
split(fld1,arr1stFld," ");
split(arr1stFld[4],arrTs,":");
# Date
dt=substr(arrTs[1],2);
split(dt,arrDt,"/");
_dd=arrDt[1];
_mnt=arrDt[2];
_mm=mntArr[_mnt];
_yyyy=arrDt[3];
# Time
tm=arrTs[2]":"arrTs[3]":"arrTs[4];
# hour
hour=arrTs[2];
_min=arrTs[3];
_sec=arrTs[4];
# timezone
tz=substr(arr1stFld[5],1,5);
_stdTmStr=_yyyy" "_mm" "_dd" "hour" "_min" "_sec" "tz;
tmInSec=mktime(_stdTmStr);
#---Process 2nd field
#GET /ClntIdxWb/pages/client/clntSearch.faces?ctx=com.sysg.finMgmt HTTP/1.1
fld2=$2;
# Tokenize 2nd field
split(fld2,arr2ndFld," ");
_request=arr2ndFld[1];
if(_request ~ /(^GET$|^POST$|^PUT$|^HEAD$|^OPTIONS$|^CONNECT$|^DELETE$|^TRACE$|^SECURE$|^SEARCH$|^PROPATCH$|^PROFIND$|^MKCOL$)/){
request = _request;
preParams="";
} else {
#some urls are like this: "eventId=409970&consentComments=&finMgmtExpand=falseGET /SysgSso/redirect.jsp HTTP/1.1"
switch(_request){
case /.*GET$/:
request="GET";
break;
case /.*POST$/:
request="POST";
break;
case /.*PUT$/:
request="PUT";
break;
case /.*HEAD$/:
request="HEAD";
break;
case /.*OPTIONS$/:
request="OPTIONS";
break;
case /.*CONNECT$/:
request="CONNECT";
break;
case /.*DELETE$/:
request="DELETE";
break;
case /.*TRACE$/:
request="TRACE";
break;
case /.*SECURE$/:
request="SECURE";
break;
case /.*SEARCH$/:
request="SEARCH";
break;
case /.*PROPATCH$/:
request="PROPATCH";
break;
case /.*PROFIND$/:
request="PROFIND";
break;
case /.*MKCOL$/:
request="MKCOL";
break;
}
preParams=_request;
}
#Split the URL into uriPath and Parameters
split(arr2ndFld[2],url,"?");
uriPath=url[1];
#parse uri path to extract domain, page, and extension
if(uriPath != "") {
if(uriPath == "/"){
domain="/";
page="NA";
ext="NA";
} else {
split(uriPath,arrUriPath,"/");
if(arrUriPath[2] ~ /.*\..*/){
domain="/";
page=arrUriPath[2];
split(page,arrPage,".");
ext=arrPage[2];
} else {
domain=arrUriPath[2];
page=arrUriPath[length(arrUriPath)];
split(page,arrPage,".");
if(length(arrPage) > 0){
ext=arrPage[length(arrPage)];
} else {
ext="NA";
}
}
}
} else {
domain="NA";
page="NA";
ext="NA";
}
# create domain array
arrDmnLst[domain];
params=url[2];
if(preParams != ""){
if(params != "")
params=params"&"preParams;
else
params=preParams;
}
protocol=arr2ndFld[3];
#---Process 3rd field
#302 20 JSESSIONID="-
#200 28075 JSESSIONID="00006zV1pGhZFY7Gg2P1nzrkjyd:19758rty4
fld3=$3;
# Tokenize 3rd field
split(fld3,arr3rdFld," ");
# response code
response=arr3rdFld[1];
# Response size to client in bytes
size=arr3rdFld[2];
#remove 'JSESSIONID=\"' as it is not necessary.
gsub(/JSESSIONID=\"/,"",arr3rdFld[3]);
if(arr3rdFld[3] != "-"){
split(arr3rdFld[3],arrSess,":");
# remove '0000' prefix from jsession as it is useless
jsession=substr(arrSess[1],5);
cloneID=arrSess[2];
was=arrWasCloneIDs[cloneID];
} else {
jsession="-";
cloneID="-";
was="-";
}
#print arr3rdFld[3],jsessStr,jsession,cloneID
#---Process 4th field
#UID="abc.def@xyz.com
fld4=$4;
#Remove first 5 character (i.e. UID=\") to retrieve UID
uid=substr(fld4,6);
#---Process 5th field
#46954 2474 6210
fld5=$5;
split(fld5,arrFld5," ");
# get response time and convert micro second to second
respTime=arrFld5[1]/1000000
# Byte Received
byteRcvd=arrFld5[2];
# Bytes sent
byteSnt=arrFld5[3];
# determine response range
if(respTime <= 1) {
respRange = arrRangeName[1];
} else {
if(respTime <= 5) {
respRange = arrRangeName[2];
} else {
if(respTime <= 10) {
respRange = arrRangeName[3]
} else{
if(respTime <= 20) {
respRange = arrRangeName[4];
} else {
respRange = arrRangeName[5];
}
}
}
}
#---Process 6th field
# Mapping of Windows NT to Actual Windows OS:
# https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
# https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
# User agent: https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
#Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
#"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36"
#"Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4"
#"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
#"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" - IE11
#"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
#"Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko"
#"Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"
#"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
#"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)"
#"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727;SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; CMDTDFJS; InfoPath.3)"
#Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.<OS build number>
fld6=$6;
split(fld6,arrUAgnt," ");
uAgntArrSize=length(arrUAgnt);
osName="";
osFlav="";
osVer="";
name="";
mode="";
rev="";
trident="";
browser="";
switch(fld6){
case /.*X11.*Linux.*/:
#"Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)"
browser=arrUAgnt[uAgntArrSize-1];
osName=arrUAgnt[3]"/"substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
osFlav=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
osVer=substr(arrUAgnt[5],4,length(arrUAgnt[5])-4);
#print "browser:"browser";osName:"osName";osFlav:"osFlav";osVer:"osVer;
break;
case /.*Firefox.*/:
browser=arrUAgnt[uAgntArrSize];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(compatible; MSIE [0-9]+\.[0-9]+; Windows NT [0-9]+\.[0-9]+; Trident\/.*\)/:
mode=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
trident=substr(arrUAgnt[8],1,length(arrUAgnt[8])-1);
rev=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
name=arrUAgnt[3];
browser=name"/"rev";"mode";"trident;
osName=arrUAgnt[5];
osFlav=arrUAgnt[6];
osVer=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(Windows NT [0-9]+\.[0-9]+; WOW64; Trident\/[0-9]+\.[0-9]+; rv:[0-9]+\.[0-9]+\) like Gecko/:
trident=substr(arrUAgnt[6],1,length(arrUAgnt[6])-1);
rev=substr(arrUAgnt[7],4,length(arrUAgnt[7])-4);
name="MSIE";
browser=name"/"rev";"trident;
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(Windows NT [0-9]+\.[0-9]+; WOW64; Trident\/[0-9]+\.[0-9]+; .*; rv:[0-9]+\.[0-9]+\) like Gecko/:
trident=substr(arrUAgnt[6],1,length(arrUAgnt[6])-1);
rev=substr(arrUAgnt[8],4,length(arrUAgnt[8])-4);
name="MSIE";
browser=name"/"rev";"trident;
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(Windows NT [0-9]+\.[0-9]+; Win64; x64; Trident\/[0-9]+\.[0-9]+; .*; rv:[0-9]+\.[0-9]+\) like Gecko/:
trident=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
rev=substr(arrUAgnt[9],4,length(arrUAgnt[9])-4);
name="MSIE";
browser=name"/"rev";"trident;
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(Windows NT [0-9]+\.[0-9]+; Win64; x64; Trident\/[0-9]+\.[0-9]+; rv:[0-9]+\.[0-9]+\) like Gecko/:
trident=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
rev=substr(arrUAgnt[8],4,length(arrUAgnt[8])-4);
name="MSIE";
browser=name"/"rev";"trident;
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(Windows NT [0-9]+\.[0-9]+; Trident\/[0-9]+\.[0-9]+; rv:[0-9]+\.[0-9]+\) like Gecko/:
trident=substr(arrUAgnt[5],1,length(arrUAgnt[5])-1);
rev=substr(arrUAgnt[6],4,length(arrUAgnt[6])-4);
name="MSIE";
browser=name"/"rev";"trident;
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(compatible; MSIE [0-9]+\.[0-9]+; Windows NT [0-9]+\.[0-9]+; WOW64; Trident\/.*\)/:
mode=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
rev=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1)
trident=substr(arrUAgnt[9],1,length(arrUAgnt[9])-1);
name=arrUAgnt[3];
browser=name"/"rev";"mode";"trident;
osName=arrUAgnt[5];
osFlav=arrUAgnt[6];
osVer=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(compatible; MSIE [0-9]+\.[0-9]+; Windows NT [0-9]+\.[0-9]+; Win64; x64; Trident\/.*\)/:
mode=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
trident=substr(arrUAgnt[10],1,length(arrUAgnt[10])-1);
rev=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
name=arrUAgnt[3];
browser=name"/"rev";"mode";"trident;
osName=arrUAgnt[5];
osFlav=arrUAgnt[6];
osVer=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
break;
case /Mozilla\/[0-9]+\.[0-9]+ \(compatible; MSIE [0-9]+\.[0-9]+; Windows NT [0-9]+\.[0-9]+.*\)/:
mode=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
trident="";
rev=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
name=arrUAgnt[3];
browser=name"/"rev";"mode;
osName=arrUAgnt[5];
osFlav=arrUAgnt[6];
osVer=substr(arrUAgnt[7],1,length(arrUAgnt[7])-1);
break;
case /.*Edge\/[0-9]+\..*/:
browser=arrUAgnt[uAgntArrSize];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /.*iPad.*AppleWebKit\/.*\(KHTML, like Gecko\) .*Safari\/.*/:
#"Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4"
#"Mozilla/5.0 (iPad; CPU OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/58.0.3029.83 Mobile/14A456 Safari/602.1"
browser=arrUAgnt[uAgntArrSize-1]"/"arrUAgnt[uAgntArrSize];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
osFlav=arrUAgnt[6]" "arrUAgnt[7]" "arrUAgnt[8]" "substr(arrUAgnt[9],1,length(arrUAgnt[9])-1);
osVer=arrUAgnt[5];
break;
case /.*iPhone.*AppleWebKit\/.*\(KHTML, like Gecko\) [^Chrome].*Safari\/.*/:
#"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
browser=arrUAgnt[17];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
osFlav=arrUAgnt[7]" "arrUAgnt[8]" "arrUAgnt[9]" "substr(arrUAgnt[10],1,length(arrUAgnt[10])-1);
osVer=arrUAgnt[6];
break;
case /.*Linux.*Android.*AppleWebKit\/.*\(KHTML, like Gecko\) [Chrome].*Safari\/.*/:
#"Mozilla/5.0 (Linux; Android 5.0; SM-G900W8 Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36"
browser=arrUAgnt[uAgntArrSize-2]"/"arrUAgnt[uAgntArrSize-1]"/"arrUAgnt[uAgntArrSize];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2])-2);
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
case /.*AppleWebKit\/.*\(KHTML, like Gecko\) [Chrome].*Safari\/.*/:
#"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
browser=arrUAgnt[uAgntArrSize-1]"/"arrUAgnt[uAgntArrSize];
osName=substr(arrUAgnt[2],2,length(arrUAgnt[2]));
osFlav=arrUAgnt[3];
osVer=substr(arrUAgnt[4],1,length(arrUAgnt[4])-1);
break;
default:
browser="Other";
osName="Other";
osFlav="na";
osVer="na";
# log the unknown user agent into file for review.
print $0 >> fTempHttp".unknownua";
break;
}
#---Process 7th field
#srvwebp0bfv050 app_user="abc.def@sysg.com
split($7,fld7Tok," ");
#webSrvr=$7
webSrvr=fld7Tok[1];
#print formatted and filtered access log records
# here is output field mapping, may need later
# $1:webSrvr;$2:dt;$3:tm;$4:tz;$5:hour;$6:jsession;$7:cloneID;$8:was;$9:domain;$10:page;$11:ext;$12:uriPath;$13:params;$14:protocol;$15:request
# $16:response;$17:size;$18:byteRcvd;$19:byteSnt;$20:uid;$21:respTime;$22:respRange;$23:browser;$24:osName;$25:osFlav;$26:osVer.
print webSrvr,dt,tm,tz,hour,jsession,cloneID,was,domain,page,ext,uriPath,params,protocol,request,response,size,byteRcvd,byteSnt,uid,respTime,respRange,browser,osName,osFlav,osVer >> fTempHttp".access_log_all";
# Create separate array of transaction that has response code greater than or equal to 400 and also print them in separate file.
if(response >= 400){
arrUri400plsUriRange[uriPath"|"response]++;
}
#Gather some request stats for monthly reporting
arrByHstByRqst[webSrvr"|"request]++;
arrByHstByRsp[webSrvr"|"response]++;
arrWebSrv[webSrvr];
# discard certain records and write them into separate file for review.
# request comming from Curl, 'curl'
# request not having UID, i.e. UID="-"
if (fld6 ~ /curl\/*/ || uid == "-" || uid ==""){
discRecCnt++;
#print the discarded record in separate file for later review
print webSrvr,dt,tm,tz,hour,jsession,cloneID,was,domain,page,ext,uriPath,params,protocol,request,response,size,byteRcvd,byteSnt,uid,respTime,respRange,browser,osName,osFlav,osVer >> fTempHttp".discarded";
} else {
rcdCntIncl++;
# daily unique users
arrDlyuUid[uid];
# hourly unique users
arrHrlUUid[hour","uid];
if(uid != "" && uid != "-"){
# daily unique users by domain
arrDlyuUidDmn[uid","domain];
# hourly unique users by domain
arrHrlUUidDmn[hour","uid","domain];
arrWebUid[webSrvr"|"uid];
if(cloneID != "" && cloneID != "-")
arrWasUid[was","cloneID","uid];
}
if(jsession != "" && jsession != "-"){
arrHrljSess[hour","jsession]=uid;
# hourly jSesion by Domain
arrHrljSessDmn[hour","jsession","domain];
#daily unique jSession;
arrDlyjSess[cloneID","jsession];
#daily unique jSession by Domain
arrDlyjSessDmn[cloneID","jsession","domain];
#jSession count by web server.
#Note: since there is possibility that two AppServer may generate same jsession and when
#finding unique session at Web Server, these two may be considered as one, so use cloneID in combination.
arrWebHostjSess[webSrvr","jsession","cloneID];
#jSession count by WAS
arrWasjSess[was","cloneID","jsession];
#where the user is in particular momenet:
if(uriPath == "/SecurityWeb/roleSelect/loginRoleSelect.xhtml"){
arrWhereUidStart[webSrvr" "was" "cloneID" "jsession" "uid]=dt":"tm" "tmInSec;
}
if(uriPath == "/SecurityWeb/Portal" && params ~ /logout=true/){
arrWhereUidEnd[webSrvr" "was" "cloneID" "jsession" "uid]=dt":"tm" "tmInSec;
}
}
#Count by http response code
arrRespCnt[response]++;
# Array for uri range
arrURIRange[uriPath","respRange]++;
arrURITimeSum[uriPath]+=respTime;
arrURICnt[uriPath]++
#Hourly record count - including static content
arrHrlyRcdCntIncl[hour]++;
# Summarize by extension
arrExtRange[ext","respRange]++;
arrExtCnt[ext]++;
arrExtRspTmSum[ext]+=respTime;
arrBrwsr[browser","uid];
arrOS[osName","osFlav","osVer","uid];
# request count by Web Server - including static content
arrReqCntByWSIncl[webSrvr]++;
arrReqCntByWASIncl[was","cloneID]++;
# Exclude static content for the following calculation
# hourly response range
if(response != "304" && ext !~ /(^jpg$|^gif$|^png$|^ico$|^js$|^cgi$|^css$|^htm$|^html$|^pdf$|^null$|^doc$|^xlsx$|^xsl$|^aspx$|^txt$)/ && uriPath !~ /(.*\.css\.xhtml$|.*\.js\.xhtml$|.*\.png\.xhtml$|.*\.gif\.xhtml$)/ && params !~ /(WilyCmd=cmdJS|WilyCmd=cmdMetrics)/){
#Daily Record count - excluding static contents
rcdCntXcl++;
#Hourly record count - excluding static content
arrHrlyRcdCntXcl[hour]++;
#Hourly range
arrHrlRange[hour","respRange]++;
#Hourly Sum of response time
arrHrlyRspTimeSum[hour]+=respTime;
#Damily Response time sum
dlyRespTimeSum+=respTime;
#Daily range
arrDlyRange[respRange]++;
#arrDmnRange[domain","respRange]++;
arrDmnSum[domain]+=respTime;
arrDmnCnt[domain]++;
arrUidRange[uid","respRange]++;
arrUidSum[uid]+=respTime;
arrUidCnt[uid]++;
# stats by Web and App server
arrReqCntByWSXcl[webSrvr]++;
arrReqCntByWASXcl[was","cloneID]++;
# range
arrRngByWS[webSrvr","respRange]++;
arrRngByWAS[was","cloneID","respRange]++;
# perf
arrPerfByWS[webSrvr]+=respTime;
arrPerfByWAS[was","cloneID]+=respTime;
# record min and max time for the transaction
min=max=respTime;
uriMnMxStr=arrURIMnMx[uriPath];
if(uriMnMxStr != ""){
split(uriMnMxStr,uriMnMxStrTok,"|");
min=uriMnMxStrTok[1];
max=uriMnMxStrTok[2];
if(respTime > max){
max=respTime;
arrURIMnMx[uriPath]=min"|"max;
} else {
if(respTime < min){
min=respTime;
arrURIMnMx[uriPath]=min"|"max;
}
}
} else {
arrURIMnMx[uriPath]=min"|"max;
}
}
}
} END {
# print request type and response code matrics by server.
if(rptType == "daily"){
#DO NOT CHANGE THE SEQUENCE
reqLst="GET|POST|PUT|HEAD|OPTIONS|CONNECT|DELETE|TRACE|PROFIND|SEARCH|PROPATCH|SECURE|MKCOL";
split(reqLst,arrReqLst,"|");
#DO NOT CHANGE THE SEQUENCE
rspLst="100|101|102|103|200|201|202|203|204|205|206|207|208|226|300|301|302|303|304|305|306|307|308|400|401|402|403|404|405|406|407|408|409|410|411|412|413|414|415|416|417|418|419|420|421|422|423|424|426|428|429|431|440|444|449|450|451|495|496|497|498|499|500|501|502|503|504|505|506|507|508|509|510|511|520|521|523|524|525|526";
split(rspLst,arrRspLst,"|");
reqStr="";
if(length(arrByHstByRqst) >0){
for(eWS in arrWebSrv){
eWSReqStr="";
for(reqIdx in arrReqLst){
_val=arrByHstByRqst[eWS"|"arrReqLst[reqIdx]];
if(_val == "")
_val = 0;
if(length(eWSReqStr) > 0)
eWSReqStr=eWSReqStr"|"_val;
else
eWSReqStr=_val;
}
eWSReqStr=recDate"|"eWS"|"eWSReqStr;
if(length(reqStr) > 0)
reqStr=reqStr"\n"eWSReqStr;
else
reqStr=eWSReqStr;
}
print reqStr >> rptRqstTypeByHostHistFile;
}
if(length(arrByHstByRsp) > 0){
rspStr="";
for(eWS in arrWebSrv){
eWSRspStr="";
for(eRspIdx in arrRspLst){
_val=arrByHstByRsp[eWS"|"arrRspLst[eRspIdx]];
if(_val == "")
_val = 0;
if(length(eWSRspStr) > 0)
eWSRspStr=eWSRspStr"|"_val;
else
eWSRspStr=_val;
}
eWSRspStr=recDate"|"eWS"|"eWSRspStr;
if(length(rspStr) > 0)
rspStr=rspStr"\n"eWSRspStr;
else
rspStr=eWSRspStr;
}
print rspStr >> rptRspByCodeHistFile;
}
}
# print roaming user
if(length(arrRoamUid) > 0){
for(eRuid in arrRoamUid){
print eRuid >> fTempHttp".ruid";
}
}
# print number of discarded records in summary file.
print "Number of discarded records : "discRecCnt >> fTempHttp".summary";
# Create alert if number of discarded records is higher than certain threshold
if(discRecCnt > arrTh["httpDiscRcdCountTh"]){
print discRecCnt" : total number of discarded record counts exceeds threshold of : "arrTh["httpDiscRcdCountTh"]". Review "rptDiscardedRecordsFile >> alrtF;
}
# Print hourly statistics
print "" >> fTempHttp".summary";
print "" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "===== Hourly Statistics =====" >> fTempHttp".summary";
print "Note: Hourly statistics excludes the following static contents from calculation:" >> fTempHttp".summary";
print "excludes with these extensions: jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "" >> fTempHttp".summary";
hrlHdFmt="%-3s\t%5s\t%5s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\t%8s\t%8s\n";
hrlBdFmt="%-3d\t%5d\t%5d\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8d\t%8d\n";
printf hrlHdFmt,"hr","uuc","usc","art",arrRangeName[1],arrRangeName[2],arrRangeName[3],arrRangeName[4],arrRangeName[5],"xrc","irc" >> fTempHttp".summary";
#for hourly average history file
tmpHrlyAvgStr=""recDate;
tmpHrlyuUidStr=""recDate;
for (i=0; i < 24; i++){
if(i<10){
j=0i;
} else {
j=i;
}
hrUidCnt[j]=0;
for(hduid in arrHrlUUid){
split(hduid,hr,",");
if(j == hr[1]){
hrUidCnt[j]++;
}
}
hrjSessCnt[j]=0;
for(hdjSess in arrHrljSess){
split(hdjSess,hs,",");
if(j == hs[1]){
hrjSessCnt[j]++;
}
}
hrlyAvgRespTime="";
if(arrHrlyRcdCntXcl[j] > 0){
hrlyAvgRespTime=arrHrlyRspTimeSum[j]/arrHrlyRcdCntXcl[j];
}
tmpHrlyuUidStr=tmpHrlyuUidStr"|"hrUidCnt[j];
tmpHrlyAvgStr=tmpHrlyAvgStr"|"hrlyAvgRespTime;
#hrlyRowTtl=arrHrlRange[j","arrRangeName[1]]+arrHrlRange[j","arrRangeName[2]]+arrHrlRange[j","arrRangeName[3]]+arrHrlRange[j","arrRangeName[4]]+arrHrlRange[j","arrRangeName[5]];
if(arrHrlyRcdCntXcl[j] > 0){
hrlPc=100/arrHrlyRcdCntXcl[j];
} else {
hrlPc="";
}
if(hrUidCnt[j] > 0) {
printf hrlBdFmt, j, hrUidCnt[j],hrjSessCnt[j], hrlyAvgRespTime, arrHrlRange[j","arrRangeName[1]]*hrlPc, arrHrlRange[j","arrRangeName[2]]*hrlPc, arrHrlRange[j","arrRangeName[3]]*hrlPc, arrHrlRange[j","arrRangeName[4]]*hrlPc, arrHrlRange[j","arrRangeName[5]]*hrlPc,arrHrlyRcdCntXcl[j],arrHrlyRcdCntIncl[j] >> fTempHttp".summary";
}
# Alert if average response time is higher than threshold
if(hrlyAvgRespTime > arrTh["httpAvgRespTimeTh"]) {
print "Average response time: "hrlyAvgRespTime " : for hour: "j" exceeds threshold value: "arrTh["httpAvgRespTimeTh"]". Investigate further ..." >> alrtF;
}
#hourly domain count by unique user
for(eDmn in arrDmnLst){
arrHrlDmnByUuid[j","eDmn];
arrHrlDmnBySess[j","eDmn];
for(eRec in arrHrlUUidDmn){
split(eRec,arrRecUUidDmn,",");
if(arrRecUUidDmn[1] == j && arrRecUUidDmn[3] == eDmn){
arrHrlDmnByUuid[arrRecUUidDmn[1]","eDmn]++;
}
}
for(eRec in arrHrljSessDmn){
split(eRec,arrRecSessDmn,",");
if(arrRecSessDmn[1] == j && arrRecSessDmn[3] == eDmn){
arrHrlDmnBySess[arrRecSessDmn[1]","eDmn]++;
}
}
}
}
#print the hourly average in hourly average history file
if(rptType == "daily"){
print tmpHrlyAvgStr >> rptHrlyAvgHistFile;
print tmpHrlyuUidStr >> rptUnqUsrHrlyHistFile;
}
#print daily range
#dlyRowTtl=arrDlyRange[arrRangeName[1]]+arrDlyRange[arrRangeName[2]]+arrDlyRange[arrRangeName[3]]+arrDlyRange[arrRangeName[4]]+arrDlyRange[arrRangeName[5]];
if(rcdCntXcl > 0){
dlyPc=100/rcdCntXcl;
} else {
dlyPc=0;
}
# Calculate daily average - excludes the static contents
dlyAvgRespTime=0;
if(rcdCntXcl > 0){
dlyAvgRespTime=dlyRespTimeSum/rcdCntXcl;
}
#print rcdCntXcl,dlyAvgRespTime,arrDlyRange[arrRangeName[1]]*dlyPc, arrDlyRange[arrRangeName[2]]*dlyPc, arrDlyRange[arrRangeName[3]]*dlyPc, arrDlyRange[arrRangeName[4]]*dlyPc, arrDlyRange[arrRangeName[5]]*dlyPc;
# Alert logic for daily average and range
if(length(arrTh) > 0 ){
# Alert for Average response time
if(arrTh["httpAvgRespTimeTh"] != "" && dlyAvgRespTime != "" && dlyAvgRespTime > arrTh["httpAvgRespTimeTh"]){
print "Overall average response time: "dlyAvgRespTime " : exceeds the threshold value of "arrTh["httpAvgRespTimeTh"]". Investigate further ..." >> alrtF;
}
# Alert for range percentage
if(arrTh["httpDly1SecRangeTh"] != "" && arrDlyRange[arrRangeName[1]]*dlyPc < arrTh["httpDly1SecRangeTh"]){
print arrDlyRange[arrRangeName[1]]*dlyPc "% in 1 sec range is less than expected threshold value of "arrTh["httpDly1SecRangeTh"]"%. Investigate further ..." >> alrtF;
}
if(arrTh["httpDly20SecRangeTh"] != "" && arrDlyRange[arrRangeName[5]]*dlyPc > arrTh["httpDly20SecRangeTh"]){
print arrDlyRange[arrRangeName[5]]*dlyPc "% in 20 sec or higher range is more than threshold value of "arrTh["httpDly20SecRangeTh"]"%. Investigate further ..." >> alrtF;
}
}
# summary by UID
for(eachUid in arrUidCnt){
avgRspTimeByUid="";
if(arrUidCnt[eachUid] > 0){
avgRspTimeByUid=arrUidSum[eachUid]/arrUidCnt[eachUid];
uidRngPc=100/arrUidCnt[eachUid];
}
#Print into separate file as it may have few hundred lines. Later on top 10 users can be printed into summary file.
print eachUid,arrUidRange[eachUid","arrRangeName[1]]*uidRngPc,arrUidRange[eachUid","arrRangeName[2]]*uidRngPc,arrUidRange[eachUid","arrRangeName[3]]*uidRngPc,arrUidRange[eachUid","arrRangeName[4]]*uidRngPc,arrUidRange[eachUid","arrRangeName[5]]*uidRngPc,arrUidCnt[eachUid],avgRspTimeByUid >> fTempHttp".byuid"
}
#Print the daily summary into history file
if(rptType == "daily"){
print recDate,length(arrUidCnt),length(arrDlyjSess),arrDlyRange[arrRangeName[1]]*dlyPc, arrDlyRange[arrRangeName[2]]*dlyPc, arrDlyRange[arrRangeName[3]]*dlyPc, arrDlyRange[arrRangeName[4]]*dlyPc, arrDlyRange[arrRangeName[5]]*dlyPc,dlyAvgRespTime,rcdCntXcl,rcdCntIncl >> rptPerfHistFile;
}
#print daily summary also in summary file.
print "" >> fTempHttp".summary";
print "" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "===== Overall-Daily Statistics =====" >> fTempHttp".summary";
print "Note: Overall response range and average response time excludes the following static contents from calculation:" >> fTempHttp".summary";
print "excludes with these extensions: jpg|gif|png|ico|js|cgi|css|htm|html|pdf|null|doc|xlsx|xsl|aspx|txt|.css.xhtml|.js.xhtml|.png.xhtml|.gif.xhtml" >> fTempHttp".summary";
print "=====================================================" >> fTempHttp".summary";
print "" >> fTempHttp".summary";
dlyHdFmt="%-10s\t%5s\t%5s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\t%8s\t%8s\n";
dlyBdFmt="%10s\t%5d\t%5d\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8d\t%8d\n";
printf dlyHdFmt,"date","uuc","usc","art",arrRangeName[1],arrRangeName[2],arrRangeName[3],arrRangeName[4],arrRangeName[5],"xrc","irc" >> fTempHttp".summary";
printf dlyBdFmt,recDate,length(arrUidCnt),length(arrDlyjSess),dlyAvgRespTime,arrDlyRange[arrRangeName[1]]*dlyPc, arrDlyRange[arrRangeName[2]]*dlyPc, arrDlyRange[arrRangeName[3]]*dlyPc, arrDlyRange[arrRangeName[4]]*dlyPc, arrDlyRange[arrRangeName[5]]*dlyPc,rcdCntXcl, rcdCntIncl >> fTempHttp".summary"