LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   server load script cgi (https://www.linuxquestions.org/questions/programming-9/server-load-script-cgi-336015/)

newuser455 06-22-2005 03:16 AM

server load script cgi
 
The script below will display your server uptime and load in text. Does anyone know how I could modify it so that it displays the load as a graphical status bar?

Code:

#!/usr/bin/perl --
print "content-type:text/html\n\n";
 
my $html = `uptime`;
$html =~ s/\n+//g;
if ($ENV{QUERY_STRING} =~ /js/){ print qq~uptime=('$html'); document.write(uptime);~; }
else{ print $html; }
exit;


macemoneta 06-22-2005 07:57 PM

Well, you could modify the bwbar to display load instead of network usage.

You can also create a bar-like chart using just HTML. For example, this shell CGI script extract is one I created for status on my firewall, which is then included by the target page:

Code:

#-----------------------------------------------------------
# Create a bar chart to relate the rolling number of entries
# in the datafile to virus/hack activity
#-----------------------------------------------------------
ENTRIES=`/bin/cat /var/www/html/datafile | /usr/bin/wc -l`
REALENTRIES=$ENTRIES
if [ $ENTRIES -gt 450 ]
then
  ENTRIES=450
fi
PAD=$((450-$ENTRIES))
BAR="darkgreen"
if [ $ENTRIES -ge 180 ]
then
  BAR="yellow"
fi
if [ $ENTRIES -ge 250 ]
then
  BAR="darkred"
fi
echo "<font color=blue>"                                                        > /var/www/html/virus.html
echo "72-hour rolling automatic firewall subnet block list summary:"          >> /var/www/html/virus.html
echo "</font>"                                                                >> /var/www/html/virus.html
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>"                            >> /var/www/html/virus.html
echo "<TR bgcolor=#AAAAAA><TH align=left WIDTH=150>Virus/Hack Activity:</TH>"  >> /var/www/html/virus.html
echo "  <TH align=left WIDTH=150><font color=darkgreen>Low</TH>"              >> /var/www/html/virus.html
echo "  <TH align=left WIDTH=150><font color=yellow>Normal</TH>"              >> /var/www/html/virus.html
echo "  <TH align=left WIDTH=150><font color=darkred>High</TH>"              >> /var/www/html/virus.html
echo "</TR>"                                                                  >> /var/www/html/virus.html
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>"                            >> /var/www/html/virus.html
echo "<TR bgcolor=#AAAAAA><TH align=right WIDTH=150>${REALENTRIES}&nbsp;</TH>" >> /var/www/html/virus.html
echo "  <TH bgcolor=${BAR} align=left WIDTH=${ENTRIES}>&nbsp;</TH>"          >> /var/www/html/virus.html
echo "  <TH bgcolor=#AAAAAA align=left WIDTH=${PAD}></TH>"                    >> /var/www/html/virus.html
echo "</TR>"                                                                  >> /var/www/html/virus.html
echo "</TABLE>"                                                                >> /var/www/html/virus.html
/bin/chmod 644 /var/www/html/virus.html
/bin/chown nobody.nobody /var/www/html/virus.html

You can see the result here. The bar changes from green to yellow to red as thresholds are passed, and the bar gets longer. It's a very simplistic way of doing it, but it gets the job done.


All times are GMT -5. The time now is 08:34 PM.