-
Notifications
You must be signed in to change notification settings - Fork 0
/
slurmnodez
executable file
·121 lines (103 loc) · 3.3 KB
/
slurmnodez
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
#!/usr/bin/perl
use Time::Local;
use Term::ANSIColor;
use Data::Dumper;
use Cwd 'abs_path';
use File::Basename;
my $EXECPATH = abs_path(dirname(__FILE__));
$SLURMDIR= "/usr/local/bin";
$dockerPath = "/varidata/research/clustermgmt/vaihpc/VAIDocker/hpcnode";
$sinfo = `$SLURMDIR/sinfo -o "%n %e %m %t %c %C" -h`;
$squeue = `$SLURMDIR/squeue --format="%i %.9P %.30j %.15u %.8T %.10M %.9l %.10D %R " -h`;
$docker = ` ls -rt $EXECPATH/cpulogs/computeloads* | tail -n 1 | xargs cat`;
open HAND, '<', "$EXECPATH/nodes.txt";
%nodeClass = map {chomp; split /\t+/} (<HAND>);
my @nodes = split "\n", $sinfo;
my @containers = split "\n", $docker;
my @jobs = split "\n", $squeue;
$detail = 1 if $ARGV[0] eq "-f";
foreach my $n (@nodes)
{
my @lines = split /\s+/, $n;
my $node = $lines[0];
my @nodeCores = split "/", $lines[5];
$nodeprops{$node}{status}=$lines[3];
$nodeprops{$node}{cores}=$lines[4];
$nodeprops{$node}{coresinuse}=$nodeCores[0];
$nodeprops{$node}{coresfree}=$nodeCores[1];
}
foreach my $n (@containers)
{
my @lines = split /\s+/, $n;
my $node = $lines[2];
$nodeprops{$node}{baremetal}=$lines[0];
$nodeprops{$node}{baremetal} =~ s/\://g;
$nodeprops{$node}{cpuload}=$lines[3];
$nodeprops{$node}{cpuload} =~ s/\.\d+\%//;
$nodeprops{$node}{cpuload} = $nodeprops{$node}{cpuload} / 100;
$nodeprops{$node}{memload}=$lines[4];
$nodeprops{$node}{memload}=~ s/\.\d+//g;
$nodeprops{$node}{memlimit}=$lines[6];
$nodeprops{$node}{memlimit}=~ s/\.\d+//g;
$nodeprops{$node}{mempct}=$lines[7];
$nodeprops{$node}{threads}=$lines[14];
}
foreach my $n (@jobs)
{
my @lines = split /\s+/, $n;
my $user = $lines[3];
my $jobID = $lines[0];
my $nodeList = $lines[8];
my @jobNodes;
while ($nodeList =~ /(compute\d\d\d)/g)
{
push @jobNodes, $1;
}
while ($nodeList =~ /\[(\d\d\d)-(\d\d\d)\]/g)
{
for my $i ($1..$2)
{
push @jobNodes, sprintf("compute%03d", $i);
}
}
for my $j (@jobNodes)
{
$nodeprops{$j}{job}{$jobID}{user} = $user;
}
}
#print Dumper(%nodeprops);
foreach $k (sort keys %nodeprops)
{
$color = $nodeprops{$k}{job} ? "red" : "green";
print color($color) . "$k " . $nodeClass{$k} . "\t" . color("reset");
print "$nodeprops{$k}{cores}core\t";
for my $j (keys %{ $nodeprops{$k}{job} }) {
print "[" . color("cyan") . "#$j" . color("reset") . ":" . color("yellow") . $nodeprops{$k}{job}{$j}{user} . color("reset") . "]";
}
if( $nodeprops{$k}{status} =~ /down/)
{
print color("red") . "NODE IS OFFLINE" . color("reset");
}
elsif( $nodeprops{$k}{status} =~ /drain/)
{
print color("magenta") . "temporary maintenance mode " . color("reset");
}
elsif (! %{ $nodeprops{$k}{job}})
{
print color("green") . "FREE" . color("reset");
}
#print "\t" . $nodeprops{$k}{coresinuse} . " cores requested" if %{ $nodeprops{$k}{job}};
print "\tload=" . $nodeprops{$k}{cpuload} if %{ $nodeprops{$k}{job}} || $detail;
print "\tmem=" . $nodeprops{$k}{memload} . "/" . $nodeprops{$k}{memlimit} if $detail ;
print "\tthreads=" . $nodeprops{$k}{threads} if $detail;
print "\thost=" . &computeToServer($k) if $detail;
print "\n";
}
sub computeToServer
{
my $compute = shift @_;
my $server = `grep $compute $dockerPath/*.yml | head -n 1`;
$server =~ /(server\d\d\d)/;
return $1;
}
#system "echo " . time . " " . $ENV{USER} ." >> $root_directory/log/access.log";