I am using
this application to capture, log, and graph out ethernet utilization information on a couple network devices at work. The application collects data at five minute intervals and prints out the result from each "run" to the logfile.
Initially I had it print out each run line (with data) to the console when I was building the tool (so I could watch it), but now I am using a logfile so that I can do weekly/monthly reports etc. The application creates a new logfile for each day at 8am and will continue to run till 5pm and then exit. Here is a snippet of log information:
Begin data collection for 0.0.0.0 - Runs: 108
Starting run 1\108 - In: 0.00 Out: 0.00 Time: 8:00
Starting run 2\108 - In: 0.05 Out: 0.10 Time: 8:05
...
Starting run 108\108 - In: 0.27 Out: 0.01 Time: 16:55
Utilization Graph Completed - Run length: 9 hours
Generation complete.
Now when I go and look at the current logfile for the day, I notice that no data actually gets printed to the file until run #74 (always) for each device (all seperate scripts in seperate dir's, with different logfiles). It prints up to the same point on line #74 and then doesn't print the remaining log info until program exit.
It looks to me like its waiting until some kind of buffer reaches a certain point, then dumps it out, then continues without printing until my program exists. In my current program I am writing to the logs like this:
open(LOG, "+>$logFile") || die "Can't open logfile: ($!)\n";
print LOG "Begin data collection for $host - Runs: $numRuns\n";
for ($run = 1; $run <= $numRuns; $run++) {
print LOG "Starting run $run\\$numRuns - ";
snmpRun();
unless ($run == $numRuns) { sleep("$pauseTime"); }
}
This prints out the first line of my logfile, then calls the snmpRun sub from the loop. Inside my sub is this bit of code:
sub snmpRun {
...
print LOG "In: $octetInUtil Out: $octetOutUtil Time: $time\n";
...
}
Is there another way to do this so that the data does get written to the file as it hits the print lines? This isn't a big deal, but I'm curious to know.
djw