This repository was archived by the owner on Jun 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog2db.pm
More file actions
611 lines (534 loc) · 19.3 KB
/
Copy pathlog2db.pm
File metadata and controls
611 lines (534 loc) · 19.3 KB
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
#! /usr/bin/perl -w
#
# Author: Sravan Bhamidipati @bsravanin
# License: MIT License http://www.opensource.org/licenses/mit-license.php
# Courtesy: Symantec Corporation http://www.symantec.com
# Date: 23rd November, 2011
# Purpose: Modify logs into text databases that vxperf2 can parse.
# DONE: esxtop iostat mpstat netstat pidstat prstat sar slabinfo top typeperf vmstat vxfsstatBCache vxfsstatICache vxstat
# TODO: sarasc
use strict;
use File::Basename;
use File::Path;
# Name: modifyIostat
# Purpose: To modify iostat log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyIostat {
my ($logPath, $tablePath, $time, $firstWord, $os, @temp) = ($_[0], $_[1], "", 0, "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if ($firstWord == 0) {
$firstWord++;
if (/Linux/) {$os = "linux"}
}
if ($os eq "linux") {
if (/Time:/) {
&use24HourFormat();
chomp();
s#.*(\d\d:\d\d:\d\d).*#$1#g;
$time = $_;
print MODIFIED "\n";
}
else {
if (/(\d\d)\/(\d\d)\/(\d\d)/ || $_ eq "\n") {}
else {
s#^(.*)(avg-cpu:)?#$time\t$1#;
(/Device:/) ? print MODIFIED "\n$_" : print MODIFIED $_;
}
}
}
else {
if (/\d\d:\d\d:\d\d/) {
&use24HourFormat();
chomp();
@temp = split(/\s+/, $_);
$time = $temp[3];
print MODIFIED "\n";
}
elsif (/tty\s+cpu/ || /extended\s+device\s+statistics/) {}
elsif (/device/) {print MODIFIED "\n$time\t$_"}
else {print MODIFIED "$time\t$_"}
}
}
close MODIFIED;
close LOG;
}
# Name: modifyNetstat
# Purpose: To modify netstat log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyNetstat {
my ($logPath, $tablePath, $interface, @temp) = ($_[0], $_[1], "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/input/) {
@temp = split(/\s+/, $_);
$interface = $temp[2];
}
elsif (/packets/) {print MODIFIED "\n$interface-input-packets\t$interface-input-errs\t$interface-output-packets\t$interface-output-errs\t$interface-output-colls\t$interface-input-total-packets\t$interface-input-total-errs\t$interface-output-total-packets\t$interface-output-total-errs\t$interface-output-total-colls\n"}
else {print MODIFIED $_}
}
close MODIFIED;
close LOG;
}
# Name: modifySlabinfo
# Purpose: To modify slabinfo log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifySlabinfo {
my ($logPath, $tablePath, $time) = ($_[0], $_[1], "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/SLAB_INFO > INFO/) {
&use24HourFormat();
chomp();
s#.*(\d\d:\d\d:\d\d).*#$1#g;
$time = $_;
print MODIFIED "\n";
}
else {
if (/slabinfo\s+-\s+version:/) {}
else {
s/#|<|>|:|tunables|slabdata//g && s#^#$time\t#;
print MODIFIED $_;
}
}
}
close MODIFIED;
close LOG;
}
# Name: modifySolstat
# Purpose: To modify mpstat or prstat log of Solaris to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifySolstat {
my ($logPath, $tablePath, $time, @temp) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/) {
&use24HourFormat();
chomp();
s#.*(\d\d:\d\d:\d\d).*#$1#g;
$time = $_;
print MODIFIED "\n";
}
elsif (/Total:/) {
@temp = split(/,\s+|\s+/, $_);
print MODIFIED "\nprocesses\tlwps\tld1\tld5\tld15\n$temp[1]\t$temp[3]\t$temp[7]\t$temp[8]\t$temp[9]\n\n";
}
else {
if (defined $time) {s#^(Total:|CPU)#\n$time\t$1# || s#^#$time\t#}
else {s#^(PID|CPU)#\n$1#}
print MODIFIED $_;
}
}
close MODIFIED;
close LOG;
}
# Name: modifySysstat
# Purpose: To modify pidstat or sar log of Sysstat to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifySysstat {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/(\d\d)\/(\d\d)\/(\d\d)/ || /Average/) {}
else {&use24HourFormat(); print MODIFIED $_}
}
close MODIFIED;
close LOG;
}
# Name: modifyTop
# Purpose: To modify Unix top log to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyTop {
my ($logPath, $tablePath, $time, $ld1, $ld5, $ld15, $procs, $idleProcs, $idle, $user, $kernel, $wait, $totalMem, $bufMem, $freeMem, $totalSwap, $freeSwap, @temp) = ($_[0], $_[1], "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/load averages/) {
@temp = split(/,\s+|;\s+|\s+/, $_);
$ld1 = $temp[2];
$ld5 = $temp[3];
$ld15 = $temp[4];
$time = $temp[5];
}
elsif (/processes/) {
@temp = split(/\s+/, $_);
$procs = $temp[0];
$idleProcs = $temp[2];
}
elsif (/CPU states/) {
@temp = split(/\s+/, $_);
$idle = $temp[2];
$user = $temp[4];
$kernel = $temp[6];
$wait = $temp[8];
}
elsif (/Memory/) {
@temp = split(/\s+/, $_);
$totalMem = $temp[1];
$bufMem = $temp[3];
$freeMem = $temp[5];
}
elsif (/Swap/) {
@temp = split(/\s+/, $_);
$totalSwap = $temp[1];
$freeSwap = $temp[3];
}
elsif (/PID/) {
print MODIFIED "\nTimestamp\tld1\tld5\tld15\tProcs\tIdleProcs\t%Idle\t%User\t%Kernel\t%Wait\tTotalMem\tBufMem\tFreeMem\tTotalSwap\tFreeSwap\n$time\t$ld1\t$ld5\t$ld15\t$procs\t$idleProcs\t$idle\t$user\t$kernel\t$wait\t$totalMem\t$bufMem\t$freeMem\t$totalSwap\t$freeSwap\n\nTimestamp\t$_";
}
elsif (/^$/) {}
else {print MODIFIED "$time\t$_"}
}
close MODIFIED;
close LOG;
}
# Name: modifyTypeperf
# Purpose: To modify esxtop (ESX) or typeperf (Windows) log to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyTypeperf {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
s#" "#"0"#g;
s#"\(|\)|\\\\##g;
s# |\(|\\|\/#-#g;
s#",#\t#g;
s#"##g;
s#-+#-#g;
print MODIFIED $_;
}
close MODIFIED;
close LOG;
}
# Name: modifyVmstat
# Purpose: To modify vmstat log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVmstat {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/memory/ || /--/) {print MODIFIED "\n"}
elsif (/us\s+sy\s+/) {
s#us\s+sy\s+#us sys #;
print MODIFIED $_;
}
else {print MODIFIED $_}
}
close MODIFIED;
close LOG;
}
# Name: modifyVrstat
# Purpose: To modify vrstat logs to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVrstat {
my ($logPath, $tablePath, $time) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/Replicated Data Set|Data Status:|sec_vvr:|Network Statistics:|Messages\s+Errors\s+Flow Control|--|HOST\s+NAME\s+OPERATIONS\s+BLOCKS\s+AVG TIME|READ\s+WRITE\s+READ\s+WRITE\s+READ\s+WRITE|Host\s+Pool\s+DG\s+Min\s+Max\s+In\s+Allocated\s+Max\s+Waiting|Size\s+Size\s+Use\s+Used/ || $_ eq "\n") {}
elsif (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/) {
&use24HourFormat();
chomp();
s#.*(\d\d:\d\d:\d\d).*#$1#g;
$time = $_;
}
elsif (/#\s+Blocks\s+RT\(msec\)\s+Timeout\s+Stream Memory\s+Delays/) {print MODIFIED "\nTime\t#\tBlocks\tRT(msec)\tTimeout\tStream\tMemory\tDelays\n"}
elsif (/Data Volume-I\/O Statistics:/) {print MODIFIED "\nTime\tHost\tName\tDVIO-OpsRd\tDVIO-OpsWr\tDVIO-BlksRd\tDVIO-BlksWr\tDVIO-AvgTimeRd\tDVIO-AvgTimeWr\n"}
elsif (/SRL-I\/O Statistics:/) {print MODIFIED "\nTime\tHost\tName\tSRLIO-OpsRd\tSRLIO-OpsWr\tSRLIO-BlksRd\tSRLIO-BlksWr\tSRLIO-AvgTimeRd\tSRLIO-AvgTimeWr\n"}
elsif (/Memory-pool Statistics:/) {print MODIFIED "\nTime\tHost\tPool\tDG\tMinSize\tMaxSize\tInUse\tAllocated\tMaxPoolUsed\tWaiting\n"}
else {print MODIFIED "$time\t$_"}
}
close MODIFIED;
close LOG;
}
# Name: modifyVvrstat
# Purpose: To modify vxmemstat, vxrlink, vxrvg logs to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVvrstat {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|--|Size\s+Size\s+Use\s+Used|Messages\s+Errors\s+Flow\s+Control|Conflicts\s+Max\sAvg\s+Max\s+Avg/ || $_ eq "\n") {}
elsif (/Pool\s+DG\s+Min\s+Max\s+In\s+Allocated\s+Max\s+Pool\s+Waiters/) {print MODIFIED "\nPool\tDG\tMinSize\tMaxSize\tInUse\tAllocated\tMaxPoolUsed\tWaiters\n"}
elsif (/#\s+Blocks\s+RT\(msec\)\s+Timeout\s+Stream Memory\s+Delays/) {print MODIFIED "\n#\tBlocks\tRT(msec)\tTimeout\tStream\tMemory\tDelays\n"}
elsif (/Read\/Write\s+Concurrency\s+Write-size/) {print MODIFIED "\nRWConflicts\tMaxConcurrency\tAvgConcurrency\tMaxWriteSize\tAvgWriteSize\n"}
else {print MODIFIED "$_"}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxfsstatBCache
# Purpose: To modify vxfsstat_bcache log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxfsstatBCache {
my ($logPath, $tablePath, $time, $current, $maximum, $lookups, $hitRate, $recycleAge, @temp) = ($_[0], $_[1], "", "", "", "", "", "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\ncurrent\tmaximum\tlookups\thitRate\trecycleAge\n";
print MODIFIED "\n";
while (<LOG>) {
chomp();
s#^\s+##;
if ($_ eq "\n" || /buffer cache statistics/) {}
elsif (/sample/) {
($time, @temp) = split(/\s+/, $_);
}
elsif (/Kbyte/) {
@temp = split(/\s+/, $_);
$current = $temp[0];
$maximum = $temp[3];
}
elsif (/lookups/) {
@temp = split(/\s+/, $_);
$lookups = $temp[0];
$hitRate = $temp[2];
}
elsif (/recycle/) {
($recycleAge, @temp) = split(/\s+/, $_);
print MODIFIED "$time\t$current\t$maximum\t$lookups\t$hitRate\t$recycleAge\n";
}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxfsstatICache
# Purpose: To modify vxfsstat_icache log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxfsstatICache {
my ($logPath, $tablePath, $time, $maximumDNLCEntries, $totalLookups, $fastDNLCLookups, $totalDNLCLookups, $DNLCHitRate, $totalEnter, $hitPerEnter, $totalDirCacheSetup, $callsPerSetup, $directoryScan, $fastDirectoryScan, $inodesCurrent, $inodesPeak, $inodesMaximum, $inodeLookups, $inodeHitRate, $inodesAllocated, $inodesFreed, $recycleAge, $freeAge, @temp) = ($_[0], $_[1], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
print MODIFIED "time\tmaximumDNLCEntries\ttotalLookups\tfastDNLCLookups\ttotalDNLCLookups\tDNLCHitRate\ttotalEnter\thitPerEnter\ttotalDirCacheSetup\tcallsPerSetup\tdirectoryScan\tfastDirectoryScan\tinodesCurrent\tinodesPeak\tinodesMaximum\tinodeLookups\tinodeHitRate\tinodesAllocated\tinodesFreed\trecycleAge\tfreeAge\n";
while (<LOG>) {
chomp();
s#^\s+##;
if ($_ eq "\n" && /Statistics/i) {}
elsif (/sample/) {
($time, @temp) = split(/\s+/, $_);
}
elsif (/maximum entries in dnlc/) {
($maximumDNLCEntries, @temp) = split(/\s+/, $_);
}
elsif (/fast lookup/) {
@temp = split(/\s+/, $_);
$totalLookups = $temp[0];
$fastDNLCLookups = $temp[3];
}
elsif (/dnlc lookup/) {
@temp = split(/\s+/, $_);
$totalDNLCLookups = $temp[0];
$DNLCHitRate = $temp[4];
}
elsif (/hit per enter/) {
@temp = split(/\s+/, $_);
$totalEnter = $temp[0];
$hitPerEnter = $temp[3];
}
elsif (/dircache/) {
@temp = split(/\s+/, $_);
$totalDirCacheSetup = $temp[0];
$callsPerSetup = $temp[4];
}
elsif (/scan/) {
@temp = split(/\s+/, $_);
$directoryScan = $temp[0];
$fastDirectoryScan = $temp[4];
}
elsif (/inodes current/) {
@temp = split(/\s+/, $_);
$inodesCurrent = $temp[0];
$inodesPeak = $temp[3];
$inodesMaximum = $temp[5];
}
elsif (/% hit rate/) {
@temp = split(/\s+/, $_);
$inodeLookups = $temp[0];
$inodeHitRate = $temp[2];
}
elsif (/freed/) {
@temp = split(/\s+/, $_);
$inodesAllocated = $temp[0];
$inodesFreed = $temp[3];
}
elsif (/recycle/) {
($recycleAge, @temp) = split(/\s+/, $_);
}
elsif (/free age/) {
($freeAge, @temp) = split(/\s+/, $_);
print MODIFIED "$time\t$maximumDNLCEntries\t$totalLookups\t$fastDNLCLookups\t$totalDNLCLookups\t$DNLCHitRate\t$totalEnter\t$hitPerEnter\t$totalDirCacheSetup\t$callsPerSetup\t$directoryScan\t$fastDirectoryScan\t$inodesCurrent\t$inodesPeak\t$inodesMaximum\t$inodeLookups\t$inodeHitRate\t$inodesAllocated\t$inodesFreed\t$recycleAge\t$freeAge\n";
}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxfsstatFile
# Purpose: To modify vxfsstat_file log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxfsstatFile {
my ($logPath, $tablePath, $time, @temp) = ($_[0], $_[1], "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
print MODIFIED "Time\tvxi\tCount\n";
while (<LOG>) {
if ($_ eq "\n") {}
elsif (/sample/) {
chomp();
($time, @temp) = split(/\s+/, $_);
}
else {print MODIFIED "$time\t$_"}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxrlinkE
# Purpose: To modify vxrlink_e logs to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxrlinkE {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
print MODIFIED "SentBlks\tFreeMem\tFreeSlots\tFreeMemNmcom\tTimeout\tMissingPkts\tMissingMsgs\tStream\tChecksum\tDeliveryFailed\n";
while (<LOG>) {
if (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Messages :|Errors :|--/ || $_ eq "\n") {}
elsif (/transaction/) {
s#.*(\d)#$1#g;
print MODIFIED "$_";
}
else {
chomp();
s#.*(\d)#$1#g;
print MODIFIED "$_\t";
}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxrlinkStatus
# Purpose: To modify vxrlink_status logs to tables.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxrlinkStatus {
my ($logPath, $tablePath) = ($_[0], $_[1]);
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
print MODIFIED "Outstanding\tOccupying\tPercentage\n";
while (<LOG>) {
if (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/ || $_ eq "\n") {}
elsif (/ is up to date/) {print MODIFIED "Up\tTo\tDate\n"}
else {
s#.* has ##g;
s# outstanding writes, occupying #\t#g;
s# Kbytes \(#\t#g;
s#%\).*##g;
print MODIFIED $_;
}
}
close MODIFIED;
close LOG;
}
# Name: modifyVxstat
# Purpose: To modify vxstat log to table.
# Parameters: Path to log file, path to table file.
# Returns: -
sub modifyVxstat {
my ($logPath, $tablePath, $time) = ($_[0], $_[1], "");
open LOG, $logPath or die "Cannot open $logPath for read: $!\n";
open MODIFIED, ">$tablePath" or die "Cannot open $tablePath for write: $!\n";
print MODIFIED "\n";
while (<LOG>) {
if (/OPERATIONS\s+BLOCKS\s+AVG\s+TIME/ || $_ eq "\n") {}
elsif (/TYP\s+NAME\s+READ\s+WRITE\s+READ\s+WRITE\s+READ\s+WRITE/) {print MODIFIED "Time\tType\tName\tOpsRd\tOpsWr\tBlksRd\tBlksWr\tAvgTimeRd\tAvgTimeWr\n"}
elsif (/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/) {
&use24HourFormat();
chomp();
s#.*(\d\d:\d\d:\d\d).*#$1#g;
$time = $_;
}
else {print MODIFIED "$time\t$_"}
}
close MODIFIED;
close LOG;
}
# Name: use24HourFormat
# Purpose: To modify a timestamp to 24-hour format.
# Parameters: String containing timestamp.
# Returns: -
sub use24HourFormat {
my $colon = ":"; # Timestamp delimiter
s#(\d\d):(\d\d):(\d\d)\s+AM#$1:$2:$3#g || s#(\d\d):(\d\d):(\d\d)\s+PM#($1+12).$colon.$2.$colon.$3#eg;
}
1;
#__END__
###########################################DOCUMENTATION###########################################
=head1
=head1 NAME
B<log2db>
=head1 SYNOPSIS
use log2db;
&modifyIostat($logPath, $tablePath); # iostat
&modifyNetstat($logPath, $tablePath); # netstat
&modifySlabinfo($logPath, $tablePath); # slabinfo
&modifySolstat($logPath, $tablePath); # mpstat, prstat
&modifySysstat($logPath, $tablePath); # pidstat, sar
&modifyTop($logPath, $tablePath); # top
&modifyTypeperf($logPath, $tablePath); # esxtop, typeperf
&modifyVmstat($logPath, $tablePath); # vmstat
&modifyVrstat($logPath, $tablePath); # vrstat
&modifyVvrstat($logPath, $tablePath); # vxmemstat, vxrlink, vxrvg
&modifyVxfsstatBCache($logPath, $tablePath); # vxfsstat_bcache
&modifyVxfsstatICache($logPath, $tablePath); # vxfsstat_icache
&modifyVxfsstatFile($logPath, $tablePath); # vxfsstat_file
&modifyVxrlinkE($logPath, $tablePath); # vxrlink_e
&modifyVxrlinkStatus($logPath, $tablePath); # vxrlink_status
&modifyVxstat($logPath, $tablePath); # vxstat
=head1 DESCRIPTION
B<log2db> is a utility to modify log files generated using esxtop, iostat, mpstat, netstat, pidstat, prstat, sar, slabinfo, typeperf, vmstat, vxfsstat, vxstat into text database that can be parsed by B<vxperf2>. B<log2db.pl> is the Perl wrapper around B<log2db> which can be run from the command-line or called from non-Perl scripts.
=head1 SUBROUTINES
The B<log2db> module contains sixteen subroutines: B<modifyIostat>, B<modifyNetstat>, B<modifySlabinfo>, B<modifySolstat>, B<modifySysstat>, B<modifyTop>, B<modifyTypeperf>, B<modifyVmstat>, B<modifyVrstat>, B<modifyVvrstat>, B<modifyVxfsstatBCache>, B<modifyVxfsstatICache>, B<modifyVxfsstatFile>, B<modifyVxrlinkE>, B<modifyVxrlinkStatus> and B<modifyVxstat>.
All of them take two parameters -- path to the log file to be modified and path to the table file to be saved as. They're all very trivial, basic, and "hardcoded". One golden rule for creating subroutines is that B<the table file should always start with a newline>.
=head1 AUTHOR
B<Sravan Bhamidipati> (Sravan_Bhamidipati@symantec.com, bsravanin@gmail.com)
=head1 CREDITS
Rajalaxmi Angadi contributed to the B<modifyVxfsstatBCache>, B<modifyVxfsstatICache>, B<modifyVxfsstatFile> and B<modifyVxstat> subroutines.
=head1 LICENSE AND COPYRIGHT
MIT License: http://www.opensource.org/licenses/mit-license.php
Symantec Corporation: http://www.symantec.com
=head1 LAST UPDATED
29th November, 2011
=cut