#!/usr/bin/perl # systemstatus.cgi = shows a servers usage via CGI and a web browser # Copyright (c) 1999 Jeremy C. Reed. All Rights Reserved. # license change 2001 # This program is free software; you may redistribute it and/or modify # it as long as you retain this entire copyright and notice. # This software is provided as is and the author is not liable # for anything resulting from its use. # was converting GMT to local use Time::Local; #*timelocal::cheat = \&Time::Local::cheat; #$time_difference = 28800; ## seconds from GMT $systemstatus_cgi_version = "0.21"; $html_refresh = ''; ## use a number for seconds for html meta refresh $bgcolor='WHITE'; $title_color = 'GREEN'; $text_color = 'BLACK'; $link_color = 'BLUE'; $vlink_color = 'PURPLE'; $warn_color = 'ORANGE'; $danger_color = 'RED'; $fixed_font_face = 'Clean, Fixed, Courier New, Courier, Terminal, Screen'; #$httpd_log_file = "/var/log/apache-httpd/access_log"; $httpd_log_file = '/var/log/boa/access_log'; $tail_amt = 250; ## set to check for last amount from httpd_log_file if ($html_refresh) { $meta_tag = ""; } @months = ("January","February","March","April","May","June","July","August","September","October","November","December"); @short_months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); ($c_seconds,$c_minutes,$c_hour,$c_day,$c_month,$c_year,$c_wday,$c_yday,$c_isdst) = localtime(time); ## get current time and date info $c_year = 1900 + $c_year; if ($c_minutes < 10) { $c_minutes = "0$c_minutes"; } print "Content-type: text/html\n\n"; print qq{
The source code is freely available.
http://www.reedmedia.net/projects/systemstatus/
Version $systemstatus_cgi_version
};
## end of main
sub uptime {
chop($uptime = `uptime`);
$uptime =~ s/\t/ /g;
$uptime =~ s/\s/\ \;/g;
print qq{
System status
$uptime
};
} ## uptime
sub www_status {
$total = 0;
$today_requests = 0;
$month_requests = 0;
$currently = "$short_months[$c_month]\/$c_year";
open (LOG, "$httpd_log_file") || &error ("Could not open $httpd_log_file file\n");
while ($line = \n";
} ## display_free
sub free_disk_space {
@df = `df -h`;
$title_line = shift @df;
$title_line =~ s/\t/ /g;
$title_line =~ s/\s/\ \;/g;
print "\n";
print "$title_line
"
}
else {
$requests_per_day = "This is less than one request per day.
";
}
}
print qq{
$ENV{SERVER_NAME} HTTPD Status
Since $timestamp ($total_days days ago), the web server has had $total requests.
$requests_per_day
Today, it already has $today_requests requests.
And, this month the server has had $month_requests requests.
};
} ## www_status
sub display_free {
@info = `free -o`;
$line = shift @info; ## get rid of header
$line = shift @info;
my ($type, $total, $used, $free, $shared, $buffers, $cached) =
split(/\s+/, $line);
$capacity = (($used/$total) * 100);
if ($capacity < 50) {
$color = $text_color;
} elsif ($capacity < 90) {
$color = $warn_color;
} else {
$color = $danger_color;
}
print "\n";
print "Memory Usage ";
printf ("%3.0f%% memory used,", $capacity);
print qq{
$free K free
(shared: $shared, buffers: $buffers, cached: $cached).
};
$line = shift @info;
my ($type, $total, $used, $free, $shared, $buffers, $cached) =
split(/\s+/, $line);
$capacity = (($used/$total) * 100);
if ($capacity < 50) {
$color = $text_color;
} elsif ($capacity < 90) {
$color = $warn_color;
} else {
$color = $danger_color;
}
print "Swap Usage ";
printf ("%3.0f%% used", $capacity);
print ", $free K free.
\n";
foreach $line (@df) {
my ($dev, $size, $used, $avail, $capacity, $mount) = split(/\s+/, $line);
$line =~ s/\t/ /g;
$line =~ s/\s/\ \;/g;
$capacity =~ s/%//;
if ($capacity < 50) {
$color = $text_color;
} elsif ($capacity < 90) {
$color = $warn_color;
} else {
$color = $danger_color;
}
$line =~ s/$capacity%/\$capacity%\<\/FONT\>/;
print "$line
\n";
} ## for each line
print "
\n";
} ## free_disk_space
sub who {
@who = `w`;
shift @who;
$title_line = shift @who;
$title_line =~ s/\t/ /g;
$title_line =~ s/\s/\ \;/g;
print "\n";
print "$title_line\n";
foreach $w (@who) {
## commented out code is for setting up warning for idle time over 4 hours
## but not done because havne't parsed info correctly
# ($user, $tty, $from, $login, $idle, $jcpu, $pcpu, $what) =
# split (/\s\s+/, $w);
# $idle =~ /(\d+)\:(\d+)(.)$/;
# $sec_or_min = $3;
# print "$sec_or_min SM\n";
$w =~ s/\t/ /g;
$w =~ s/\s/\ \;/g;
print "
\n$w\n";
# print "idle: $idle
\n";
}
} ## who
sub processes {
open (PS,"/bin/ps aux | /usr/bin/sort -rn +4 |");
@ps_info =
};
foreach $line (@ps_info) {
$line =~ s/\t/ /g;
$line =~ s/\s/\ \;/g;
print "$line
\n";
}
print "
\n";
} ## processes
sub error {
print "$_[0]
\n";
exit;
}