-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqstat+
executable file
·2788 lines (2777 loc) · 77 KB
/
qstat+
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
#!/usr/bin/perl -w
#
# <- Last updated: Mon Jul 1 13:20:31 2024 -> SGK
#
# PERL script to parse output of SGE's qstat
# uses qstat's -xlm output
#
use strict;
#
my $VERSION = 'qstat+: Ver 5.5/2 - Jun 2024';
#
# ------------------------------------------------------------------------
#
# list of nodes: head node, login nodes, NSDs
#
my @logNames = qw/hydra-7 login01 login02 login04 login07/;
my @nsdNames = qw/nsd01 nsd02/;
my $nodePrfx = 'compute-';
#
# list of queues to show - all.q is ignored
#
my @queueSet = ('sThC.q', 'mThC.q', 'lThC.q', 'uThC.q', '',
'sThM.q', 'mThM.q', 'lThM.q', 'uThM.q', '',
'uTxlM.rq', '',
'lTIO.sq', '',
'sTgpu.q','mTgpu.q', 'lTgpu.q', '',
'qgpu.iq', 'qrsh.iq',
);
#
# queue to ignore, this can be a RE since it is used as if ($queue !~ /$ignQueue/)
my $ignQueue = 'all.q';
#
# type of GE implementation: SGE or UGE/AGE
#
my $geType = 'sge';
my $qstat = "qstat";
if (defined $ENV{SGE_ROOT}) {
$qstat = "$ENV{SGE_ROOT}/bin/$ENV{SGE_ARCH}/$qstat";
if ($ENV{SGE_ROOT} =~ /\/uge\//) {
$geType = 'uge';
}
} else {
$geType = 'uge';
}
#
# use ruptime or ssh $host uptime?
#
my $uptimeCommand = '/usr/bin/ruptime -n=25';
# my $uptimeCommand = 'uptime';
#
# ------------------------------------------------------------------------
#
# what to show
#
my %show = ('running' => 0,
'queued' => 0,
'others' => 0,
'header' => 1,
'footer' => 1,
'age' => 0,
'cpu' => 0,
'user' => 1,
'mem' => 0,
'load' => 0,
'u/a' => 0,
'start' => 0,
'io' => 0,
'iow' => 0,
'ioops' => 0,
'license' => 1,
'ineff' => 0,
'osub' => 0,
'raw' => 0,
'warn' => 0,
'sfmt' => 0 );
#
# options
#
my %option = ('fake' => 0,
'cntPE' => 0,
'mode' => 'userlist',
'verbose' => 0,
'wide' => 0,
'sort' => 'jid',
'esx' => 0,
'notty' => 0,
'user' => "'*'",
'ineffT' => 33,
'osubT' => 133,
'osubE' => 0,
'oresF' => 2.5,
'ageT' => 1,
'uptime' => $uptimeCommand,
'limit' => '');
# args
my %args = (
# modes
'-s' => 'o:mode=summary',
'-sx' => 'o:mode=summary,s:sfmt=1',
'-sc' => 'o:mode=summary,s:sfmt=2',
'-a' => 'o:mode=showa',
'-q' => 'o:mode=showq',
'-r' => 'o:mode=showr',
'-X' => 'o:mode=showX',
'-j' => 'o:mode=jid,o:jidList=NEXT',
'-gc' => 'o:mode=gc',
'-es' => 'o:mode=es',
'-esx' => 'o:mode=es,o:esx=1',
'-osub' => 'o:mode=showr,s:osub=1,s:cpu=2,s:age=1,s:header=1,s:footer=0,o:user=$USER',
'-ineff' => 'o:mode=showr,s:ineff=1,s:cpu=2,s:age=1,s:header=1,s:footer=0,o:user=$USER',
'-ores' => 'o:mode=showr,s:ores=1,s:mem=3,s:cpu=2,s:age=1,s:header=1,s:footer=0,o:user=$USER',
'-oresF' => 'o:oresF=NEXT',
'-osubT' => 'o:osubT=NEXT',
'-osubE' => 'o:osubE=NEXT',
'-ineffT' => 'o:ineffT=NEXT',
'-ageT' => 'o:ageT=NEXT',
'-nlist' => 'o:mode=nodelist,o:jidList=NEXT',
'-hiload' => 'o:mode=hiload,o:offset=NEXT',
'-down' => 'o:mode=down',
'-ssd' => 'o:mode=ssd',
'-h' => 'o:mode=help',
'-help' => 'o:mode=help',
'--help' => 'o:mode=help',
'-examples' => 'o:mode=examples',
# options
'-v' => 'o:verbose=1',
'-verbose' => 'o:verbose=1',
'-warn' => 's:warn=1',
'-u' => 'o:user=NEXT',
'-queue' => 'o:queue=NEXT',
'-wide' => 'o:wide=1',
'-notty' => 'o:notty=1',
'-npes' => 'o:cntPE=1',
'-nqpe' => 'o:cntPE=2',
'-nqxx' => 'o:cntPE=4',
'-njobs' => 'o:cntPE=-1',
'-check-load' => 'o:check-load=1',
# show
'-load' => 's:load=1',
'-sua' => 's:u/a=1',
'+lic' => 's:license=1',
'-lic' => 's:license=0',
'-age' => 's:age=1',
'-cpu' => 's:cpu=1',
'-cpu%' => 's:cpu=2',
'-cpur' => 's:cpu=3',
'-io' => 's:io=1',
'-iow' => 's:iow=1',
'-ioops' => 's:ioops=1',
'-mem' => 's:mem=1',
'-memx' => 's:mem=2',
'-memr' => 's:mem=3',
'-noheader' => 's:header=0',
'-nofooter' => 's:footer=0',
'-raw' => 's:raw=1',
# shorthands
'+a' => 'x:-a -u $USER -nofooter',
'+a%' => 'x:-a -u $USER -nofooter -age -cpu%',
'+ax%' => 'x:-a -u $USER -nofooter -age -cpu% -load -sua -mem -io',
'+ar%' => 'x:-a -u $USER -nofooter -age -cpu% -memr -io',
'+r' => 'x:-r -u $USER -nofooter',
'+r%' => 'x:-r -u $USER -nofooter -age -cpu%',
'+rx%' => 'x:-r -u $USER -nofooter -age -cpu% -load -sua -memx -io -iow -ioops',
'+rr%' => 'x:-r -u $USER -nofooter -age -cpu% -memr -io -iow -ioops',
'+q' => 'x:-q -u $USER -nofooter',
'+q%' => 'x:-q -u $USER -nofooter -age',
'+qx%' => 'x:-q -u $USER -nofooter -age -mem ',
'+X' => 'x:-X -u $USER -nofooter',
'+n' => 'x:-notty -wide -noheader -nofooter',
# debug using files/fake, comment it out for production
'-debug' => 'o:fake=NEXT',
'-geType' => 'o:geType=NEXT',
);
#
my @ERRMSG = ('use qstat+ -help to get usage',
' qstat+ -examples to see examples', '',
$VERSION,
'');
#
my @HELP = ('usage: qstat+ [mode] [options]',
' where modes are (exclusive list):',
' -s|-sx|-sc show summary (simple, extended or compact)',
' -a show all jobs',
' -q show queued jobs',
' -r show running jobs',
' -X show extra jobs (dr, Eqw, t)',
' -j JID show info on a specific (set of) job(s)',
' -nlist JID show node list for a (set of) job(s)',
' use job.task to specify a task number, list of JIDs must be comma separated',
' -hiload N show node(s) with high load',
' -gc show global cluster status',
' -es[x] show empty slots, -esx: expanded info',
' -down show node(s) that are down',
' -ores show overreserved jobs, i.e.: resMem/maxVMem > '.$option{'oresF'}.', & age > '.$option{'ageT'}.' hr',
' -osub show oversubscribed jobs, i.e.: cpu% > '.$option{'osubT'}.'%, & age > '.$option{'ageT'}.' hr',
' -ineff show inefficient jobs, i.e.: cpu% < '.$option{'ineffT'}.'%, & age > '.$option{'ageT'}.' hr',
' -ssd show SSD usage',
' -h|-help--help show help',
' -examples show examples',
'',
'where options are:',
' -u USER limit to the specified user, you can use "*" or "all" to list everybody\'s jobs',
' or a coma-separated list',
' -njobs show counts in no. of jobs',
' -npes show counts in no. of PEs (slots)',
' -nqpe show jobs/PEs not jobs/tasks for queued jobs',
' -nqxx show jobs/tasks/PEs for queued jobs',
' -load show the nodes\' load',
' -sua show the nodes\' used/avail no of slots',
' -age show the age of the jobs, i.e., elapsed time vs starting/submit time',
' -cpu show the amount of CPU used by running job(s)',
' -cpu% show the amount of CPU/age/#PE in % (job efficiency)',
' -cpur show the ratio CPU/AGE, not scaled by #PE',
' -mem show the mean memory usage for running jobs, the total requested memory for queued jobs, in GB',
' -memx show more memory info for running jobs: reserved, mean, vmem and maxvmem (slow)',
' -memr show more memory info for running jobs: reserved, mean, maxvmem and res/mxvmem (slow)',
' -io show the I/O usage',
' -iow show the I/O wait usage (slow)',
' -ioops show the IOPs usage (slow)',
' +lic show license info (default), although not in detailed outputs',
' -lic do not show license info',
'',
' -noheader do not show the header',
' -nofooter do not show the footer',
' -raw print raw values (for easier parsing)',
' -queue QSPEC limit to jobs in queue QSPEC (RE ok)',
' -oresF VAL change the overreserved factor to VAL',
' -osubT VAL change the oversubscribed threshold to VAL, in %',
' -osubE VAL set the oversubscribtion excess threshold to VAL, in hr x slots',
' -ineffT VAL change the inefficient threshold to VAL, in %',
' -ageT VAL change the minimum age threshold to VAL, in hour',
'',
' -v|-verbose set verbose mode',
' -warn show warnings',
' -wide wide output (132 cols, implies -notty)',
' -notty do not use the width of the terminal, as returned by stty',
' -check-load check the instantanous load (-hiload only)',
'',
'shorthands:',
' +a is expanded to -a -u $USER -nofooter show all your jobs',
' +a% -a -u $USER -nofooter -age -cpu% ibidem, with cpu on % of age',
' +ax% -a -u $USER -nofooter -age -cpu% -load -sua -mem -io',
' +ar% -a -u $USER -nofooter -age -cpu% -memr -io',
' +r -r -u $USER -nofooter show all your running jobs',
' +r% -r -u $USER -nofooter -age -cpu% ibidem, with cpu on % of age',
' +rr% -r -u $USER -nofooter -age -cpu% -memr -io -iow -ioops',
' +rx% -r -u $USER -nofooter -age -cpu% -load -sua -memx -io -iow -ioops',
' +q -q -u $USER -nofooter show all your queued jobs',
' +q% -q -u $USER -nofooter -age ibidem but show age',
' +qx% -q -u $USER -nofooter -age -mem ibidem plus mem info',
' +X -X -u $USER -nofooter show all your extra jobs',
' +n -notty -wide -noheader -nofooter',
'',
' -debug DIR read files from DIR to debug',
' -geType sge|uge test that type of GE', '',
$VERSION,
'');
my @EXAMPLES = ('examples:',
' qstat+ -a -u hpc show all of hpc\'s jobs',
' qstat+ -r -cpu% -u hpc show all of hpc\'s running jobs, cpu in %',
' qstat+ -r -cpu% -load -sua -u hpc show all of hpc\'s running jobs, cpu in %, and',
' the nodes\' load and slot usage/availability',
' qstat+ -q show all the queued jobs',
' qstat+ -j 8683280,8683285 show info on specific job IDs',
' qstat+ -nlist 8683280,8683285 show nodes list for specific job IDs',
' qstat+ -hiload 1.5 show nodes whose load is 1.5 greater than the number of slots used',
' qstat+ -ineffT 50 -ineff show jobs that are below a 50% efficiency threshold',
' qstat+ -osubT 200 -ageT 48 -osub show jobs that are above a 200% usage threshold and are older than 48 hours',
' qstat+ -gc show the global cluster status',
' qstat+ -es show the empty slots',
' qstat+ -down show which nodes are down',
'',
' +ax% -u all is equiv to -a -u all -cpu% -load -sua -mem',
' etc... for the +XXX shorthands',
'',
$VERSION,
'');
my $saveCmd = '';
my $saveLines;
#
my %timeThen;
my %hashJListTable = ();
my %hashQListTable = ();
#
$timeThen{main} = time();
#
# Parse arguments
#
&ParseArgs();
#
if ($option{'mode'} eq 'help') {
print STDERR join("\n", @HELP);
exit();
} elsif ($option{'mode'} eq 'examples') {
print STDERR join("\n", @EXAMPLES);
exit();
} elsif ($option{'mode'} eq 'showa') {
$show{running} = 1;
$show{queued} = 1;
$show{others} = 1;
$option{'mode'} = 'showDetails';
} elsif ($option{'mode'} eq 'showq') {
$show{running} = 0;
$show{queued} = 1;
$option{'mode'} = 'showDetails';
} elsif ($option{'mode'} eq 'showr') {
$show{running} = 1;
$show{queued} = 0;
$option{'mode'} = 'showDetails';
} elsif ($option{'mode'} eq 'showX') {
$show{others} = 1;
$option{'mode'} = 'showDetails';
}
#
if ($option{'user'} eq 'all' || $option{'user'} eq '*') {
$option{'user'} = "'*'";
}
#
if ($option{'geType'}) {$geType = $option{'geType'}}
if ($option{'verbose'}) {
my $key;
print STDERR "qstat+: -verbose geType = $geType\n";
print STDERR "qstat+: -verbose option: ";
foreach $key (sort(keys(%option))) {
print STDERR " $key=$option{$key}";
}
print STDERR "\n";
print STDERR "qstat+: -verbose show: ";
foreach $key (sort(keys(%show))) {
print STDERR " $key=$show{$key}";
}
print STDERR "\n";
}
#
my $q_load_avg = 'q_load_avg';
my $nodeExt = 'local';
if ($geType eq 'uge') {
$q_load_avg = 'q_np_load_avg';
$nodeExt = 'cm.cluster';
}
#
# Run different modes
#
if ($option{'mode'} eq 'jid') {
#
my @jidx = split(',', $option{'jidList'});
#
foreach my $jidx (@jidx) {
my ($jid, $tid) = split('\.', $jidx);
$option{'jid'} = $jid;
$option{'tid'} = $tid;
my @out = &ExecQstat('J');
#
if ($#jidx > 0) {
print " --- $jidx --- \n";
}
#
&ShowJstat(@out);
}
#
} elsif ($option{'mode'} eq 'nodelist') {
#
my @outF = &ExecQstat('F');
my @fVals = &ParseQstat(@outF);
#
&ShowNodeList(@fVals);
#
} elsif ($option{'mode'} eq 'gc') {
#
my @outF = &ExecQstat('F');
my @fVals = &ParseQstat(@outF);
#
&ShowClusterStats(@fVals);
#
} elsif ($option{'mode'} eq 'es') {
#
my @outF = &ExecQstat('F');
my @fVals = &ParseQstat(@outF);
#
&ShowEmptySlots($option{esx}, @fVals);
#
} elsif ($option{'mode'} eq 'hiload') {
#
my @outF = &ExecQstat('F');
my @fVals = &ParseQstat(@outF);
#
&ShowHiLoad(@fVals);
#
} elsif ($option{'mode'} eq 'down') {
#
my @outF = &ExecQstat('F');
my @fVals = &ParseQstat(@outF);
&ShowDown(@fVals);
#
} elsif ($option{'mode'} eq 'showDetails') {
#
my @outR = &ExecQstat('R');
my @outF = &ExecQstat('F');
#
my @rVals = &ParseQstat(@outR);
my @fVals = &ParseQstat(@outF);
#
&ShowDetails(\@rVals, \@fVals);
#
} elsif ($option{'mode'} eq 'userlist') {
#
my @outR = &ExecQstat('R');
my @outF = &ExecQstat('F');
#
my @rVals = &ParseQstat(@outR);
my @fVals = &ParseQstat(@outF);
#
&ShowUserList(\@rVals, \@fVals);
#
} elsif ($option{'mode'} eq 'summary') {
#
my @outR = &ExecQstat('R');
my @outF = &ExecQstat('F');
#
my @rVals = &ParseQstat(@outR);
my @fVals = &ParseQstat(@outF);
#
&ShowSummary(\@rVals, \@fVals);
#
} elsif ($option{'mode'} eq 'ssd') {
my @out = &ExecQstat('S');
&ShowSSDUsage(\@out);
} else {
#
die("Internal error: code should never get here (mode=$option{'mode'})");
}
#
if ($option{verbose}) {
my $elapsedTime = time() - $timeThen{main};
print STDERR "qstat+: all done in $elapsedTime sec\n";
}
exit;
#
# ---------------------------------------------------------------------------
#
# Routines
#
# sub ParseArgs - parse the arguments
# sub ExecQstat - execute qstat -xml [options]
# sub ParseQstat - parse the output of qstat -xml
# sub CompileStats - Compile cluster stats
# ---
# sub ShowDetails - show details
# sub ShowJstat - show job stats
# sub ShowNodeList - show node lisy
# sub ShowEmptySlots - show empry slots
# sub ShowClusterStats - show cluster stats
# sub ShowDown - show nodes down
# sub ShowHiLoad - show nodes with excessive load
# sub ShowUserList - show list of users
# sub ShowSSDUsage - show SSD usage
# sub ShowHeader - show header
# sub ShowFooter - show footer
# sub ShowSummary - show summary
# sub ShowQState - show queue stats
# ---
# sub FmtIOW - format IOW
# sub FmtIOOps
# sub FmtIOUse
# sub CvtSSD
# sub FmtSSD
# ---
# sub Load
# sub UseAvail
# sub SubStartTime
# sub CvtTime
# sub FormatTime
# sub Age
# sub Total
# sub XVals
# ---
# sub GetValJList
# sub GetValQList
# sub GetNodeNumber
# sub GetJobInfo
# sub GetVMem
# sub GetMaxVMem
# sub GetIOWait
# sub GetIOOPs
# ---
# sub Uptime
# sub bynode
# ---
#
# ------------------------------------------------------------------------
#
sub ParseArgs {
#
#
#
my $subName = (caller(0))[3];
$timeThen{$subName} = time();
my %set = ();
my $err = 0;
#
while ($#ARGV >= 0) {
if ($set{$ARGV[0]}) {
if ($show{warn}) {
print STDERR 'qstat+: ParseArgs() warning duplicate argument "'.$ARGV[0].'"'."\n";
}
# $err++;
# goto nextArg;
}
#
$set{$ARGV[0]}++;
foreach my $key (keys %args) {
if ($ARGV[0] eq $key) {
foreach my $val (split(',', $args{$key})) {
my ($t, $a) = split(':', $val);
my ($k, $v) = split('=', $a);
#
my $ign = 0;
if ($set{$k}) {
# qstat+: ParseArgs() argument "-u" conflicts with "-osub" (user)
if ($k eq 'user') {
if ($set{$k} eq '-osub' ||
$set{$k} eq '-ineff' ||
$set{$k} eq '-ores' ) { $ign = 1;}
}
if ($set{$k} ne $key && $ign == 0) {
#
$err++;
print STDERR 'qstat+: ParseArgs() argument "'.$ARGV[0].'"'.' conflicts with "'.$set{$k}.'"'." ($k)\n";
}
}
$set{$k} = $key;
#
if ($t eq 'o') {
#
if ($v eq 'NEXT') {
shift @ARGV;
if ($#ARGV >= 0) {
$option{$k} = $ARGV[0];
} else {
$err++;
print STDERR 'qstat+: ParseArgs() incomplete "'.$key.'" argument'."\n";
}
} else {
$option{$k} = $v;
}
#
} elsif ($t eq 's') {
#
$show{$k} = $v;
#
} elsif ($t eq 'x') {
#
my @w = split(' ', $a);
my $w;
my @l = ();
#
foreach $w (@w) {
if ($w =~ /^\$/) {
$w =~s/.//;
$w = $ENV{$w};
}
@l = (@l, $w);
}
# splice @l in @ARGV
$w = shift @ARGV;
@ARGV = ($w, @l, @ARGV);
#
## print STDERR join(':',@ARGV),"\n"; die "here";
} else {
#
die "qstat+: ParseArgs() should not get here (t=$t)";
#
}
}
goto nextArg;
}
}
$err++;
print STDERR 'qstat+: ParseArgs() invalid argument "'.$ARGV[0].'"'."\n";
nextArg:
shift @ARGV;
}
#
if ($err > 0) {
print STDERR join("\n", @ERRMSG);
exit(1);
}
#
if ($option{verbose}) {
my $elapsedTime = time() - $timeThen{$subName};
print STDERR "qstat+: ParseArgs() done in $elapsedTime sec\n";
}
}
#
# ---------------------------------------------------------------------------
#
sub ExecQstat {
#
# execute qstat command
#
my $subName = (caller(0))[3];
$timeThen{$subName} = time();
#
my $mode = shift(@_);
my $fn = '';
my $opts = '';
my $cmd = '';
#
if ($option{fake}) {
if ($mode eq 'R') {
if ($option{user} ne "'*'") {
$fn = $option{fake}.'/qstat-r-'.$option{user}.'.xml';
} else {
$fn = $option{fake}.'/qstat-r.xml';
}
}
elsif ($mode eq 'F') {
if ($option{user} ne "'*'") {
$fn = $option{fake}.'/qstat-f-'.$option{user}.'.xml';
} else {
$fn = $option{fake}.'/qstat-f.xml';
}
}
elsif ($mode eq 'J') {
# use the 1st jobid from the list, and ignore .$tid if any
my @jids = split(',', $option{jidList});
my ($jid, $tid) = split('\.', $jids[0]);
$fn = $option{fake}.'/qstat-j-'.$jid.'.txt';
}
elsif ($mode eq 'S') { $fn = $option{fake}.'/qstat-ssd.txt'; }
else {die "qstat+: ExecQstat(): invalid mode $mode\n"; }
#
$cmd = 'cat '.$fn;
} else {
my $queue = '';
if ($option{'queue'}) { $queue = " -q '$option{'queue'}'"; }
if ($mode eq 'R') { $opts = ' -xml -r -ext -u '.$option{'user'}.$queue; }
elsif ($mode eq 'F') { $opts = ' -xml -f -u '.$option{'user'}.$queue; }
elsif ($mode eq 'J') { $opts = ' -j '.$option{'jid'}; }
elsif ($mode eq 'S') {
#
# don't bother to use -xml
$opts = '-F ssd_res,ssd_free,ssd_total -q all.q@@ssd-hosts -u nobody';
} else {die "qstat+: ExecQstat(): invalid mode $mode\n"; }
$cmd = $qstat.' '.$opts;
}
#
if ($option{verbose} || $option{fake}) {
print STDERR "qstat+: ExecQstat(): executing <$cmd>";
if (! $option{verbose}) { print STDERR "\n"; }
}
#
my @lines = `$cmd`;
if ($? != 0) {
die "qstat+: ExecQstat(): command failed <$!>\n";
}
#
if ($option{verbose}) {
my $elapsedTime = time() - $timeThen{$subName};
print STDERR " done in $elapsedTime sec\n";
}
#
return @lines;
#
}
#
# ---------------------------------------------------------------------------
#
sub ParseQstat {
#
# the parsing should return a tree, not a list, but this will do for now
#
my $subName = (caller(0))[3];
$timeThen{$subName} = time();
#
my $line = '';
my $tag = '';
my $val = '';
my $tagx = '';
my @opts = ();
my @tags = ();
my @info = ();
my %info = ();
#
my %prfx = ('Queue-List' => 'q_',
'job_list' => 'j_');
#
# parsing xlm data. -> @info = ({%info})
#
my $iLine = 1;
my $level = 0;
my $prfx;
#
foreach $line (@_) {
#
if ($line =~ /<\?xml .*\?\>/) {
#ignore
} elsif ($line =~ /\<.*\>.*\<\/.*\>/) {
# <tag options>value</tag>
$line =~ s/\<(.*)\>(.*)\<\/(.*)\>//;
($tag, @opts) = split(' ', $1);
$val = $2;
$tagx = $3;
if ($tag ne $tagx) {
die "qstat+: ParseQstat() error: $tag & $tagx do not match at line $iLine\n";
}
# parse opts for name="";
foreach my $opt (@opts) {
my ($k, $v) = split('=', $opt);
if ($k eq 'name') {
$v =~ s/^\"//;
$v =~ s/\"$//;
$tag .= '.'.$v;
}
}
#
my $nTag = $#tags;
$prfx = '';
while ($prfx eq '') {
if ($prfx{$tags[$nTag]}) {
$prfx = $prfx{$tags[$nTag]};
} else {
$nTag--;
}
}
#
if ($prfx eq '') { die "qstat+: ParseQstat() error: invalid tag[$nTag]=$tags[$nTag]\n"; }
#
$info{$prfx.$tag} = $val;
#
} else {
#
# <tag options>
$line =~ s/\<(.*)\>//;
($tag, @opts) = split(' ', $1);
if ($tag =~ /^\/.*/) {
$level--;
$tag =~ s/.//;
$tagx = pop(@tags);
if ($tag ne $tagx) {
die "qstat+: ParseQstat() error: $tagx & /$tag do not match at line $iLine\n";
}
#
if ($tag eq 'job_list' || $tag eq 'Queue-List') {
#
my $n = keys(%info);
if ($n > 0) {
#
# UGE --> load *= n_slots
if ($geType eq 'uge') {
if (defined $info{$q_load_avg}) {
$info{$q_load_avg} *= $info{q_slots_total};
}
}
@info = (@info, {%info});
###
my $k = $prfx.'JB_job_number';
if ($info{$k}) {
$tag .= ' '.$info{$k};
}
}
%info = ();
}
#
} else {
#
# push the tag
$level++;
@tags = (@tags, $tag);
}
#
}
$iLine++;
}
#
# done parsing the xml data
#
if ($option{verbose}) {
my $elapsedTime = time() - $timeThen{$subName};
print STDERR "qstat+: ParseQstat() done in $elapsedTime sec\n";
}
return @info;
}
#
# ---------------------------------------------------------------------------
#
sub CompileStats {
#
my $subName = (caller(0))[3];
$timeThen{$subName} = time();
#
# parsing these licenses
#
my @lic = ('idlrt');
#
my @info = @{$_[0]}; # qstat -r
my @infox = @{$_[1]}; # qstat -f
my $info = '';
#
my %cntR = ();
my %cntRJ = ();
my %cntQ = ();
my %cntQT = ();
my %cntQJ = ();
my %cntX = ();
my %cntXS = ();
my %total = ();
my %lic = ();
#
my %info = ();
my $user = '';
my $state = '';
#
$total{slots} = 0;
$total{runPEs} = 0;
$total{runJobs} = 0;
$total{queued} = 0;
$total{extra} = 0;
#
$total{queues} = '';
$total{racks} = '';
#
$total{slots_disabled} = 0;
#
foreach $info (@info) {
%info = %{$info};
#
$user = $info{j_JB_owner};
$state = $info{j_state};
if ($state =~ /r$/) {
my $nPE = 1;
foreach my $pe ('granted_pe.mpich', 'granted_pe.mthread', 'granted_pe.orte') {
if ($info{'j_'.$pe}) { $nPE = $info{'j_'.$pe}; }
}
$total{runJobs}++;
$total{runPEs} += $nPE;
$cntR{$user} += $nPE;
$cntRJ{$user}++;
# parse license info
foreach my $lic (@lic) {
my $key = 'j_hard_request.'.$lic.'_license';
if ( $info{$key} ) {
$lic{$lic} += $info{$key};
}
}
#
} elsif ($state eq 'qw' || $state eq 'hqw') {
# get # slots and tasks info to compute requested PEs
my $nPE = 1;
my $nT = 1;
if ($info{j_slots}) { $nPE = $info{j_slots}; }
if ($info{j_tasks}) {
if ($info{j_tasks} =~ /:/) {
my ($i,$j, $k) = split('[\-\:]', $info{j_tasks});
$nT = ($j - $i + 1)/$k;
}
# total is slots*tasks
$nPE *= $nT;
}
#
$cntQ{$user}+= $nPE;
$cntQT{$user}+= $nT;
$cntQJ{$user}++;
$total{queued}++;
#
} else {
$cntX{$user}++;
$total{extra}++;
$cntXS{$state}++;
}
}
#
my %list = ();
my ($name, $queue, $host);
#
$total{down} = 0;
my %qNode = ();
my %qLoad = ();
my %qSlot = ();
my %qResv = ();
my %qUsed = ();
my %qDis = ();
my %qAtt = ();
my %qErr = ();
my %rNode = ();
my %init = ();
my %down = ();
my ($c, $rack, $node);
#
foreach $info (@infox) {
%info = %{$info};
if ($info{q_name}) {
$name = $info{q_name};
($queue, $host) = split('@', $name, 2);
#
$qNode{$queue}++;
#
if (defined $info{$q_load_avg}) {
$qLoad{$queue} += $info{$q_load_avg};
$qSlot{$queue} += $info{q_slots_total};
$qResv{$queue} += $info{q_slots_resv};
$qUsed{$queue} += $info{q_slots_used};
}
#
$host = &GetNodeNumber($host);
($rack, $node) = split('-', $host);
#
my $enabled = 1;
#
if ($info{q_state}) {
# check queue state
if ($info{q_state} =~ /d/) { $qDis{$queue}++; $enabled = 0; }
if ($info{q_state} =~ /a/) { $qAtt{$queue}++; $enabled = 0; }
if ($info{q_state} =~ /E/) { $qErr{$queue}++; $enabled = 0; }
}
#
if ($list{$host}) {
# don't count twice
} else {
#
$rNode{$rack}++;
$list{$host}++;
if (defined $info{$q_load_avg}) {
$total{load} += $info{$q_load_avg};
} else {
$total{down}++;
$down{$host}++;
}
$total{nodes}++;
if ($enabled == 1) {
$total{slots} += $info{q_slots_total};
} else {
$total{slots_disabled} += $info{q_slots_total};
}
}
$total{slotsUsed} += $info{q_slots_used};
#
} else {
# print join(', ', keys %info),"\n";
}
}
#
foreach $queue (sort keys %qNode) {
# queue:load, noNodes, nUsed(CPUs), nRes(CPUs), nCPUs(avail)
if (! $qLoad{$queue}) {$qLoad{$queue} = 0.0;}
if (! $qNode{$queue}) {$qNode{$queue} = 0;}
if (! $qUsed{$queue}) {$qUsed{$queue} = 0;}
if (! $qResv{$queue}) {$qResv{$queue} = 0;}
if (! $qSlot{$queue}) {$qSlot{$queue} = 0;}
$total{queues} .= "$queue:$qLoad{$queue},$qNode{$queue},$qUsed{$queue},$qResv{$queue},$qSlot{$queue} ";
}
chop($total{queues});
#
foreach $rack (sort keys %rNode) {
$total{racks} .= "$rack/$rNode{$rack} ";
}
chop($total{racks});
#
$total{dis} = &Total(%qDis);
$total{att} = &Total(%qAtt);
$total{err} = &Total(%qErr);
#
if ($option{verbose}) {
my $elapsedTime = time() - $timeThen{$subName};
print STDERR "qstat+: CompileStats() done in $elapsedTime sec\n";
}
#
return (\%cntR, \%cntRJ, \%cntQ, \%cntQT, \%cntQJ, \%cntX, \%total, \%lic, \%cntXS,
\%qDis, \%qAtt, \%qErr, \%down);
#
}
#
# ---------------------------------------------------------------------------
#
sub ShowDetails {
#
my $subName = (caller(0))[3];
$timeThen{$subName} = time();
#
my @info = @{$_[0]}; # qstat -r
my @infox = @{$_[1]}; # qstat -f
#
my $info;
my %info;
#
my %cntR;
my %cntRJ;
my %cntQ;
my %cntQT;
my %cntQJ;
my %cntX;
my %total;
my %lic;
my %cntXS;
# my %qDis;
# my %qAtt;
# my %qErr;
#
if ($show{header} == 1 || $show{footer} == 1 ) {