NBI-Slurm
view release on metacpan or search on metacpan
bin/slurm-load view on Meta::CPAN
my $up = $total - $down;
my $jobs_running = $job->{jobs_running} || 0;
my $jobs_pending = $job->{jobs_pending} || 0;
my $nodes_running = $job->{nodes_running} || 0;
my $nodes_pending = $job->{nodes_pending} || 0;
my $load = sprintf('%d%%', load_pct($node));
push @rows, [
$partition,
$total,
$up,
$idle,
$mix,
$alloc,
$down,
$jobs_running,
$jobs_pending,
$nodes_running,
$nodes_pending,
$load,
];
$totals{total} += $total;
$totals{up} += $up;
$totals{idle} += $idle;
$totals{mix} += $mix;
$totals{alloc} += $alloc;
$totals{down} += $down;
$totals{jobs_running} += $jobs_running;
$totals{jobs_pending} += $jobs_pending;
$totals{nodes_running} += $nodes_running;
$totals{nodes_pending} += $nodes_pending;
}
if (@rows > 1) {
push @rows, [
$totals{partition},
$totals{total},
$totals{up},
$totals{idle},
$totals{mix},
$totals{alloc},
$totals{down},
$totals{jobs_running},
$totals{jobs_pending},
$totals{nodes_running},
$totals{nodes_pending},
sprintf('%d%%', load_pct(\%totals)),
];
}
return \@rows;
}
sub load_pct {
my ($row) = @_;
my $total = $row->{total} || 0;
my $down = $row->{down} || 0;
my $up = $total - $down;
return 0 if $up <= 0;
my $busy = ($row->{mix} || 0) + ($row->{alloc} || 0);
return ($busy / $up) * 100;
}
sub normalise_node_state {
my ($state) = @_;
$state = lc($state // '');
$state =~ s/[^a-z].*$//;
return 'idle' if $state =~ /^idle/;
return 'mix' if $state =~ /^mix/;
return 'alloc' if $state =~ /^alloc/;
return 'down' if $state =~ /^(down|drain|drng|drained|fail)/;
return 'alloc';
}
sub normalise_job_state {
my ($state) = @_;
$state = uc($state // '');
return 'pending' if $state eq 'PD';
return 'running' if $state =~ /^(R|CG|CF|SI|SO|ST)$/;
return 'running';
}
sub print_tsv {
my ($rows) = @_;
for my $row (@{$rows}) {
say join("\t", @{$row});
}
}
sub print_table {
my ($rows) = @_;
my @widths;
for my $row (@{$rows}) {
for my $i (0 .. $#{$row}) {
my $len = length($row->[$i] // '');
$widths[$i] = $len if !defined $widths[$i] || $len > $widths[$i];
}
}
for my $idx (0 .. $#{$rows}) {
my $row = $rows->[$idx];
my @parts;
for my $i (0 .. $#{$row}) {
my $fmt = $i == 0 ? "%-*s" : "%*s";
push @parts, sprintf($fmt, $widths[$i], $row->[$i]);
}
if ($idx == 0) {
say BOLD, join(" ", @parts), RESET;
my @rule = map { '-' x $_ } @widths;
say join(" ", @rule);
next;
}
if ($row->[0] eq 'TOTAL') {
say BOLD, join(" ", @parts), RESET;
} else {
say join(" ", @parts);
}
( run in 1.550 second using v1.01-cache-2.11-cpan-63c85eba8c4 )