Hi monks
Following on a past thread, I created a log follower. The problem is that it is a cpu hog, and robs the processor from doing real work. Given the following log file monitor, can anyone check this over, and suggest a more efficient way to do this.
#!/usr/local/bin/perl use strict; my (@list) #DRACSTAT is nothing more than a text file which is appended to everyt +ime a job is # launched, it gives information about the type of job, where it was r +un, etc. chdir(); open (DRACSTAT, "<.dractrack") or die "Can't open drackstat.."; while (<DRACSTAT>){ chomp $_; push (@list, $_); } close DRACSTAT; # For each line run the log checker. Ideally, I would do this in parr +allel for # each item for (my $i=0; $i<@list; $i++){ &CheckStat($list[$i]); chdir(); open (DRACNEW, ">>.dracnew") or die "I think dracktrack is running"; # as you get done remove that item from the list.. for (my $j=$i; $j+1<@list; $j++){ print DRACNEW "$list[$j+1]\n"; print "$list[$j+1]\n"; } rename (".dracnew", ".dractrack") or die "Can't replace .dracktrack. +."; } sub CheckStat { my (%drac, @stages, @lstage); my $tmp = shift; # this is the line from DRACSTAT ($drac{Type},$drac{primary},$drac{rundir},$drac{printfile},$drac{hos +tname}) = split / /, $tmp , 5; chdir($drac{rundir}); # This just gets the total number of stages in a particular job open (STAGES, "jxrun.stg") or die "Can't open jxrun.stg"; while (<STAGES>){ chomp $_; @stages = split /\b/, $_; } close STAGES; my $percomp = 0; while ($percomp != 100){ # This is the actual logfile which we are continually monitoring.. open (LOGFILE, "<$drac{printfile}"."."."log") or die "Can't open $ +drac{printfile}.log"; while(<LOGFILE>){ chomp $_; next if ($_ !~ m/AT STAGE:/); @lstage = split /\s+/, $_; } close LOGFILE; my $percomp = ($lstage[3]/$stages[8])*100; # Give'm stats - I don't like the /r but it works -- any better i +deas? if ($percomp == 100){ print "\n$drac{Type} job $drac{primary} on $drac{hostname} -- DO +NE\n"; return; } else { print "Cell: $drac{primary} Verifying: $drac{type} Total Stages: + $stages[8] Number complete: $lstage[3] -- "; printf ("%2.2f\%\r", $percomp); } } }
Thanks much for your infinite wisdom:)

Rhodium

The <it>seeker</it> of perl wisdom.


In reply to Is this the most efficient way to monitor log files.. by Rhodium

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.