LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-22-2005, 04:16 AM   #1
newuser455
Member
 
Registered: May 2004
Location: Texas
Posts: 277

Rep: Reputation: 30
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;
 
Old 06-22-2005, 08:57 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 328Reputation: 328Reputation: 328Reputation: 328
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.

Last edited by macemoneta; 06-22-2005 at 09:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory listing - Calling shell script from a CGI script seran Programming 6 08-12-2005 12:08 AM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 12:43 PM
cgi uaseradd script help newuser455 Programming 3 01-29-2005 07:29 PM
limiting page load frequency with a perl cgi script Metroid Programming 0 12-30-2004 11:33 PM
pipe in a cgi script lukas_z Linux - Software 0 08-10-2003 04:43 PM


All times are GMT -5. The time now is 05:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration