forked from hpcugent/slurm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsjstat
executable file
·534 lines (433 loc) · 14.4 KB
/
sjstat
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
#!/usr/bin/perl
###############################################################################
#
# sjstat - List attributes of jobs under SLURM control
#
###############################################################################
# Copyright (C) 2007 The Regents of the University of California.
# Copyright (C) 2008-2009 Lawrence Livermore National Security.
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
# Written by Phil Eckert <eckert21@llnl.gov>.
# CODE-OCEC-09-009. All rights reserved.
#
# This file is part of Slurm, a resource management program.
# For details, see <https://slurm.schedmd.com/>.
# Please also read the included file: DISCLAIMER.
#
# SLURM is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# In addition, as a special exception, the copyright holders give permission
# to link the code of portions of this program with the OpenSSL library under
# certain conditions as described in each individual source file, and
# distribute linked combinations including the two. You must obey the GNU
# General Public License in all respects for all of the code used other than
# OpenSSL. If you modify file(s) with this exception, you may extend this
# exception to your version of the file(s), but you are not obligated to do
# so. If you do not wish to do so, delete this exception statement from your
# version. If you delete this exception statement from all source files in
# the program, then also delete it here.
#
# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with SLURM; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Based off code with permission copyright 2006, 2007 Cluster Resources, Inc.
###############################################################################
#
# Man page stuff.
#
BEGIN {
# Just dump the man page in *roff format and exit if --roff specified.
foreach my $arg (@ARGV) {
if ($arg eq "--") {
last;
} elsif ($arg eq "--roff") {
use Pod::Man;
my $parser = Pod::Man->new (section => 1);
$parser->parse_from_file($0, \*STDOUT);
exit 0;
}
}
}
use strict;
use Getopt::Long 2.24 qw(:config no_ignore_case);
use autouse 'Pod::Usage' => qw(pod2usage);
#
# Global Variables.
#
my ($help, $man, $pool, $running, $verbose);
my (%MaxNodes, %MaxTime);
#
# Check SLURM status.
#
isslurmup();
#
# Get user options.
#
get_options();
#
# Get partition information from scontrol, used
# currently in conjunction with the sinfo data..
#
do_scontrol_part();
#
# Get and display the sinfo data.
#
do_sinfo();
#
# If the -c option was entered, stop here.
#
exit if ($pool);
#
# Get and display the squeue data.
#
do_squeue();
exit;
#
# Get the SLURM partitions information.
#
sub do_sinfo
{
my (@s_part, @s_mem, @s_cpu, @s_feat, @s_active, @s_idle,
@s_out, @s_total, @s_usable);
#
# Get the partition and node info.
#
my $options = "\"%9P %7m %.4c %.22F %f\"";
my $ct = 0;
my @sin = `sinfo -e -o $options`;
foreach my $tmp (@sin) {
next if ($tmp =~ /^PARTITION/);
chomp $tmp;
my @line = split(' ',$tmp);
$s_part[$ct] = $line[0];
$s_mem[$ct] = $line[1];
$s_cpu[$ct] = $line[2];
#
# Split the status into various components.
#
my @fields = split(/\//, $line[3]);
$s_active[$ct] = $fields[0];
$s_idle[$ct] = $fields[1];
$s_out[$ct] = $fields[2];
$s_total[$ct] = $fields[3];
$s_usable[$ct] = $s_total[$ct] - $s_out[$ct];
$s_feat[$ct] = ($line[4] .= " ");
$s_feat[$ct] =~ s/\(null\)//g;
$ct++;
}
printf("\nScheduling pool data:\n");
if ($verbose) {
printf("----------------------------------------------------------------------------------\n");
printf(" Total Usable Free Node Time Other \n");
printf("Pool Memory Cpus Nodes Nodes Nodes Limit Limit traits \n");
printf("----------------------------------------------------------------------------------\n");
} else {
printf("-------------------------------------------------------------\n");
printf("Pool Memory Cpus Total Usable Free Other Traits \n");
printf("-------------------------------------------------------------\n");
}
for (my $i = 0; $i < $ct; $i++) {
if ($verbose) {
my $p = $s_part[$i];
$p =~ s/\*//;
printf("%-9s %7dMb %5s %6s %7s %6s %6s %10s %-s\n",
$s_part[$i], $s_mem[$i], $s_cpu[$i],
$s_total[$i], $s_usable[$i],
$s_idle[$i], $MaxNodes{$p},
$MaxTime{$p}, $s_feat[$i]);
} else {
printf("%-9s %7dMb %5s %6s %6s %6s %-s\n",
$s_part[$i], $s_mem[$i], $s_cpu[$i],
$s_total[$i], $s_usable[$i],
$s_idle[$i], $s_feat[$i]);
}
}
printf("\n");
return;
}
#
# Get the SLURM queues.
#
sub do_squeue
{
my (@s_job, @s_user, @s_nodes, @s_status, @s_begin, @s_limit,
@s_start, @s_pool, @s_used, @s_master);
#
# Base options on whether this partition is node or process scheduled.
#
my ($type, $options);
my $rval = system("scontrol show config | grep cons_res >> /dev/null");
if ($rval) {
$type = "Nodes";
$options = "\"%8i %8u %.6D %2t %S %.12l %.9P %.11M %1000R\"";
} else {
$type = "Procs";
$options = "\"%8i %8u %.6C %2t %S %.12l %.9P %.11M %1000R\"";
}
#
# Get the job information.
#
my $ct = 0;
my $pat = "tr -s '[' '\000' |cut -d'-' -f 1 | cut -d',' -f 1";
my @sout = `squeue -o $options`;
foreach my $tmp (@sout) {
next if ($tmp =~ /^JOBID/);
next if ($running && $tmp =~ / PD /);
chomp $tmp;
my @line = split(' ', $tmp);
$s_job[$ct] = $line[0];
$s_user[$ct] = $line[1];
$s_nodes[$ct] = $line[2];
$s_status[$ct] = $line[3];
$line[4] =~ s/^.....//;
$line[4] = "N/A" if ($line[3] =~ /PD/);
$s_begin[$ct] = $line[4];
$s_limit[$ct] = $line[5];
if ($line[5] eq "UNLIMITED") {
$s_limit[$ct] = $line[5];
} else {
$s_limit[$ct] = convert_time($line[5]);
}
$s_pool[$ct] = $line[6];
$s_used[$ct] = $line[7];
#
# Only keep the master node from the nodes list.
#
$line[8] =~ s/\[([0-9.]*).*/$1/;
$s_master[$ct] = $line[8];
$ct++;
}
printf("Running job data:\n");
if ($verbose) {
printf("---------------------------------------------------------------------------------------------------\n");
printf(" Time Time Time \n");
printf("JobID User $type Pool Status Used Limit Started Master/Other \n");
printf("---------------------------------------------------------------------------------------------------\n");
} else {
printf("----------------------------------------------------------------------\n");
printf("JobID User $type Pool Status Used Master/Other \n");
printf("----------------------------------------------------------------------\n");
}
for (my $i = 0; $i < $ct; $i++) {
if ($verbose) {
printf("%-8s %-8s %6s %-9s %-7s %10s %11s %14s %.12s\n",
$s_job[$i], $s_user[$i], $s_nodes[$i],
$s_pool[$i], $s_status[$i],
$s_used[$i], $s_limit[$i], $s_begin[$i],
$s_master[$i]);
} else {
printf("%-8s %-8s %6s %-9s %-7s %10s %.12s\n",
$s_job[$i], $s_user[$i], $s_nodes[$i],
$s_pool[$i], $s_status[$i],
$s_used[$i], $s_master[$i]);
}
}
printf("\n");
return;
}
#
# Get the SLURM partitions.
#
sub do_scontrol_part
{
#
# Get All partition data Don't need it all now, but
# it may be useful later.
#
my @scon = `scontrol show part`;
my $part;
foreach my $tmp (@scon) {
chomp $tmp;
my @line = split(' ',$tmp);
($part) = ($tmp =~ m/PartitionName=(\S+)/) if ($tmp =~ /PartitionName=/);
($MaxTime{$part}) = ($tmp =~ m/MaxTime=(\S+)\s+/) if ($tmp =~ /MaxTime=/);
($MaxNodes{$part}) = ($tmp =~ m/MaxNodes=(\S+)\s+/) if ($tmp =~ /MaxNodes=/);
$MaxTime{$part} =~ s/UNLIMITED/UNLIM/ if ($MaxTime{$part});
$MaxNodes{$part} =~ s/UNLIMITED/UNLIM/ if ($MaxNodes{$part});
}
return;
}
#
# Show the man page.
#
sub show_man
{
if ($< == 0) { # Cannot invoke perldoc as root
my $id = eval { getpwnam("nobody") };
$id = eval { getpwnam("nouser") } unless defined $id;
$id = -2 unless defined $id;
$< = $id;
printf("\n You can not do this as root!\n\n");
exit 1;
}
$> = $<; # Disengage setuid
$ENV{PATH} = "/bin:/usr/bin"; # Untaint PATH
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
if ($0 =~ /^([-\/\w\.]+)$/) { $0 = $1; } # Untaint $0
else { die "Illegal characters were found in \$0 ($0)\n"; }
pod2usage(-exitstatus => 0, -verbose => 2);
return;
}
#
# Convert the time to a better format.
#
sub convert_time
{
my $val = shift(@_);
my $tmp;
my @field = split(/-|:/, $val);
if (@field == 4) {
$tmp = ($field[0]*24)+$field[1] . ':'.$field[2] . ':' . $field[3];
} else {
$tmp = sprintf("%8s",$val);
}
return($tmp);
}
#
# Get options.
#
sub get_options
{
GetOptions(
'help|h|?' => \$help,
'man' => \$man,
'v' => \$verbose,
'r' => \$running,
'c' => \$pool,
) or usage(1);
show_man() if ($man);
usage(0) if ($help);
return;
}
#
# Usage.
#
sub usage
{
my $eval = shift(@_);
#
# Print usage instructions and exit.
#
print STDERR "\nUsage: sjstat [-h] [-c] p\[-man] [-r] [-v]\n";
printf("\
-h shows usage.
-c shows computing resources info only.
-man shows man page.
-r show only running jobs.
-v is for the verbose mode.\n
Output is very similar to that of squeue.
\n\n");
exit($eval);
}
#
# Determine if SLURM is available.
#
sub isslurmup
{
my $out = `scontrol show part 2>&1`;
if ($?) {
printf("\n SLURM is not communicating.\n\n");
exit(1);
}
return;
}
__END__
=head1 NAME
B<sjstat> - List attributes of jobs under the SLURM control
=head1 SYNOPSIS
B<sjstat> [B<-h> ] [B<-c>] [B<-r> ] [B<-v>]
=head1 DESCRIPTION
The B<sjstat> command is used to display statistics of jobs under control of SLURM.
The output is designed to give information on the resource usage and availablilty,
as well as information about jobs that are currently active on the machine. This output
is built using the SLURM utilities, sinfo, squeue and scontrol, the man pages for these
utilites will provide more information and greater depth of understanding.
=head1 OPTIONS
=over 4
=item B<-h>
Display a brief help message
=item B<-c>
Display the computing resource information only.
=item B<-man>
Show the man page.
=item B<-r>
Display only the running jobs.
=item B<-v>
Display more verbose information.
=back
=head1 EXAMPLE
The following is a basic request for status.
> sjstat
Scheduling pool data:
------------------------------------------------------------
Pool Memory Cpus Total Usable Free Other Traits
------------------------------------------------------------
pdebug 15000Mb 8 32 32 24 (null)
pbatch* 15000Mb 8 1072 1070 174 (null)
Running job data:
-------------------------------------------------------------------
JobID User Nodes Pool Status Used Master/Other
-------------------------------------------------------------------
395 mary 1000 pbatch PD 0:00 (JobHeld)
396 mary 1000 pbatch PD 0:00 (JobHeld)
375 sam 1000 pbatch CG 0:00 (JobHeld)
388 fred 32 pbatch R 25:27 atlas89
361 harry 512 pbatch R 1:01:12 atlas618
1077742 sally 8 pdebug R 20:16 atlas18
The Scheduling data contains information pertaining to the:
Pool a set of nodes
Memory the amount of memory on each node
Cpus the number of cpus on each node
Total the total number of nodes in the pool
Usable total usaable nodes in the pool
Free total nodes that are currently free
The Running job data contains information pertaining to the:
JobID the SLURM job id
User owner of the job
Nodes nodes required, or in use by the job
(Note: On cpu scheduled machines, this field
will be labled "Procs" show the number of processors
the job is using.)
Pool the Pool required or in use by the job
Status current status of the job
Used Wallclick time used by the job
Master/Other Either the Master (head) node used by the job, or may
indicate furhter status of a pending, or completing job.
The common status values are:
R The job is running
PD The job is Pending
CG The job is Completing
These are states reproted by SLURM and more elaborate docuemntation
can be found in the squeue/sinfo man pages.
An example of the -v option.
Scheduling pool data:
-----------------------------------------------------------------------------
Total Usable Free Node Time Other
Pool Memory Cpus Nodes Nodes Nodes Limit Limit Traits
-----------------------------------------------------------------------------
pdebug 15000Mb 8 32 32 24 16 30 (null)
pbatch* 15000Mb 8 1072 1070 174 UNLIM UNLIM (null)
Running job data:
---------------------------------------------------------------------------------------------------
Time Time Time
JobID User Nodes Pool Status Used Limit Started Master/Other
---------------------------------------------------------------------------------------------------
38562 tom 4 pbatch PD 0:00 1:00:00 01-14T18:11:22 (JobHeld)
The added fields to the "Scheduling pool data" are:
Node Limit SLURM imposed node limit.
Time Limit SLURM imposed time limit, value in minutes.
The added fields to the "Running job data" are:
Limit Time limit of job.
Start Start time of job.
=head1 REPORTING BUGS
Report bugs to <eckert2@llnl.gov>
=cut