#!/usr/bin/env perl # Harry Mangalam 06-22-2018 $optcpuload = 0.8; $saferamload = 0.9; $ff = 1; $hh=`qhost | grep compute | scut -f=0`; # results in a string of hostnames chomp $hh; $hh =~ s/\n/ /g; # suck in the entire 'qstat -s r' output and do everything in ram # need field 3 (user) 7(free64@compute-4-32.local) 8(# of cores) # ie an array of type: vojh1,free64@compute-1-3.local,1 $qn = @qs =`qstat -s r | scut -f="3 7 8" --od=',' | tail -n+3`; # user,q@host.local,cores my %hun; for ($e=0; $e<$qn; $e++){ chomp $qs[$e]; $n = @q = split(/,/,$qs[$e]); @h = split(/@/,$q[1]); $hn = substr($h[1], 0, -6); # now need to make a 3way indexed hash on host, Q, username $qp = $h[0]; # qp = Q part # now put the nec values into a host-indexed hash if (!defined $hun{$hn}{$qp}{$q[0]}) { $hun{$hn}{$qp}{$q[0]} = $q[2]; }# hash indexed by hostname, then by user, containing job else { $hun{$hn}{$qp}{$q[0]} += $q[2]; } } # save this as an example for other scripts. # now print out that hash somehow, with 2 levels of keys. #foreach $hst (sort keys %hun) { # print "\n$hst "; # foreach $hq (sort keys %{$hun{$hst}}) { # print "| $hq:"; # foreach $usr (sort keys %{$hun{$hst}{$hq}}) { # print "$usr,$hun{$hst}{$hq}{$usr} "; # } # print " "; # } #} @Q = `qhost -h $hh -q`; print "Shows most of the info shown from 'qhost -q' and 'qstat -s r' but in one line. Also shows whether a node is over (+) or under(-) loaded. At the end of each line is the status of all Qs that use this node. Only compute nodes are shown in this output."; print " under/ CPUs RAM (Assigned/Total) HOSTNAME over USED/TOTAL USED/TOTAL Queue v [flags] users,jobs"; for ($i=3;$i<$#Q; $i++) { chomp $Q[$i]; $N = @A = split(/\s+/,$Q[$i]); if ($N == 11) {$ff = 1;} if ($ff == 1) { $hn = $TH = $A[0]; $TQ = $A[1]; $q = 0; # reset $ff *= -1; # flipflop # and print them out. $loadratio = $A[6] / $A[5]; $used = $A[8]; $total = $A[7]; if ($A[8] =~ /G/) {$used =~ tr/G//d;} if ($A[7] =~ /G/) {$total =~ tr/G//d;} $ramratio = $used / $total; $ul = " "; if ($A[8] =~ /M/) {$ramratio = 0.1;} if ($loadratio < $optcpuload && $ramratio < $saferamload) {$ul = "-"} if ($loadratio > 1.1) { $ul = "+";} printf "\n%-13s %s %5s / %3s %7s /%7s ", $A[0], $ul, $A[6], $A[5], $A[8], $A[7]; } elsif ($A[0] =~ /compute/) { # then dump all the prepped values $ff = 1; # flipflop } elsif ($A[0] eq "") { # one of the Q lines; process # mod $A[3] to remove the 1st '0/' - we never use/mod it $A[3] = substr($A[3],2); if ($A[4] eq "") { printf "%s(%s)" , $A[1], $A[3];} else { printf "%s(%s)[%s]" ,$A[1], $A[3], $A[4];} # and append the user info based on Q, so each Q is also # followed by the jobs running in that Q # so have to create a struct that is indexed: # hostname -> Q -> user -> total jobs $hst = $TH; #=host $hq = $A[1]; #=Q, get keys and print as above; foreach $usr (sort keys %{$hun{$hst}{$hq}}) { print " $usr,$hun{$hst}{$hq}{$usr} "; } print " "; } }