[LON-CAPA-cvs] cvs: modules /gerd monitor.pl
www
lon-capa-cvs@mail.lon-capa.org
Mon, 16 Feb 2004 21:23:40 -0000
www Mon Feb 16 16:23:40 2004 EDT
Added files:
/modules/gerd monitor.pl
Log:
Little script to show users over time in an active showcase
Index: modules/gerd/monitor.pl
+++ modules/gerd/monitor.pl
#!/usr/bin/perl
$|=1;
# "Life view" of LON-CAPA cluster
# $Id: monitor.pl,v 1.1 2004/02/16 21:23:40 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA 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.
#
# LON-CAPA 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 LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
use POSIX;
my %totals=();
my %overtime=();
my %timeidx=();
my %monitoredhosts=(
'msua1' => 'msu:Michigan State University, Server 1',
'msua2' => 'msu:Michigan State University, Server 2',
'msua3' => 'msu:Michigan State University, Server 3',
'msua4' => 'msu:Michigan State University, Server 4',
'msua5' => 'msu:Michigan State University, Server 5',
'msuzzz' => 'loncapa:System-Wide Use',
'sfua1' => 'sfu:Simon Fraser University, Server 1',
'sfua2' => 'sfu:Simon Fraser University, Server 2',
'sfuzzz' => 'loncapa:System-Wide Use',
'oucapa7' => 'ohiou:Ohio University, Server 1',
#'oucapa8' => 'ohiou:Ohio University, Server 2',
'oucapa10' => 'ohiou:Ohio University, Server 2',
'oucapazzz' => 'loncapa:System-Wide Use',
'fsua1' => 'fsu:Florida State University, Server 1',
'fsua2' => 'fsu:Florida State University, Server 2',
'fsuzzz' => 'loncapa:System-Wide Use',
'sca1' => 'sc:University of South Carolina',
'udel1' => 'udel:University of Delaware',
'ndsul1' => 'ndsu:North Dakota State University',
'csml1' => 'csm:Colorado School of Mines',
'csmzzz' => 'loncapa:System Wide',
'naul0' => 'nau:Northern Arizona University',
'nauzzz' => 'loncapa:System-Wide Use',
'cmichl1' => 'cmich:Central Michigan University',
'capa1' => 'uwsp:University of Wisconsin - Stevens Point',
#'bsul1' => 'bsu:Ball State University',
'tmcc1' => 'tmcc:Truckee Meadows Community College',
'tmcczzz' => 'loncapa:System-Wide Use',
);
my @monitored=sort keys %monitoredhosts;
# ========================================================= Produce a green bar
sub bar {
my $parm=shift;
my $number=int($parm+0.5);
my $return='';
$return= "<td bgcolor='#999999'><table cellpadding='0' cellspacing='0'><tr><td bgcolor='#225522'><font color='#225522' size='1'>";
for (my $i=0;$i<$number;$i++) {
$return.= "+";
}
$return.="</font></td><td> </td></tr></table></td>";
return $return;
}
# ========================================================= Get lines from file
sub getlines {
my ($server,$file)=@_;
my @output=();
open (DFH,"tail -n100 /home/monitor/clusterstatus/$server/$file.dat|");
@output=<DFH>;
close(DFH);
return @output;
}
# =============================================================================
# =============================================================================
# Main program
#
# ========================================================= Get form parameters
my $buffer;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs=split(/&/,$buffer);
my $pair; my $name; my $value;
undef %FORM;
%FORM=();
foreach $pair (@pairs) {
($name,$value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$FORM{$name}=$value;
}
# =============================================================== Add up totals
# ================================================================ Display type
my $display=$FORM{'display'};
unless ($display) { $display=0; }
if ($display>$#monitored) { $display=0; }
my $host=@monitored[$display];
my ($domain,$description)=split(/\:/,$monitoredhosts{$host});
$display++;
# ================================================================ Send Headers
print "Content-type: text/html\n\n".
"<html><head><title>LON-CAPA Cluster User Statistics</title></head><body bgcolor='#FFFFFF'>\n";
unless ($domain eq 'loncapa') {
print "<img src='/adm/lonDomLogos/$domain.gif' align='right' />";
} else {
print "<img src='/adm/lonIcons/lonlogos.gif' align='right' />";
}
print "<form name='status' method='post'><input type='hidden' name='display' value='$display' />\n";
# =================================================================== Get data
my $max=0;
my %timescnt=();
my %timessum=();
my %timesabs=();
foreach (keys %FORM) {
if ($_=~/^timesabs_(.*)$/) {
$timesabs{$1}=$FORM{$_};
}
if ($_=~/^overtime_(.+)$/) {
$overtime{$1}=$FORM{$_};
}
}
unless ($host=~/zzz$/) {
foreach (&getlines($host,'users')) {
my ($time,$values)=split(/\:/,$_);
$values=~/Overall_all_Active\=(\d+)\&/;
my $value=$1;
if ($value>$max) { $max=$value; }
$FORM{'add_'.$host}=$value;
my $timeStr = strftime("%a %I %P", localtime($time));
$timesabs{$timeStr}=$time;
$timescnt{$timeStr}++;
$timessum{$timeStr}+=$value;
}
} else {
foreach (keys %overtime) {
my $timeStr=(split(/\&/,$_))[1];
$timescnt{$timeStr}=1;
$timessum{$timeStr}+=$overtime{$_};
if ($timessum{$timeStr}>$max) { $max=$timessum{$timeStr}; }
}
}
my $total=0;
foreach (keys %FORM) {
if ($_=~/^add_/) {
$total+=$FORM{$_};
}
}
print "<font size='4' color='green' face='arial'>LON-CAPA System-Wide Active Users: $total</font><br />".
"<font size='3' face='arial'><b>Graph for ".$description."</b></font>\n\n";
if ($max) {
# ==================================================================== Displays
print('<table cellpadding="1" cellspacing="0">');
foreach (sort { $timesabs{$b}<=>$timesabs{$a} } keys %timesabs) {
my $data=($timessum{$_}?int($timessum{$_}/$timescnt{$_}):0);
unless ($host=~/zzz$/) { $overtime{$host.'&'.$_}=$data; }
print "\n<tr><td bgcolor='#FFFFAA'><font size='2'><nobr>".$_.'</nobr></font></td><td bgcolor="#BBBBFF"><font size="2">'.$data.'</font></td>'.&bar(100*$data/$max).'</tr>';
}
print('</table>'."\n\n");
} else {
print '<br />No active logins.';
}
# ================================================================ Store totals
foreach (@monitored) {
print "\n".'<input type="hidden" name="add_'.$_.'" value="'.$FORM{'add_'.$_}.'" />';
}
foreach (keys %overtime) {
print "\n".'<input type="hidden" name="overtime_'.$_.'" value="'.$overtime{$_}.'" />';
}
foreach (keys %timesabs) {
print "\n".'<input type="hidden" name="timesabs_'.$_.'" value="'.$timesabs{$_}.'" />';
}
# ============================================================== Close, refresh
print "</form><script>";
print "setTimeout('document.status.submit()',20000);\n";
print "</script></body></html>";
exit 0;