-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatit.ph
9916 lines (8815 loc) · 356 KB
/
formatit.ph
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
# copyright, 2003-20012 Hewlett-Packard Development Company, LP
#
# collectl may be copied only under the terms of either the Artistic License
# or the GNU General Public License, which may be found in the source kit
# local flags not needed/used by mainline. probably others in this category
my $printTermFirst=0;
# shared with main collectl
our %netSpeeds;
# these are only init'd when in 'record' mode, one of the reasons being that
# many of these variables may be different on the system on which the data
# is being played back on
sub initRecord
{
print "initRecord() - Subsys: $subsys\n" if $debug & 1;
initDay();
$rawPFlag=0; # always 0 when no files involved
# In some case, we need to know if we're root.
$rootFlag=`whoami`;
$rootFlag=($rootFlag=~/root/) ? 1 : 0;
# be sure to remove domain portion if present. also note we keep the hostname in
# two formats, one in it's unaltered form (at least needed by lustre directory
# parsing) as well as all lc because it displays nicer.
$Host=`hostname`;
chomp $Host;
$Host=(split(/\./, $Host))[0];
$HostLC=lc($Host);
# when was system booted?
$uptime=(split(/\s+/, `cat /proc/uptime`))[0];
$boottime=time-$uptime;
$Distro=cat('/etc/redhat-release') if -e '/etc/redhat-release';
chomp $Distro;
if (-e '/etc/redhat-release')
{
$Distro=cat('/etc/redhat-release');
chomp $Distro;
}
elsif (-e '/etc/SuSE-release')
{
my @temp=split(/\n/, cat('/etc/SuSE-release', 1));
$temp[2]=~/(\d+$)/; # patchlevel
$Distro="$temp[0] SP$1"; # append onto release string as SP
}
elsif (-e '/etc/debian_version')
{
# Both debian and ubuntu have 2 files
$Distro='debian '.cat('/etc/debian_version');
chomp $Distro;
# append distro to base release, if there
if (-e '/etc/lsb-release')
{
my $temp=cat('/etc/lsb-release',1);
$temp=~/DESCRIPTION=(.*)/;
$temp=$1;
$temp=~s/\"//g;
$Distro.=", $temp";
}
}
# For -sD calculations, we need the HZ of the system
$HZ=POSIX::sysconf(&POSIX::_SC_CLK_TCK);
$PageSize=POSIX::sysconf(_SC_PAGESIZE);
# If we have process IO everyone must. This was added in 2.6.23,
# but then only if someone builds the kernel with it enabled, though
# that, will probably change with future kernels.
$processIOFlag=(-e '/proc/self/io') ? 1 : 0;
$slabinfoFlag= (-e '/proc/slabinfo') ? 1 : 0;
$slubinfoFlag= (-e '/sys/slab') ? 1 : 0;
$processCtxFlag=($subsys=~/Z/ && `$Grep ctxt /proc/self/status` ne '') ? 1 : 0;
# just because slab structures there, are they readable? A chunk of extra work, but worth it.
if ($subsys=~/y/i && $slabinfoFlag || $slubinfoFlag)
{
$message='';
$message='/proc/slabinfo' if $slabinfoFlag && !(eval {`cat /proc/slabinfo 2>/dev/null` or die});
$message='/sys/slab' if $slubinfoFlag && !(eval {`cat /proc/slubinfo 2>/dev/null` or die});
if ($message ne '')
{
my $whoami=`whoami`;
chomp $whoami;
disableSubsys('y', "/proc/slabinfo is not readable by $whoami");
$interval=~s/(^\d*):\d+/$1:/ if $subsys!~/z/i; # remove int2 if not needed or we'll get error
}
}
# Get number of ACTIVE CPUs from /proc/stat and in case we're not running on a
# kernel that will set the CPU states (or let us change them), enable CPU flag
$NumCpus=`$Grep cpu /proc/stat | wc -l`;
$NumCpus=~/(\d+)/;
$NumCpus=$1-1;
for (my $i=0; $i<$NumCpus; $i++)
{
$cpuEnabled[$i]=1;
}
$cpusEnabled=$NumCpus;
# Now get the total number the system sees, and if different, reset the
# number as well as a flag for the header
$cpuDisabledFlag=0;
$cpuDisabledMsg='';
$cpusDisabled=0;
if (-e '/sys')
{
my $totalCpus=`ls /sys/devices/system/cpu/|$Grep '^cpu[0-9]'|wc -l`;
chomp $totalCpus;
if ($totalCpus!=$NumCpus)
{
$NumCpus=$totalCpus;
$cpusDisabled++; # for use in header
$cpuDisabledFlag=1;
# we really only have to worry about lower level details of WHO is disabled when
# doing cpu or interrupt stats. Furthermore, if doing cpu, the dynamic processing
# will figure out who's disabled but its too much overhead for interrupts alone so
# we'll do that here one time only. This may have to be do dynamically if a problem.
if ($subsys=~/j/i && $subsys!~/c/i)
{
# CPU0 always online AND no 'online' entry exists!
$cpusEnabled=1;
$cpuEnabled[0]=1;
for (my $i=1; $i<$NumCpus; $i++)
{
my $online=`cat /sys/devices/system/cpu/cpu$i/online`;
chomp $online;
$cpuEnabled[$i]=$online;
$cpusEnabled++ if $online;
$intrptTot[$i]=0;
}
}
}
}
$temp=`$Grep vendor_id /proc/cpuinfo`;
$CpuVendor=($temp=~/: (.*)/) ? $1 : '???';
$temp=`$Grep siblings /proc/cpuinfo`;
$CpuSiblings=($temp=~/: (\d+)/) ? $1 : 1; # if not there assume 1
$temp=`$Grep "cpu cores" /proc/cpuinfo`;
$CpuCores=($temp=~/: (\d+)/) ? $1 : 1; # if not there assume 1
$temp=`$Grep "cpu MHz" /proc/cpuinfo`;
$CpuMHz=($temp=~/: (.*)/) ? $1 : '???';
$Hyper=($CpuSiblings/$CpuCores==2) ? "[HYPER]" : "";
if (-e "/sys/devices/system/node")
{
$CpuNodes=`ls /sys/devices/system/node |$Grep '^node[0-9]'|wc -l`;
}
else
{
# if doesn't exist set nodes to 1 and disable '-sM' if specified
$CpuNodes=1;
disableSubsys('M', "/sys/devices/system/node doesn't exist", 1) if $subsys=~/M/;
}
chomp $CpuNodes;
# /proc read speed test, note various reasons to skip it
# These tests should be updated as we learn more about other distros
$ProcReadTest='no' if $NumCpus<32 || $Kernel lt '2.6.32';
$ProcReadTest='no' if $Distro=~/Red Hat.*release (\S+)/ && $1>=6.2;
$ProcReadTest='no' if $Distro=~/SUSE.*Server (\d+).*SP(\d+)/ && ($1!=11 || $2>=1);
if ($ProcReadTest=~/yes/i)
{
$procReadTested=1; # can call this routine twice!
my $strace=`strace -c cat /proc/stat 2>&1`;
$strace=~/^\s*\S+\s+(\S+).*read$/m;
my $speed=$1;
print "ProcReadSpeed: $speed\n" if $debug * 1;
if ($speed>0.01)
{
# may be going to a lot of effort here but I want to make sure these messages aren't
# recorded as errors and you don't have to include -m to see them as they are pretty
# important to the users to know about this.
my $line1="Slow /proc/stat read speed of $speed seconds";
my $line2="Consider a kernel patch/upgrade. See http://collectl.sourceforge.net/FAQ for more";
my $line3="Change 'ProcReadSpeed' in /etc/collectl.conf to suppress this message in the future";
if ($DaemonFlag)
{
logmsg('W', $line1);
logmsg('I', $line2);
logmsg('I', $line3);
}
else
{
print "$line1\n$line2\n$line3\n";
}
}
}
$Memory=`$Grep MemTotal /proc/meminfo`;
$Memory=(split(/\s+/, $Memory, 2))[1];
chomp $Memory;
$Swap=`$Grep SwapTotal /proc/meminfo`;
$Swap=(split(/\s+/, $Swap, 2))[1];
chomp $Swap;
# B u d d y i n f o
if ($subsys=~/b/i)
{
if (!open BUD, '</proc/buddyinfo')
{
disableSubsys('b', '/proc/buddyinfo does not exist');
}
else
{
$NumBud=0;
while (my $line=<BUD>)
{
$NumBud++
}
close BUD;
}
}
# D i s k C h e c k s
undef @dskOrder;
$dskIndexNext=0;
my @temp=`$Cat /proc/diskstats`;
foreach my $line (@temp)
{
next if $line!~/$DiskFilter/;
my @fields=split(/\s+/, $line);
my $diskName=$fields[3];
$diskName=remapDiskName($diskName) if $diskRemapFlag;
$diskName=~s/cciss\///;
push @dskOrder, $diskName;
$disks{$diskName}=$dskIndexNext++;
}
$dskSeenLast=$dskIndexNext;
logmsg("I", "initDisk initialized $dskIndexNext disks") if $debug & 1;
# I n o d e s
if ($subsys=~/i/)
{
$dentryFlag= (-e '/proc/sys/fs/dentry-state') ? 1 : 0;
$inodeFlag= (-e '/proc/sys/fs/inode-state') ? 1 : 0;
$filenrFlag= (-e '/proc/sys/fs/file-nr') ? 1 : 0;
if ($debug & 1)
{
print "/proc/sys/fs/dentry-state missing\n" if !$dentryFlag;
print "/proc/sys/fs/dentry-state missing\n" if !$inodeFlag;
print "/proc/sys/fs/dentry-state missing\n" if !$filenrFlag;
}
}
# I n t e r c o n n e c t C h e c k s
# Set IB speeds non-conditionally (even if not running IB) and then only for ofed.
# Furthermore assume if mulitple IB interfaces they're all the same speed.
$ibSpeed='??';
if (-e '/sys/class/infiniband')
{
$line=`cat /sys/class/infiniband/*/ports/1/rate 2>&1`;
if ($line=~/\s*(\d+)\s+(\S)/)
{
$ibSpeed=$1;
$ibSpeed*=1000 if $2 eq 'G';
}
}
# if doing interconnect, the first thing to do is see what interconnect
# hardware is present via lspci. Note that from the H/W database, we get
# the following IDS -Quadrics: 14fc, Myricom: 14c1, Mellanox (IB): 15b3
# OR 0c06, QLogic (IB): 1077
# we also have to make sure in the right position of output of lspci command
# so need to be a little clever
$NumXRails=$NumHCAs=0;
$myrinetFlag=$quadricsFlag=$mellanoxFlag=0;
if ($subsys=~/x/i)
{
my $lspciVer=`$Lspci --version`;
$lspciVer=~/ (\d+\.\d+)/;
$lspciVer=$1;
my $lspciVendorField=($lspciVer<2.2) ? 3 : 2;
# Turns out SuSE put 'Class' string back into V2.4.4 without changing
# version number in SLES 10. It also looks like they got it right in
# SLES 11, but who know what will happen in SLES 12!
$lspciVendorField=3 if $Distro=~/SUSE.*10/;
print "lspci -- Version: $lspciVer Vendor Field: $lspciVendorField\n"
if $debug & 1;
$command="$Lspci -n | $Egrep '15b3|0c06|14c1|14fc|1077'";
print "Command: $command\n" if $debug & 1;
@pci=`$command`;
foreach $temp (@pci)
{
# Save the type in case we ever need that level of discrimination.
($vendorID, $type)=split(/:/,(split(/\s+/, $temp))[$lspciVendorField]);
if ($vendorID eq '14c1')
{
printf "WARNING: found myrinet card but no collectl support\n";
}
if ($vendorID eq '14fc')
{
print "Found Quadrics Interconnect\n" if $debug & 2;
$quadricsFlag=1;
elanCheck();
}
if ($vendorID=~/15b3|0c06|1077/)
{
next if $type eq '5a46'; # ignore pci bridge
print "Found Infiniband Interconnect\n" if $debug & 1;
$mellanoxFlag=1;
$HCANames='';
ibCheck('');
}
}
disableSubsys('x', 'no interconnect hardware/drivers found')
if $myrinetFlag+$quadricsFlag+$mellanoxFlag==0;
# User had ability to turn off in case they don't want destructive monitoring
if ($mellanoxFlag)
{
$message='';
$message="Open Fabric IB Stats disabled in $configFile" if -e $SysIB && $PQuery eq '';
$message="Voltaire IB Stats disabled in $configFile" if !-e $SysIB && $PCounter eq '';
if ($message ne '')
{
logmsg("W", $message);
$xFlag=$XFlag=0;
$subsys=~s/x//ig;
$mellanoxFlag=0;
}
if ($mellanoxFlag)
{
# The way forward is clearly OFED
if (-e $SysIB)
{
# This block's job is to make sure perfquery is there
{
print "Looking for 'perfquery' and 'ofed_info'\n" if $debug & 2;
$PQuery=getOfedPath($PQuery, 'perfquery', 'PQuery');
if ($PQuery eq '')
{
disableSubsys('x', "couldn't find perfquery!");
$mellanoxFlag=0;
last;
}
# I hate support questions and this is the place to catch perfquery problems!
# so, if perfquery IS there, since it generates warnings on stderr in V1.5 and
# we don't know the version yet, always ignore them
if ($mellanoxFlag)
{
my $message='';
my $temp=`$PQuery 2>/dev/null`;
$message="Permission denied" if $temp=~/Permission denied/;
$message="Failed to open IB device" if $temp=~/Failed to open/;
$message="Required module missing" if $temp=~/required by/;
$message="No such file or directory" if $temp=~/No such file/;
if ($message ne '')
{
disableSubsys('x', "perfquery error: $message!");
$mellanoxFlag=0;
$PQuery='';
last;
}
}
# perfquery IS there and we can execute it w/o error...
# Can you believe it? PQuery writes its version output to stderr!
$temp=`$PQuery -V 2>&1`;
$temp=~/VERSION: (\d+\.\d+\.\d+)/;
$PQVersion=$1;
}
# perfquery there, but what is ofed's version?
# NOTE - looks like RedHat is no longer shipping ofed
if ($PQuery ne '')
{
if (!-e $OfedInfo)
{
$OfedInfo=getOfedPath($OfedInfo, 'ofed_info', 'OfedInfo');
logmsg('W', "Couldn't find 'ofed_info'. Won't be able to determine OFED version")
if $OfedInfo eq '';
}
# Unfortunately the ofed_info that ships with voltaire adds 5 extra
# line at front end so let's look at first 10 lines for version.
$IBVersion=($OfedInfo ne '' && `$OfedInfo|head -n10`=~/OFED-(.*)/) ? $1 : '???';
print "OFED V: $IBVersion PQ V:$PQVersion\n" if $debug & 2;
}
}
else
{
$IBVersion=(`head -n1 $VoltaireStats`=~/ibstat\s+(.*)/) ? $1 : '???';
print "Voltaire IB V$IBVersion\n" if $debug & 2;
}
}
}
# One last check and this is a doozie! Because we read IB counters by doing
# a read/clear everytime, multiple copies of collectl will step on each other.
# Therefore we can only allow one instance to actually monitor the IB and the
# first one wins, unless we're trying to start a daemon in which case we let
# step on the other [hopefully temporary] instance. Since there are odd cases
# where it may not always catch exception, one can override checking in .conf
if ($IbDupCheckFlag && $mellanoxFlag)
{
my $myppid=getppid();
$command="$Ps axo pid,cmd | $Grep collectl | $Grep -vE 'grep|ssh'";
foreach my $line (`$command`)
{
$line=~s/^\s+//; # some pids have leading white space
my ($pid, $procCmd)=split(/ /, $line, 2);
next if $pid==$$ || $pid==$myppid; # check ppid in case started by a script
# There are just too many ways one can specify the subsystems whether it's
# overriding the DaemonCommands or SubsysCore in collectl.conf, using an
# alternate collectl.conf or specifying --subsys instead of -s and I'm
# just not going to go there [for now] as it's complicated enough, hence
# '$IbDupCheckFlag'
# If not running as a daemon, '$procCmd' has the command invocation string
# from the 'ps' above. If a daemon, we need to pull it out of collectl.cont.
my $tempDaemonFlag=($procCmd=~/-D/) ? 1 : 0;
if ($tempDaemonFlag)
{
# This is getting even uglier, but if someone chose to duplicate
# 'DaemonCommands' and comment one out, we really need to look for
# the last uncommented one.
foreach my $cmd (`$Grep 'DaemonCommands =' $configFile`)
{
next if $cmd=~/^#/;
$procCmd=$cmd;
}
}
# Now that we have the full command passed to collectl, pull out -s (if any)
# which may be surrounded by optional white space.
chomp $procCmd;
$procSubsys=($procCmd=~/-s\s*(\S+)\s*/) ? $1 : '';
# The default subsys is different for daemon and interactive use
# if no -s, we use default and if there, assume we're overriding
$tempSubsys=($tempDaemonFlag) ? $SubsysDefDaemon : $SubsysDefInt;
# So now we need to figure out what actual subsystems are in use
# by that instance in case it was started with either +/- OR
# a fixed set
if ($procSubsys=~/^[\+\-]/)
{
# the stolen from main collectl switch validation code noting
# we don't need to validate the switches since done when
# daemon started
if ($procSubsys=~/-(.*)/)
{
my $pat=$1;
$pat=~s/\+.*//; # if followed by '+' string
$tempSubsys=~s/[$pat]//g;
}
if ($procSubsys=~/\+(.*)/)
{
my $pat=$1;
$pat=~s/-.*//; # if followed by '-' string
$tempSubsys.=$pat;
}
}
elsif ($procSubsys ne '')
{
$tempSubsys=$procSubsys;
}
# At this point if there IS an instance of collectl running with -sx,
# we need to disable it here, unless we're a daemon in which case we
# just log a warning.
if ($tempSubsys=~/x/i)
{
if (!$daemonFlag)
{
disableSubsys('x', 'another instance already monitoring Infiniband');
}
else
{
logmsg("W", "another instance is monitoring IB and the stats will be in error until it is stopped");
}
last;
}
}
}
}
# Let's always get the platform name if dmidecode is there
if ($Dmidecode ne '')
{
$ProductName=($rootFlag) ? `$Dmidecode | grep -m1 'Product Name'` : '';
$ProductName=~s/\s*Product Name: //;
chomp $ProductName;
$ProductName=~s/\s*$//; # some have trailing whitespace
}
# E n v i r o n m e n t a l C h e c k s
if ($subsys=~/E/ && $envTestFile eq '')
{
# Note that these tests are in the reverse order since the last value of $message
# in the one reported AND only if not using a 'test' file for data source.
my $message='';
$message="'IpmiCache' not defined or specifies a directory"
if $IpmiCache eq '' || -d $IpmiCache;
$message="cannot find /dev/ipmi* (is impi_si loaded?)"
if !-e '/dev/ipmi0' && !-e '/dev/ipmi/0' && !-e '/dev/ipmidev/0';
$message="cannot find 'ipmitool' in '$ipmitoolPath'"
if $Ipmitool eq '';
$message="you must be 'root' to do environmental monitoring"
if !$rootFlag;
if ($message eq '')
{
# If specified by --envopts, set -d for ipmitool
$Ipmitool.=" -d $1" if $envOpts=~/(\d+)/;
logmsg('I', "Initialized ipmitool cache file '$IpmiCache'");
my $command="$Ipmitool sdr dump $IpmiCache";
# If we can't dump the cache, something is wrong so make sure we pass along
# error and disable E monitoring. Ok to create 'exec' below since we'll
# never execute it
$message=`$command 2>&1`;
if ($message=~/^Dumping/)
{
# Create 'exec' option file in save directory as cache, but only for
# those options that actually return data
my $cacheDir=dirname($IpmiCache);
$ipmiExec="$cacheDir/collectl-ipmiexec";
if (open EXEC, ">$ipmiExec")
{
$message=''; # indicates no errors for test below
foreach my $type (split(/,/, $IpmiTypes))
{
my $command="$Ipmitool -S $IpmiCache sdr type $type";
next if `$command` eq '';
print EXEC "sdr type $type\n";
}
close EXEC;
}
else
{
$message="couldn't create '$ipmiExec'";
}
}
}
disableSubsys('E', $message) if $message ne '';
}
# find all the networks and when possible include their speeds
undef @temp;
$netIndexNext=0;
$NetWidth=$netOptsW; # Minimum size
$null=($debug & 1) ? '' : '2>/dev/null';
my $interval1=(split(/:/, $interval))[0];
# but first look up all the network speed in /sys/devices and load them into a hash
# for easier access in the loop below
my $command="find /sys/devices/ 2>&1 | grep net | grep speed";
open FIND, "$command|" or logmsg('E', "couldn't execute '$command'");
while (my $line=<FIND>)
{
chomp $line;
my $mode=$line;
$mode=~s/speed/operstate/;
$mode=`cat $mode`;
next if $mode!~/up|unknown/;
my $speed=`cat $line 2>&1`;
chomp $speed;
$line=~/.*\/(\S+)\/speed/;
my $netName=$1;
$speed='??' if $netName=~/^vnet/; # hardcoded in kernel to 10 which causes bogus msgs later
$netSpeeds{$netName}=$speed if $speed!~/Invalid/; # this can happen on a VM where operstate IS up
#print "set netSpeeds{$netName}=$speed\n";
}
close FIND;
# Since this routine can get called multiple times during
# initialization, we need to make sure @netOrder gets clean start.
undef @netOrder;
@temp=`$Grep -v -E "Inter|face" /proc/net/dev`;
foreach my $temp (@temp)
{
next if $rawNetFilter ne '' && $temp!~/$rawNetFilter/;
$temp=~/^\s*(\S+)/; # most names have leading whitespace
$netName=$1;
$netName=~s/:.*//; # get rid of : AND possible stats if no whitespace
$NetWidth=length($netName) if length($netName)>$NetWidth;
$speed=($netName=~/^ib/) ? $ibSpeed : $netSpeeds{$netName};
$speed='??' if !defined($speed);
push @netOrder, $netName;
$netIndex=$netIndexNext;
$networks{$netName}=$netIndexNext++;
# Since speeds are in Mb we really need to multiple by 125 to conver to KB
$NetMaxTraffic[$netIndex]=($speed ne '' && $speed ne '??') ?
2*$interval1*$speed*125 : 2*$interval1*$DefNetSpeed*125;
}
$netSeenLast=$netIndexNext;
$NetWidth++; # make room for trailing colon
# S C S I C h e c k s
# not entirely sure what to do with SCSI info, but if feels like a good
# thing to have. also, if no scsi present deal accordingly
undef @temp;
$ScsiInfo='';
if (-e "/proc/scsi/scsi")
{
@temp=`$Grep -E "Host|Type" /proc/scsi/scsi`;
foreach $temp (@temp)
{
if ($temp=~/^Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/)
{
$scsiHost=$1;
$channel=$2;
$id=$3;
$lun=$4;
}
if ($temp=~/Type:\s+(\S+)/)
{
$scsiType=$1;
$type="??";
$type="SC" if $scsiType=~/scanner/i;
$type="DA" if $scsiType=~/Direct-Access/i;
$type="SA" if $scsiType=~/Sequential-Access/i;
$type="CD" if $scsiType=~/CD-ROM/i;
$type="PR" if $scsiType=~/Processor/i;
$ScsiInfo.="$type:$scsiHost:$channel:$id:$lun ";
}
}
$ScsiInfo=~s/ $//;
}
# L u s t r e C h e c k s
$CltFlag=$MdsFlag=$OstFlag=0;
$NumLustreFS=$numBrwBuckets=0;
if ($subsys=~/l/i)
{
if ((`ls /lib/modules/*/kernel/net/lustre 2>/dev/null|wc -l`==0) &&
(`ls /lib/modules/*/*/kernel/net/lustre 2>/dev/null|wc -l`==0))
{
disableSubsys('l', 'this system does not have lustre modules installed');
}
else
{
# Get Luster and SFS Versions before looking at any data structions in the
# 'lustreCheck' routines because things change over time
$temp=`$Lctl lustre_build_version 2>/dev/null`;
$temp=~/version: (.+?)-/m;
$cfsVersion=$1;
$sfsVersion='';
if (-e '/etc/sfs-release')
{
$temp=cat('/etc/sfs-release');
$temp=~/(\d.*)/;
$sfsVersion=$1;
}
elsif (-e "/usr/sbin/sfsmount" && -e $Rpm)
{
# XC and client enabler
$llite=`$Rpm -qa | $Grep lustre-client`;
$llite=~/lustre-client-(.*)/;
$sfsVersion=$1;
}
$OstWidth=$FSWidth=0;
$NumMds=$NumOst=0;
$MdsNames=$OstNames=$lustreCltInfo='';
$inactiveOstFlag=0;
lustreCheckClt();
lustreCheckMds();
lustreCheckOst();
print "Lustre -- CltFlag: $CltFlag NumMds: $NumMds NumOst: $NumOst\n"
if $debug & 8;
disableSubsys('l', "no lustre services running and I don't know its type. You will need to use --lustsvc to force type.")
if $CltFlag+$NumMds+$NumOst==0 && $lustreSvcs eq '';
# Global to count how many buckets there are for brw_stats
@brwBuckets=(1,2,4,8,16,32,64,128,256);
push @brwBuckets, (512,1024) if $sfsVersion ge '2.2';
$numBrwBuckets=scalar(@brwBuckets);
# if we're doing lustre DISK stats, figure out what kinds of disks
# and then build up a list of them for collection to use. To keep switch
# error processing clean, only try to open the file if an MDS or OSS.
# Since services may not be up, we also need to look at '$lustreSvcs',
# though ultimately we'll only set the disk types and the maximum buckets
if ($subsys=~/l/i && $lustOpts=~/D/ && ($MdsFlag || $OstFlag || $lustreSvcs=~/[mo]/i))
{
# The first step is to build up a hash of the sizes of all the
# existing partitions. Since we're only doing this once, a 'cat's
# overhead should be minimal
@partitions=`cat /proc/partitions`;
foreach $part (@partitions)
{
# ignore blank lines and header
next if $part=~/^\s*$|^major/;
# now for the magic. Get the partition size and name, but ignore
# cciss devices on controller 0 OR any devices with partitions
# noting cciss device partitions end in 'p-digit' and sd partitions
# always end in a digit.
($size, $name)=(split(/\s+/, $part))[3,4];
$name=~s/cciss\///;
next if $name=~/^c0|^c.*p\d$|^sd.*\d$/;
$partitionSize{$name}=$size;
}
# Determine which directory to look in based on whether or not there
# is an EVA present. If so, we look at 'sd' stats; otherwize 'cciss'
$LusDiskNames='';
$LusDiskDir=(-e '/proc/scsi/sd_iostats') ?
'/proc/scsi/sd_iostats' : '/proc/driver/cciss/cciss_iostats';
# Now find all the stat files, noting that in the case of cciss, we
# always skip c0 disks since they're local ones... Also note that
# if we're doing a showHeader with -Lm or -Lo on a client, the file
# isn't there AND we don't want to report an error either.
$openFlag=(opendir(DIR, $LusDiskDir)) ? 1 : 0;
logmsg('F', "Disk stats requested but couldn't open '$LusDiskDir'")
if !$openFlag && !$showHeaderFlag;
while ($diskname=readdir(DIR))
{
next if $diskname=~/^\.|^c0/;
# if this has a partition within the range of a service lun,
# ignore it.
if ($partitionSize{$diskname}/(1024*1024)<$LustreSvcLunMax)
{
print "Ignoring $diskname because its size of ".
"$partitionSize{$diskname} is less than ${LustreSvcLunMax}GB\n"
if $debug & 1;
next;
}
push @LusDiskNames, $diskname;
$LusDiskNames.="$diskname ";
}
$LusDiskNames=~s/ $//;
$NumLusDisks=scalar(@LusDiskNames);
$LusMaxIndex=($LusDiskNames=~/sd/) ? 16 : 24;
}
}
}
# S L A B C h e c k s
# Header for /proc/slabinfo changed in 2.6
if ($slabinfoFlag && $subsys=~/y/i)
{
$SlabGetProc=($slabFilt eq '') ? 99 : 14;
$temp=`head -n 1 /proc/slabinfo`;
$temp=~/(\d+\.\d+)/;
$SlabVersion=$1;
$NumSlabs=`cat /proc/slabinfo | wc -l`*1;
chomp $NumSlabs;
$NumSlabs-=2;
if ($SlabVersion!~/^1\.1|^2/)
{
# since 'W' will echo on terminal, we only use when writing to files
$severity=(defined($opt_s)) ? "E" : "I";
$severity="W" if $logToFileFlag;
logmsg($severity, "unsupported /proc/slabinfo version: $SlabVersion");
$subsys=~s/y//gi;
$yFlag=$YFlag=0;
}
}
}
# Why is initFormat() so damn big?
#
# Since logs can be analyzed on a system on which they were not generated
# and to avoid having to read the actual data to determine things like how
# many cpus or disks there are, this info is written into the log file
# header. initFormat() then reads this out of the head and initialized the
# corresponding variables.
#
# Counters are always incrementing (until they wrap) and therefore to get the
# value for the current interval one needs decrement it by the sample from
# the previous interval. Therefore, theere are 3 different types of
# variables to deal with:
# - current sample: some 'root', ends in 'Now'
# - last sample: some 'root', end in 'Last'
# - true value: 'root' only - rootNow-rootLast
#
# To make all this work the very first time through, all 'Last' variables
# need to be initialized to 0 both to suppress -w initialization warnings AND
# because it's good coding practice. Furthermore, life is a lot cleaner just
# to initialize everything whether we've selected the corresponding subsystem
# or not. Furthermore, since it is possible to select a subsystem in plot
# mode for which we never gathered any data, we need to initialize all the
# printable values to 0s as well. That's why there is so much crap in
# initFormat().
sub initFormat
{
my $playfile=shift;
my ($day, $mon, $year, $i, $recsys, $host);
my ($version, $datestamp, $timestamp, $interval);
$temp=(defined($playfile)) ? $playfile : '';
print "initFormat($temp)\n" if $debug & 1;
# Constants local to formatting
$OneKB=1024;
$OneMB=1024*1024;
$OneGB=1024*1024*1024;
$TenGB=$OneGB*10;
# in normal mode we report "/sec", but with -on we report "/int", noting
# this is also appended to plot format headers
$rate=$options!~/n/ ? "/sec" : "/int";
if (defined($playfile))
{
$header=getHeader($playfile);
return undef if $header eq '';
# save the first two lines of the header for writing into the new header.
# since the Deamon Options have been renamed in V1.5.3 we need to get a
# little trickier to handle both. Since they are so specific I'm leaving
# them global.
$header=~/(Collectl.*)/;
$recHdr1=$1;
$recHdr2=(($header=~/(Daemon Options: )(.*)/ || $header=~/(DaemonOpts: )(.*)/) && $2 ne '') ? "$1$2" : "";
$header=~/Collectl:\s+V(\S+)/;
$version=$1;
$hiResFlag=$1 if $header=~/HiRes:\s+(\d+)/; # only after V1.5.3
$boottime=($header=~/Booted:\s+(\S+)/) ? $1 : 0;
$Distro='';
if ($header=~/Distro:\s+(.+)/) # was optional before 'Platform' added
{
$Distro=$1;
$ProductName=$1 if $Distro=~s/Platform: (.*)//;
}
# Prior to collect V3.2.1-4, use the header to determine the type of nfs data in the
# file noting very old versions used SubOpts.
$recNfsFilt=$1 if $header=~/NfsFilt: (\S*) \S/;
$subOpts=($header=~/SubOpts:\s+(\S*)\s*Options/) ? $1 : ''; # pre V3.2.1-4
if ($version lt '3.2.1-4')
{
$nfsOpts=($header=~/NfsOpts: (\S*)\s*Interval/) ? $1 : $subOpts;
$nfsOpts=~s/[BDMORcom]//g; # in case it came from SubOpts remove lustre stuff
if ($version lt '3.2.1-3')
{
$recNfsFilt=($nfsOpts=~/C/) ? 'c' : 's';
$recNfsFilt.=($nfsOpts=~/([234])/) ? $1 : 3;
}
else
{
# very limited release
$recNfsFilt=($nfsOpts=~/C/) ? 'c3,c4' : 's3,s4';
}
}
if ($header=~/TcpFilt:\s+(\S+)/)
{
# remember, even if an option is not recorded we still report on it
my $recOpts=(defined($1)) ? $1 : $tcpFiltDefault;
$tcpFilt=$recOpts if $tcpFilt eq '';
}
# Users CAN overrider LustOpts so we need to do it this way, again accounting for
# older versions of collectl storing them as part of SubOpts
if ($lustOpts eq '')
{
$lustOpts=($header=~/LustOpts: (\S*)\s*Services/) ? $1 : $subOpts;
$lustOpts=~s/[23C]//g; # remove nfs options
}
# we want to preserve original subsys from the header, but we
# also want to override it if user did a -s. If user specified a
# +/- we also need to deal with as in collectl.pl, but in this
# case without the error checking since it already passed through.
# NOTE - rare, but if not subsys, set to ' ' also noting '' won't work
# in regx in collectl after call to this routine
$header=~/SubSys:\s+(\S*) /;
$recSubsys=$subsys=($1!~/Options/) ? $1 : ' ';
$recHdr1.=" Subsys: $subsys";
$recSubsys=$subsys='Y' if $topSlabFlag && $userSubsys eq '';
$recSubsys=$subsys='Z' if $topProcFlag && $userSubsys eq '';
# reset subsys based on what was recorded and -s
$subsys=mergeSubsys($recSubsys);
$subsys.='Y' if $subsys!~/Y/ && $topSlabFlag; # if --top need to include Y or Z if not in -s
$subsys.='Z' if $subsys!~/Z/ && $topProcFlag;
# I'm not sure the Mds/Ost/Clt names still need to be initialized
# but it can't hurt. Clearly the 'lustre' variables do.
$MdsNames=$OstNames=$lustreClts='';
$lustreMdss=$lustreOsts=$lustreClts='';
# This can only happen with pre 3.0.0 version of collectl
if ($subsys=~/LL/)
{
$subsys=~s//L/;
$lustOpts.='O';
}
# We ONLY override the settings for the raw file, never any others.
# Even though currently only 'rawp' files, we're doing pattern match below
# with [p] to make easier to add others if we ever need to.
$playfile=~/(.*-\d{8})-\d{6}\.raw([p]*)/;
if (defined($playbackSettings{$1}) && $2 eq '')
{
# NOTE - when -L not specified for lustre, $lustreSvcs will end up being
# set to the combined values of all files for this prefix
($subsys, $lustreSvcs, $lustreMdss, $lustreOsts, $lustreClts)=
split(/\|/, $playbackSettings{$1});
print "OVERRIDES - Subsys: $subsys LustreSvc: $lustreSvcs ".
"MDSs: $lustreMdss Osts: $lustreOsts Clts: $lustreClts\n"
if $debug & 2048;
}
print "Playfile: $playfile Subsys: $subsys\n" if $debug & 1;
setFlags($subsys);
# In case not in current file header but defined within set for prefix/date
$CltFlag=$MdsFlag=$OstFlag=$NumMds=$NumOst=$OstWidth=$FSWidth=0;
$MdsNames=$lustreMdss if $lustreMdss ne '';
$OstNames=$lustreOsts if $lustreOsts ne '';
# Maybe some day we can get rid of pre 1.5.0 support?
$numBrwBuckets=0;
if ($header=~/Lustre/ && $version ge '1.5.0')
{
# Remember, we could have cfs without sfs so need 2 separate pattern tests
$cfsVersion=$sfsVersion='';
if ($version ge '2.1')
{
$header=~/CfsVersion:\s+(\S+)/;
$cfsVersion=$1;
$header=~/SfsVersion:\s+(\S+)/;
$sfsVersion=$1;
}
# In case not already defined (for single or consistent files, these are
# not specified as overrides), get them from the file header. Note that
# when no osts, this will grab the next line it I include \s* after
# OstNames:, so for now I'm doing it this way and chopping leading space.
$MdsHdrNames=$OstHdrNames='';
if ($header=~/MdsNames:\s+(.*)\s*NumOst:\s+\d+\s+OstNames:(.*)$/m)
{
$MdsHdrNames=$1;
$OstHdrNames=$2;
$OstHdrNames=~s/\s+//;
$MdsNames=($lustreMdss ne '') ? $lustreMdss : $MdsHdrNames;
$OstNames=($lustreOsts ne '') ? $lustreOsts : $OstHdrNames;
}
if ($MdsNames ne '')
{
@MdsMap=remapLustreNames($MdsHdrNames, $MdsNames, 0) if $MdsHdrNames ne '';
foreach $name (split(/ /, $MdsNames))
{
$NumMds++;
$MdsFlag=1;
}
}
if ($OstNames ne '')
{
# This build list for interpretting input from 'raw' file if there is any
@OstMap=remapLustreNames($OstHdrNames, $OstNames, 0) if $OstHdrNames ne '';
# This builds data needed for display