Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w # Load - current server load print "Content-type: text/html\n\n"; require 'timelocal.pl'; $Now=time; @Now=localtime(time); $Now=&timelocal(@Now); if ($ENV{PATH_INFO} eq "") { $Log = "/usr/local/apache/access_log"; } else { $Log=$ENV{PATH_INFO}; } $Last=500; $Steps=10; open (h,"$Log") || die "Could not open access log ($!)\n"; print <<EOM; <META HTTP-EQUIV="Refresh" CONTENT=15> <TITLE> $ENV{SERVER_NAME} HTTPD Load </TITLE> <H1> Current HTTPD Load of <A HREF=/>$ENV{SERVER_NAME}</A><HR></H1> EOM # print "Logfile: $Log\n"; $from=0; LINE: while (<h>) { $line=$_; ($host, $rfc931, $authuser, $timestamp, $request, $status, $by +tes) = /^(\S+) (\S+) (\S+) \[(.+)\] \"(.+)\" (\S+) (\S+)\s/; if (!($host && $rfc931 && $authuser && $timestamp && $request && $status)) { # print(STDERR "$.:$line"); $bad++; next LINE; } $TotalReq++; $TotalBytes+=$bytes; $_ = $timestamp; ($d,$m,$y,$hh,$mm,$ss) = m|(\d+)/(\w\w\w)/(\d+):(\d+):(\d+):(\ +d+).*|; $m=index("JanFebMarAprMayJunJulAugSepOctNovDec",$m)/3; $iTime= &timelocal($ss,$mm,$hh,$d,$m,$y-1900); if ($from == 0) { $from=$iTime; $diff=$Now-$iTime; $Resolution=int($diff/$Steps); } $diff=$Now-$iTime; $iDiff=int((1.0*$diff/$Resolution)+.5); $req[$iDiff]++; $bytes[$iDiff]+=$bytes; } close h; # print $bad . "-". $TotalReq; print "<TABLE BORDER=0>\n"; print "<TR><TH>seconds</TH><TH>reqests</TH><TH>Kbytes</TH><TH>requ +ests chart</TH></TR>\n"; for ($i=0; $i<=$#req; $i++) { $r = $i*$Resolution; $q = $req[$i]; $w = $q*200.*$Steps/$TotalReq; $b = int ($bytes[$i]/1024); print "<TR ALIGN=RIGHT><TD>$r</TD><TD>$q</TD><TD>$b</TD><TD AL +IGN=LEFT><HR WIDTH=$w SIZE=14 ALIGN=LEFT></TD></TR>\n"; A } print "</TABLE><PRE>\n"; $fullDiff=($Now-$from); $fullDiffMin=$fullDiff/60; $fullRPH=$TotalReq/$fullDiff*3600.; $fullCPS=$TotalBytes/$fullDiff*11./1024.; $lastRPH=$req[0]/$Resolution*3600; $lastCPS=$bytes[0]/$Resolution*11./1024.; $lastDiffMin=$Resolution/60.; print "<B>"; printf "Load in the last %4.1f minutes: %5.0f requests/day, %5.2f +kbps.\n", $fullDiffMin,$fullRPH*24,$fullCPS; printf "Load in the last %4.1f minutes: %5.0f requests/day, %5.2f +kbps.\n", $lastDiffMin, $lastRPH*24, $lastCPS; print `uptime`; #print "\nTail of server log:\n</B>"; #print `tail $Log`; print <<EOM; </B></PRE> <HR> EOM

In reply to webload.pl by JSchmitz

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found