David A. Harding on 19 Jun 2008 22:08:39 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Load killer ?


On Thu, Jun 19, 2008 at 11:15:42PM -0400, Glenn Kelley wrote:
> I am wondering if anyone can help me here...
> [...]
> when this service goes over say 9 on load we want to kill it
> and restart

Your program was a good start.  I cleaned it up and made it loop:

  #!/usr/bin/perl -w
  use strict;
  
  open(LOAD, "/proc/loadavg") or die "couldn't open /proc/loadavg: $!\n";
  
  $_ = <LOAD>;   
  s/^(.*?) .*/$1/;
  
  if ( $_ > 9 ) {
          print "The Enterprise, NCC-1701D, may not go faster than warp 10.\n"
	  # (And if a Voyager shuttle goes warp 10, you get one crappy episode.)
          ##`/sbin/service httpd restart`;
          }
  
  sleep 1;  # NB: The kernel won't update the loadavg more than once a second
  exec $0;   

You can stop it from looping by pressing control-c.

I suggest that you consider turning off Apache when the load is above 9
and don't turn it back on until the load drops below 9.

-Dave
-- 
David A. Harding            Website:  http://dtrt.org/
1 (609) 997-0765              Email:  dave@dtrt.org
                        Jabber/XMPP:  dharding@jabber.org
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug