RE: [PHP] Log parsing

From: Date: Sun, 15 Aug 2004 01:43:29 +0000
Subject: RE: [PHP] Log parsing
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-193861@lists.php.net to get a copy of this message
I have got a messy script working, thanks for the help John. It's attached if anyone would mind helping me hack it up. There is also a copy of a sample log file. Watty > -----Original Message----- > From: John Holmes [mailto:holmes072000@charter.net] > Sent: 15 August 2004 01:52 > To: Watty > Cc: php-general@lists.php.net > Subject: Re: [PHP] Log parsing > > Watty wrote: > > > I would like to do some thorough availability reports, so I started by > > writing the result of the bash script to a log file. I want to parse the > > log file to give me availability reports. The log file is in the form: > > 08/14/04 09:10:01 [TAB] S - when the IP > > check returns OK > > 08/14/04 09:10:01 [TAB] U - when the IP need > > to be synchronised > > > > The process does not run when the computer is not on, so that needs to > > be taken into consideration. > > Is there any entry for when the script/computer is started or stopped? > If not, you're not going to be able to determine the actual uptime. If > one entry is S, then two hours pass and an entry is U, how do we know if > the computer was on or off during that time? > > Basically how this is going to work: > > 1. Read first two lines, $line[1], $line[2], using fgets() > 2. Use strtotime() to convert timestamps and subtract > to determine the elapsed time between them > 3. Add difference to either $U_time or $S_time based > upon status (S or U) in $line[1] > 4. Set $line[1] = $line[2] > 5. Read next line of file into $line[2] > 6. GOTO #2 > > Then you'll have total $U_time and total $S_time and you can calculate > your percentages from there. > > -- > > ---John Holmes... > > Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ > > php|architect: The Magazine for PHP Professionals - www.phparch.com >

« previous php.general (#193861) next »