Hi all, thanks for your help.

I've got a script (below) that opens an HTTP port (44000) for reporting some stats about the machine so a monitoring machine will call me if there is a problem.

I've got two problems with the script: 1. It always returns a complaint that the partition being checked is full (or BAD, in simple terms the monitor can understand). I don't see why this would be the case. 2. It will respond fine for a few times, then requests will time out. A portscan of the machine sees that port 44000 is still open, but it won't return a report. The HTTP daemon script continues to run. It's not using over-much memory or CPU in this state (normal amounts).

(note: yeah, it's a junk script...I always write like this to start then go back and clean up)

Here is the simple conf file:

# Location of reportsock text file $rp_loc = '/tmp/reportsock'; # Command to get information from 'top' $top_cmd = 'top -b -n 1 | head -7'; # Command to get information for disk usage $disk_cmd = 'df -h'; # Max partition usage allowed $max_hd = 95; # Max load allowed $max_load = 1; # Least CPU idle allowed $least_cpuidle = 80;
Here is the script itself:
#!/usr/bin/perl use HTTP::Daemon; use HTTP::Status; my $d = new HTTP::Daemon LocalAddr => '10.0.1.1', LocalPort => 44000; print "Starting: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { print "Got connection\n"; if ($r->method eq 'GET') { $c->send_file_response("/tmp/reportsock"); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
Here is the script that creates a report:
#!/usr/bin/perl # Read text as block $/ = ''; # Include configuration file do '/home/reportsock/reportsock.conf'; ########## Section one - load, memory and swap ########## # Get results of the top command (from conf file) $_ = `$top_cmd`; # Get load average m/(\d\.\d\d).*?(\d\.\d\d).*?(\d\.\d\d)/; my $loadavg1 = $1; my $loadavg2 = $2; my $loadavg3 = $3; # Get CPU idle m/(\d+\.\d)% idle/; my $cpuidle = $1; # Get memory stats m/Mem:\s+(\d+)K.*?(\d+)K.*?(\d+)K/; my $memtotal = $1; my $memused = $2; my $memfree = $3; # Get Swap stats m/Swap:\s+(\d+)K.*?(\d+)K.*?(\d+)K/; my $swaptotal = $1; my $swapused = $2; my $swapfree = $3; ######### Section two - disk usage ######### @lines = `$disk_cmd`; ########## Section three - report ########## open(REPORT, ">$rp_loc") or die ("Could not open $rp_loc for writing") +; print REPORT "Load\t$loadavg1, $loadavg2, $loadavg3\n"; print REPORT "CPU\t$cpuidle%\n"; print REPORT "Memory\t$memfree + $memused = $memtotal\n"; print REPORT "Swap\t$swapfree + $swapused = $swaptotal\n"; foreach $foo (@lines) { $count++; $foo =~ m/\/dev\/(hd..).*?$/; print REPORT "$1\t"; $partname = $1; $foo =~ m/\/dev\/.*?(\d+)%/; print REPORT "$1%\n"; $part_usage = $1; if ($part_usage > $max_hd) { print REPORT "$partname OK " } else { print REPORT "$partname BAD $1/$max_hd "; } } if ($loadavg1 < $max_load) { print REPORT "Load OK "; } else { print REPORT "Load BAD $loadavg1/$max_load "; } if ($cpuidle > $least_cpuidle) { print REPORT "CPU OK "; } else { print REPORT "CPU BAD $cpuidle "; } if ($swapused < $swapfree) { print REPORT "Swap OK "; } else { print REPORT "Swap BAD $swapfree/$swaptotal "; } close(REPORT);

In reply to Reporting script by Kickstart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.