• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: No instance found alert ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No instance found alert ?


  • Subject: Re: No instance found alert ?
  • From: Mike Schrag <email@hidden>
  • Date: Wed, 11 Apr 2007 14:39:02 -0400

That's a clever idea ... Does that CGI script fire in the case of a request timeout that causes a No instance available even if the user has dropped their connection before the request actually times out?

ms

On Apr 11, 2007, at 2:28 PM, Zak Burke wrote:

James Cicenia wrote on 4/11/07 10:06 AM:
Anyone know of a good cheap service to monitor my web apps when they
stop responding... i.e, no instance available, etc.

My Adaptor Settings/Redirection URL is a CGI script that sends email (see below). You can also set up a cron-job to periodically hit your site and, e.g. create a socket connection on ports 80 and 443 to make sure httpd is up (further below), or point curl at your site to make you're not seeing "no instance available" in your responses (i.e. httpd is up, but your app is down).


For a one-time $36 fee www.freeshell.org will give you a unix shell account that, I believe, has cron access.

zak.




#!/usr/bin/perl -w

# --
# -- KB error page, displayed by WO when our application is unavailable,
# -- sends email to the webmaster if $ENV{DOCUMENT_ROOT}/ i3pkb_error is
# -- more than 10 minutes old.
# --
# -- 2005-10-25, email@hidden
# --


use strict;



# recipient of email sent by this script
use constant RECIPIENT => "webmaster\@thei3p.org";

# sender of email sent by this script
use constant SENDER    => "webmaster\@thei3p.org";

# gateway to send mail through
use constant MAILHOST  => "mail.thei3p.org";

# full path to error file
# must be owned by the webserver user and chmod 700
use constant ERROR_FILE => "$ENV{'DOCUMENT_ROOT'}/i3pkb_error";

# --
# -- nothing to configure below
# --





BEGIN
{
    use strict;
    use CGI;
    use Email::Send;
    use File::stat;
}


main();

sub main
{

    my ($cgi, $message, $content, $submitter, @list) = undef;

    # send mail if it's been 10 minutes since the last time
    # this error was recorded
    my $stat = lstat(ERROR_FILE);

    if ($stat && (time() - $stat->mtime) > 600) {

$message .= "The application i3pkb on $ENV{'SERVER_NAME'} is not responding and must be restarted." ;

# message to registrar
send_mail($message, (time() - $stat->mtime), RECIPIENT, SENDER);


    }

    # reset the error timestamp
    my $error_file = ERROR_FILE;
    `touch $error_file`;


# display error page in browser $cgi = CGI->new(); print $cgi->header(); print template();

}



#
# send_mail
# send a message
sub send_mail
{
        my ($message, $age, $recipient, $sender) = @_;

    my $error_file = ERROR_FILE;

    send SMTP => <<"EOT", MAILHOST;
To: $recipient
From: $sender
Subject: ERROR: i3pkb on $ENV{'SERVER_NAME'} MUST BE RESTARTED

$message

$error_file was $age seconds old.


EOT

}



# --

# --
# -- template
# -- return the WO error page to display in place of the
# -- requested page.
sub template
{
    open FILE, "$ENV{'DOCUMENT_ROOT'}/index.html";
    my @lines = <FILE>;
    close FILE;

    return join "\n", @lines;
}





#!/usr/bin/perl -w

#
# dead simple server monitoring script
# checks whether a TCP socket can be created on a given server:port
# sends mail when a socket connection fails
#
# email@hidden, 2007-02-28
#
#


use strict; use IO::Socket; use Email::Send;

use constant MAIL_SENDER    => "webmaster\@thei3p.org";
use constant MAIL_RECIPIENT => ("webmaster\@thei3p.org");
use constant SMTP_SERVER    => "mail.thei3p.org";


# # hosts # returns a \@list of hosts and their services to monitor sub hosts { my @list;

    # http, https, imaps, smtp
    push @list, new_host("some.host.org", "80");
    push @list, new_host("some.host.org", "443");
    push @list, new_host("some.host.org", "993");
    push @list, new_host("some.host.org", "25");


return \@list; }


# # NOTHING TO CONFIGURE BELOW #



main();

sub main
{
    my ($socket, $status);
    for my $host (@{ hosts() }) {

        print "testing $host->{host}:$host->{port}...\n";

        $socket = IO::Socket::INET->new(
            PeerAddr => $host->{host},
            PeerPort => $host->{port},
            Proto    => 'tcp',
            Type     => SOCK_STREAM,
            Timeout  => 3,
            );

if (! $socket) {
print STDERR "$host->{host}:$host->{port} is unreachable.\n";
message_send("$host->{host}:$host->{port} is unreachable.");
}


    }

}



# --

#
# new_host
# shortcut to create a new hashref of server-name, server-ip and server-port
sub new_host
{
my ($host, $port) = @_;


    return {"host" => $host, "port" => $port};
}



# --

#
# message_send
# send a warning email
sub message_send
{
    my ($subject) = @_;

    for my $recip (MAIL_RECIPIENT)
    {
        my $sender    = MAIL_SENDER;
        send SMTP => <<"EOT", SMTP_SERVER;
To: $recip
From: $sender
Subject: $subject

$subject
EOT
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mdimension.com


This email sent to email@hidden


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: No instance found alert ?
      • From: Zak Burke <email@hidden>
References: 
 >No instance found alert ? (From: James Cicenia <email@hidden>)
 >Re: No instance found alert ? (From: Zak Burke <email@hidden>)

  • Prev by Date: Any docs
  • Next by Date: Re: Updating Nested To-Many Relationship *NOT SOLVED*
  • Previous by thread: Re: No instance found alert ?
  • Next by thread: Re: No instance found alert ?
  • Index(es):
    • Date
    • Thread