[ic] mod_interchange and Apache MaxClients
Ron Phipps
rphipps at reliant-solutions.com
Thu Nov 17 03:20:27 EST 2005
> From: interchange-users-bounces at icdevgroup.org
[mailto:interchange-users-
> bounces at icdevgroup.org] On Behalf Of John1
> Sent: Wednesday, November 16, 2005 5:03 PM
> Fantastic, thanks Ron, just implemented it! It occurs to me that it
may
> be
> useful to call a few system commands before restarting interchange,
and to
> add the output from these commands to the alert e-mail sent.
Thanks for the commands. Here is the updated script:
#!/usr/bin/perl
use LWP;
my $url = 'http://www.yoursite.com/checkic.html';
## CMD to return report values
my $REPORT_COMMAND = "/root/scripts/iccheckcommands.sh";
## CMD to restart
my $IC_COMMAND = "/root/scripts/icrestart.sh";
## Where is sendmail?
my $SENDMAIL_CMD = "/usr/sbin/sendmail";
## what should the subject be?
my $MAIL_SUBJECT="Alert!";
## who should we send from?
my $MAIL_SENDER="root\@yoursite.com";
## what mail account should we alert to?
my $MAIL_RECEIVER = "alerts\@yoursite.com";
my $browser = LWP::UserAgent->new;
$browser->timeout(30);
my $count = 0;
my $up = 0;
while ($count <= 4) {
my $response = $browser->get($url);
if ($response->content =~ m/UP/) {
$count = 5;
$up = 1;
}
$count++;
}
if ($up == 1) {
} else {
my $output = `$REPORT_COMMAND`;
system $IC_COMMAND;
mail_admin("IC restarted! $output");
print "IC restarted!";
}
sub mail_admin {
my $mail = "From: $MAIL_SENDER <>\nTo: $MAIL_RECEIVER\nSubject:
$MAIL_SUBJECT\nX-Priority: 1\n\n$_[0]\n";
print STDERR $mail if $DEBUG;
return if $NO_MAIL;
open SENDMAIL, "| $SENDMAIL_CMD -t" and
print SENDMAIL $mail and
close SENDMAIL or
die "Failed to send alert mail to $MAIL_SENDER: $!";
}
Create a file called iccheckcommands.sh with the following contents and
update $REPORT_COMMAND with the path to this file, make sure it's
executable:
#!/bin/bash
echo ""
echo ""
date
echo ""
echo "Connections to Apache port 80"
netstat -nt | grep :80 | wc -l
echo "Connections to Apache port 443"
netstat -nt | grep :443 | wc -l
echo ""
echo "Apache processes"
ps -elf | grep -c httpd
echo ""
echo "IC processes"
ps -elf | grep -c live48
echo ""
echo "MySQL processes"
ps -elf | grep -c mysqld
echo ""
echo "Number of connections each IP has"
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Please post if you add more commands that you find useful so that our
emails contain the same information.
Thanks,
-Ron
More information about the interchange-users
mailing list