Merge pull request #5134 from solgenomics/topic/fix_seedlot_search
[sgn.git] / cgi-bin / about / cluster_services.pl
blobaf8596024e28d1bf8bc41dbd42e499ec151be95a
1 #!/usr/bin/perl
4 use CGI;
5 my $cgi = new CGI;
7 my $mode = $cgi->param('mode');
10 my $PROCESSORS = 16*4;
11 my $THRESHOLD = 80; #Percent CPU to consider processor "used"
13 my @services = ();
15 for(my $i=1; $i<=8; $i++){
16 push(@services, "/var/lib/spong/database/blade$i.cluster.sgn/services");
17 push(@services, "/var/lib/spong/database/shiv$i.cluster.sgn/services");
21 my %cpu_files = ();
22 foreach(@services){
23 my ($cpu_file) = `ls $_/cpu*`;
24 my ($machine) = /(shiv\d+)/;
25 ($machine) = /(blade\d+)/ unless $machine;
26 chomp $cpu_file;
27 $cpu_files{$machine} = $cpu_file;
30 my $total_used = 0;
31 my $web_html = "<table border=\"0\" cellspacing=\"5\">";
33 foreach my $mach ( sort keys %cpu_files ) {
34 my $cpu_file = $cpu_files{$mach};
35 $web_html .= "<tr> <td style=\"vertical-align:top\">";
36 print "\n$mach" unless $mode eq "html";
37 $web_html .= "$mach</td><td style=\"vertical-align:top;width:100px\">";
38 open(FH, $cpu_file);
39 my $used = 0;
40 my $content = "";
41 my $row_html = "";
42 while(<FH>){
43 my ($pid, $cpu, $status, $time, $command) =
44 /(\d+)\s+([0-9\.]+)\s+(\w+)\s+\S+\s+([0-9\:\-]+)\s+(.*)$/;
45 next unless $pid;
46 if($cpu >= $THRESHOLD){
47 $content .= "\n\t$pid\t$cpu\t$time\t$command";
49 #Style command for web display:
50 $command =~ s/^(\S*?)([^\/\s]+)\s/$1<span style="color:black;font-weight:bold">$2<\/span> /; #embolden the name of the program
51 $command = "<span style=\"font-size:0.9em;color:#555\">$command</span>"; #default stylin'
53 $row_html .= "$pid&nbsp;&nbsp;$cpu&nbsp;&nbsp;$time&nbsp;&nbsp;$command<br />";
54 $used++;
55 $total_used++;
58 $row_html .= "<span style=\"color:#555\">Available</span>" unless $used;
59 $web_html .= "&nbsp;$used&nbsp;in&nbsp;use&nbsp;&nbsp;</td><td style=\"vertical-align:top\">$row_html</td></tr>";
60 # $content .= "\n" unless $used;
61 print "\t$used/4 processors in use" unless $mode eq "html";
62 print $content unless $mode eq "html";
64 $web_html .= "</table>";
67 my $available = ($PROCESSORS - $total_used);
69 $web_html = <<HTML;
71 <html>
72 <head>
73 <title>Cluster QuickView</title>
75 </head>
76 <body>
77 <h2>Cluster QuickView</h2>
78 <!--
79 <a href="http://rubisco.sgn.cornell.edu/spong-cgi/www-spong.cgi">&lt;&lt;Back to Spong</a><br />
80 -->
81 <span style="font-size:1.05em; color:#222">
82 Total processors used: <b style="color:#411">$total_used</b> &nbsp;&nbsp;&nbsp; Available: <b style="color:#141">$available</b>
83 <br />
84 </span>
85 <br />
86 $web_html
87 <br />
88 <a href="server_room.pl" target="_TOP">&lt;&lt; Back</a>
89 </body>
90 </html>
91 HTML
94 if($mode eq "html"){
95 print $web_html;
97 else{
98 print "\n";
99 print "\nTotal Processors used: $total_used\tAvailable: $available";
100 print "\n";