Re: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Marco Tabini
Hi Chris--

Try this:

 0)
{
$kbitsout = float) $data['OctetsOut'] - $olddata['OctetsOut']) /
($data['UnixTime'] - $olddata['UnixTime'])) * 8 ) / 1000;
print str_pad ($i, 2, ' ', STR_PAD_LEFT) . ' -- ' . number_format
($kbitsout, 2) . " kbits/s\n";
}

$olddata = $data;
$i++;
}

?>

I suggest you add some code to check for divisions by zero, depending on
whether your data requires it! 

Cheers,


Marco
-- 

php|architect - The Monthly Magazine for PHP Professionals
Come check us out on the web at http://www.phparch.com!

--- Begin Message ---
Ok here is what I did but it does not do anything.
I verified that is opening the file ok and everything, but it shows nothing.
It doesn't even produce an error. I am sure there is an easier way than
looping twice, but this is how I have it for now.

$Lines = array();
$TempDir = "tempdata";
$DataFromFile = file("$TempDir/$Dat.txt");
while(list(,$oneline) = each($DataFromFile)) {
 array_push($Lines, $oneline);
 }
$LineCount = 1;
while(list(,$oneline) = each($DataFromFile)) {
  $PriorLineCount = $LineCount - 1;
  list($OctetsInB,$OctetsOutB,$TimeB) = split("|", $Lines[$LineCount]);
  list($OctetsInA,$OctetsOutA,$TimeA) = split("|", $Lines[$PriorLineCount]);
  // After much help and work with Harry, this is the formula we came up
with to show data rates over time.
  // (((Counter_Now - Counter_Before) / (Time_Now - Time_Before(converted to
seconds))) * 8)) / 1000 = kbits per hour
  $kbitsout = ((($OctetsOutB - $OctetsOutA) / ($TimeB - $TimeA)) * 8 ) /
1000;
  print "$kbitsout Kbits - $LineCount\n";
  $LineCount++;
 }

"Christopher J. Crane" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Thank you, I am going to try this now.
> "Petre Agenbag" <[EMAIL PROTECTED]> wrote in message
> 1041861992.1993.36.camel@DELL">news:1041861992.1993.36.camel@DELL...
> > When you read the first line, split the data into it's components , then
> > assign each value to a variable.
> > Call them:
> > $octet_1,$unix_time_1 etc.
> > Now, start the loop.
> > Inside the loop, read the next line, assign to $octet_2, $unix_time_2
> > etc.
> > Do your calculations ( $answer = $octet_2 - $octet_1 etc. )
> > Now, before exiting the loop:
> > $octet_1 = $octet_2;
> > $unix_time_1 = $unix_time_1;
> > etc
> >
> >
> > On Mon, 2003-01-06 at 15:51, Christopher J. Crane wrote:
> > > Ok, this is the first time I will post a message without a line of
code.
> I
> > > am not sure how to go about this task. So I will describe it and maybe
> > > someone will have some thoughts.
> > >
> > > I use PHP to connect to our many routers and get data using snmp. I
have
> > > written a script that refreshes itself every 10 secs. It writes the
data
> to
> > > a text file. The key element of this data is the Octet counters, or
the
> > > amount of data that has been transfered both in and out. To keep it
> simple,
> > > I will only talk about outs. In order to find the amount od data being
> > > transfered, I have to compare two lines. Then run a calculation on
that
> and
> > > then push that data into an array to plot on a chart later on.
> > >
> > > Here is an example of the file the data is written to:
> > > OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
> > > OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031
> > > OctetsIn:4308716675|OctetsOut:4308782481|UnixTime:1041629044
> > > OctetsIn:4312595737|OctetsOut:4312685815|UnixTime:1041629058
> > > OctetsIn:4315910414|OctetsOut:4315961443|UnixTime:1041629072
> > > OctetsIn:4318948400|OctetsOut:4318975102|UnixTime:1041629085
> > > OctetsIn:4322040239|OctetsOut:4322091605|UnixTime:1041629098
> > > OctetsIn:4324981522|OctetsOut:4325033235|UnixTime:1041629111
> > > OctetsIn:4327971528|OctetsOut:4328029496|UnixTime:1041629125
> > > OctetsIn:4332318792|OctetsOut:4332379277|UnixTime:1041629138
> > > OctetsIn:4335594241|OctetsOut:4335635318|UnixTime:1041629153
> > > OctetsIn:4339008729|OctetsOut:4339048246|UnixTime:1041629166
> > > OctetsIn:4342539875|OctetsOut:4342591776|UnixTime:1041629180
> > > OctetsIn:4346070439|OctetsOut:4346127821|UnixTime:1041629193
> > > OctetsIn:4350288360|OctetsOut:4350355417|UnixTime:1041629206
> > >
> > > I can open the file and read the contents line by line
> > > split up but the delimiters and get the data I needbut this is
what
> has
> > > to happen.
> > > If PHP is on line 1, do nothing (it's needs two lines to compare
> against)
> > >
> > > If it's on line 2, then subtract Line 1, OctetsOut from Line Line 2
> > > OctetsOut. Then do the same with the UnixTime. Now run a calculation
on
> that
> > > data and push that into an array as the first data point. Now move on,
> with
> > > a loop I would assume, and do the same for lines 2 and 3, and so on,
> until
> > > we reach the end.
> > >
> > > There could be 5 lines or 500 lines.
> > >
> > > I can loop through the file and do everything, the biggest p

RE: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Ford, Mike [LSS]
> -Original Message-
> From: Christopher J. Crane [mailto:[EMAIL PROTECTED]]
> Sent: 06 January 2003 17:12
> 
> Ok here is what I did but it does not do anything.
> I verified that is opening the file ok and everything, but it 
> shows nothing.
> It doesn't even produce an error. I am sure there is an 
> easier way than
> looping twice, but this is how I have it for now.


Hoo, boy! there's so many things wrong with this I hardly know where to
start!

However...

> $Lines = array();
> $TempDir = "tempdata";
> $DataFromFile = file("$TempDir/$Dat.txt");

I hope you've assigned $Dat a value elsewhere -- it's not in the fragment
posted here!

> while(list(,$oneline) = each($DataFromFile)) {
>  array_push($Lines, $oneline);
>  }

Why on earth do you do this?  It's converting the array of lines in
$DataFromFile into -- er -- an identical array of lines in $Lines -- and
*extremely* inefficiently, too!  Just do:

$Lines = file("$TempDir/$Dat.txt");

Except, hang on, the following code then writes a whole new set of values in
to $Lines, so we can just forget the above while loop totally!

> $LineCount = 1;
> while(list(,$oneline) = each($DataFromFile)) {

Use foreach in preference to a while(each()) loop, so:

  foreach ($DataFromFile as $oneline) {

>   $PriorLineCount = $LineCount - 1;
Drop this -- it's not necessary.

>   list($OctetsInB,$OctetsOutB,$TimeB) = split("|", 
> $Lines[$LineCount]);
>   list($OctetsInA,$OctetsOutA,$TimeA) = split("|", 
> $Lines[$PriorLineCount]);

(1) H'mmm -- you've gone to the trouble of putting the current line in
$oneline -- so why ignore it and dig $Lines[$LineCount] out of the array all
over again?
(2) You don't need to split both lines here -- this way you'll be doubling
the work by splitting each line twice.
(3) explode() is the preferred name for split().
(4) This split() is good to get the three parts of the line delimited by |,
but none of these is individually a number:

> > > > Here is an example of the file the data is written to:
> > > > OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
> > > > OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031

You'll have (e.g.) $OctetsIn=='OctetsIn:4300492881',
$OctetsOut=='OctetsOut:4300544503', which will each evaluate to zero -- not
good!  You need to further split each one on the internal ":".  I'd do the
whole trick like this:

   $values = explode('|', $oneline);
   foreach ($values as $k=>$text) {
  list(,$values[$k]) = explode(':', $values[$k]);
   }

You'll see I've exploded the line into an arrray, and then exploded each
element of the array back into itself; this gives us a 3-element array with
the required values in it.  We'll find out why I've done it this way in a
minute!

OK, so far we've done everything to every line -- but when it gets to
calculating the answers, we don't want to do this for the first line (as
there's no previous one!), so:

   if ($LineCount>1) { 

>   // After much help and work with Harry, this is the formula 
> we came up
> with to show data rates over time.
>   // (((Counter_Now - Counter_Before) / (Time_Now - 
> Time_Before(converted to
> seconds))) * 8)) / 1000 = kbits per hour
>   $kbitsout = ((($OctetsOutB - $OctetsOutA) / ($TimeB - 
> $TimeA)) * 8 ) /
> 1000;

   This bit I believe -- except that it's kbits/sec, not per hour! -- but of
course it needs adjusting for the fact that the values are now in an array;
also, so far we don't know where the values for the previous line are, so
I'll come back to this!

>   print "$kbitsout Kbits - $LineCount\n";

   } // end of the if($LineCount>1)

Now we need to remember the values we extracted for this line, so that we
can use them as the *previous* values when we process the next line on the
next iteration of the foreach loop; as I've put the values in an array this
is easy:

   $prev_values = $values;

(If I'd produced three separate variables, I'd have to do three
assignments!)

>   $LineCount++;
>  }

OK, so far so good -- but what about that middle bit that I left out?  Well,
we now know that we will have the current values in $values[], and the
previous values in $prev_values[], so the calculation becomes:

$kbitsout = ($values[1]-$prev_values[1]) / ($values[3]-$prev_values[3])
/ 125;

And that's it, eventually.  Just to put it all back together, this is how
it's ended up:

$TempDir = "tempdata";
$DataFromFile = file("$TempDir/$Dat.txt");

$LineCount = 1;

foreach ($DataFromFile as $oneline) {
   $values = explode('|', $oneline);
   foreach ($values as $k=>$text) {
  list(,$values[$k]) = explode(':', $values[$k]);
   }
   if ($LineCount>1) { 
  $kbitsout = ($values[1]-$prev_values[1]) /
($values[3]-$prev_values[3]) / 125;
  print "$kbitsout Kbits - $LineCount\n";

   }

   $prev_values = $values;

   $LineCount++;
}

Final caveat emptor:  I haven't actually tested any of this, but it
shouldn't be far wrong!

Hope that lot proves helpful, and good luck with it!

Cheers!

Mike

---

Re: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Jason Wong
On Tuesday 07 January 2003 01:12, Christopher J. Crane wrote:
> Ok here is what I did but it does not do anything.
> I verified that is opening the file ok and everything, but it shows
> nothing. It doesn't even produce an error. I am sure there is an easier way
> than looping twice, but this is how I have it for now.
>
> $Lines = array();
> $TempDir = "tempdata";
> $DataFromFile = file("$TempDir/$Dat.txt");
> while(list(,$oneline) = each($DataFromFile)) {
>  array_push($Lines, $oneline);
>  }
> $LineCount = 1;
> while(list(,$oneline) = each($DataFromFile)) {
>   $PriorLineCount = $LineCount - 1;
>   list($OctetsInB,$OctetsOutB,$TimeB) = split("|", $Lines[$LineCount]);
>   list($OctetsInA,$OctetsOutA,$TimeA) = split("|",
> $Lines[$PriorLineCount]); // After much help and work with Harry, this is
> the formula we came up with to show data rates over time.
>   // (((Counter_Now - Counter_Before) / (Time_Now - Time_Before(converted
> to seconds))) * 8)) / 1000 = kbits per hour
>   $kbitsout = ((($OctetsOutB - $OctetsOutA) / ($TimeB - $TimeA)) * 8 ) /
> 1000;
>   print "$kbitsout Kbits - $LineCount\n";
>   $LineCount++;
>  }

echo() all the variables used and see what you get.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
I'm rated PG-34!!
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Christopher J. Crane
Ok here is what I did but it does not do anything.
I verified that is opening the file ok and everything, but it shows nothing.
It doesn't even produce an error. I am sure there is an easier way than
looping twice, but this is how I have it for now.

$Lines = array();
$TempDir = "tempdata";
$DataFromFile = file("$TempDir/$Dat.txt");
while(list(,$oneline) = each($DataFromFile)) {
 array_push($Lines, $oneline);
 }
$LineCount = 1;
while(list(,$oneline) = each($DataFromFile)) {
  $PriorLineCount = $LineCount - 1;
  list($OctetsInB,$OctetsOutB,$TimeB) = split("|", $Lines[$LineCount]);
  list($OctetsInA,$OctetsOutA,$TimeA) = split("|", $Lines[$PriorLineCount]);
  // After much help and work with Harry, this is the formula we came up
with to show data rates over time.
  // (((Counter_Now - Counter_Before) / (Time_Now - Time_Before(converted to
seconds))) * 8)) / 1000 = kbits per hour
  $kbitsout = ((($OctetsOutB - $OctetsOutA) / ($TimeB - $TimeA)) * 8 ) /
1000;
  print "$kbitsout Kbits - $LineCount\n";
  $LineCount++;
 }

"Christopher J. Crane" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Thank you, I am going to try this now.
> "Petre Agenbag" <[EMAIL PROTECTED]> wrote in message
> 1041861992.1993.36.camel@DELL">news:1041861992.1993.36.camel@DELL...
> > When you read the first line, split the data into it's components , then
> > assign each value to a variable.
> > Call them:
> > $octet_1,$unix_time_1 etc.
> > Now, start the loop.
> > Inside the loop, read the next line, assign to $octet_2, $unix_time_2
> > etc.
> > Do your calculations ( $answer = $octet_2 - $octet_1 etc. )
> > Now, before exiting the loop:
> > $octet_1 = $octet_2;
> > $unix_time_1 = $unix_time_1;
> > etc
> >
> >
> > On Mon, 2003-01-06 at 15:51, Christopher J. Crane wrote:
> > > Ok, this is the first time I will post a message without a line of
code.
> I
> > > am not sure how to go about this task. So I will describe it and maybe
> > > someone will have some thoughts.
> > >
> > > I use PHP to connect to our many routers and get data using snmp. I
have
> > > written a script that refreshes itself every 10 secs. It writes the
data
> to
> > > a text file. The key element of this data is the Octet counters, or
the
> > > amount of data that has been transfered both in and out. To keep it
> simple,
> > > I will only talk about outs. In order to find the amount od data being
> > > transfered, I have to compare two lines. Then run a calculation on
that
> and
> > > then push that data into an array to plot on a chart later on.
> > >
> > > Here is an example of the file the data is written to:
> > > OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
> > > OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031
> > > OctetsIn:4308716675|OctetsOut:4308782481|UnixTime:1041629044
> > > OctetsIn:4312595737|OctetsOut:4312685815|UnixTime:1041629058
> > > OctetsIn:4315910414|OctetsOut:4315961443|UnixTime:1041629072
> > > OctetsIn:4318948400|OctetsOut:4318975102|UnixTime:1041629085
> > > OctetsIn:4322040239|OctetsOut:4322091605|UnixTime:1041629098
> > > OctetsIn:4324981522|OctetsOut:4325033235|UnixTime:1041629111
> > > OctetsIn:4327971528|OctetsOut:4328029496|UnixTime:1041629125
> > > OctetsIn:4332318792|OctetsOut:4332379277|UnixTime:1041629138
> > > OctetsIn:4335594241|OctetsOut:4335635318|UnixTime:1041629153
> > > OctetsIn:4339008729|OctetsOut:4339048246|UnixTime:1041629166
> > > OctetsIn:4342539875|OctetsOut:4342591776|UnixTime:1041629180
> > > OctetsIn:4346070439|OctetsOut:4346127821|UnixTime:1041629193
> > > OctetsIn:4350288360|OctetsOut:4350355417|UnixTime:1041629206
> > >
> > > I can open the file and read the contents line by line
> > > split up but the delimiters and get the data I needbut this is
what
> has
> > > to happen.
> > > If PHP is on line 1, do nothing (it's needs two lines to compare
> against)
> > >
> > > If it's on line 2, then subtract Line 1, OctetsOut from Line Line 2
> > > OctetsOut. Then do the same with the UnixTime. Now run a calculation
on
> that
> > > data and push that into an array as the first data point. Now move on,
> with
> > > a loop I would assume, and do the same for lines 2 and 3, and so on,
> until
> > > we reach the end.
> > >
> > > There could be 5 lines or 500 lines.
> > >
> > > I can loop through the file and do everything, the biggest problem I
am
> > > having is getting the data on the line PHP is currently on, and then
> > > subtracting the line prior to it. I just can't seem to get a grasp on
> it.
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Christopher J. Crane
Thank you, I am going to try this now.
"Petre Agenbag" <[EMAIL PROTECTED]> wrote in message
1041861992.1993.36.camel@DELL">news:1041861992.1993.36.camel@DELL...
> When you read the first line, split the data into it's components , then
> assign each value to a variable.
> Call them:
> $octet_1,$unix_time_1 etc.
> Now, start the loop.
> Inside the loop, read the next line, assign to $octet_2, $unix_time_2
> etc.
> Do your calculations ( $answer = $octet_2 - $octet_1 etc. )
> Now, before exiting the loop:
> $octet_1 = $octet_2;
> $unix_time_1 = $unix_time_1;
> etc
>
>
> On Mon, 2003-01-06 at 15:51, Christopher J. Crane wrote:
> > Ok, this is the first time I will post a message without a line of code.
I
> > am not sure how to go about this task. So I will describe it and maybe
> > someone will have some thoughts.
> >
> > I use PHP to connect to our many routers and get data using snmp. I have
> > written a script that refreshes itself every 10 secs. It writes the data
to
> > a text file. The key element of this data is the Octet counters, or the
> > amount of data that has been transfered both in and out. To keep it
simple,
> > I will only talk about outs. In order to find the amount od data being
> > transfered, I have to compare two lines. Then run a calculation on that
and
> > then push that data into an array to plot on a chart later on.
> >
> > Here is an example of the file the data is written to:
> > OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
> > OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031
> > OctetsIn:4308716675|OctetsOut:4308782481|UnixTime:1041629044
> > OctetsIn:4312595737|OctetsOut:4312685815|UnixTime:1041629058
> > OctetsIn:4315910414|OctetsOut:4315961443|UnixTime:1041629072
> > OctetsIn:4318948400|OctetsOut:4318975102|UnixTime:1041629085
> > OctetsIn:4322040239|OctetsOut:4322091605|UnixTime:1041629098
> > OctetsIn:4324981522|OctetsOut:4325033235|UnixTime:1041629111
> > OctetsIn:4327971528|OctetsOut:4328029496|UnixTime:1041629125
> > OctetsIn:4332318792|OctetsOut:4332379277|UnixTime:1041629138
> > OctetsIn:4335594241|OctetsOut:4335635318|UnixTime:1041629153
> > OctetsIn:4339008729|OctetsOut:4339048246|UnixTime:1041629166
> > OctetsIn:4342539875|OctetsOut:4342591776|UnixTime:1041629180
> > OctetsIn:4346070439|OctetsOut:4346127821|UnixTime:1041629193
> > OctetsIn:4350288360|OctetsOut:4350355417|UnixTime:1041629206
> >
> > I can open the file and read the contents line by line
> > split up but the delimiters and get the data I needbut this is what
has
> > to happen.
> > If PHP is on line 1, do nothing (it's needs two lines to compare
against)
> >
> > If it's on line 2, then subtract Line 1, OctetsOut from Line Line 2
> > OctetsOut. Then do the same with the UnixTime. Now run a calculation on
that
> > data and push that into an array as the first data point. Now move on,
with
> > a loop I would assume, and do the same for lines 2 and 3, and so on,
until
> > we reach the end.
> >
> > There could be 5 lines or 500 lines.
> >
> > I can loop through the file and do everything, the biggest problem I am
> > having is getting the data on the line PHP is currently on, and then
> > subtracting the line prior to it. I just can't seem to get a grasp on
it.
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] No Idea - Comparing Lines

2003-01-06 Thread Petre Agenbag
When you read the first line, split the data into it's components , then
assign each value to a variable.
Call them:
$octet_1,$unix_time_1 etc.
Now, start the loop.
Inside the loop, read the next line, assign to $octet_2, $unix_time_2
etc.
Do your calculations ( $answer = $octet_2 - $octet_1 etc. )
Now, before exiting the loop:
$octet_1 = $octet_2;
$unix_time_1 = $unix_time_1;
etc

 
On Mon, 2003-01-06 at 15:51, Christopher J. Crane wrote:
> Ok, this is the first time I will post a message without a line of code. I
> am not sure how to go about this task. So I will describe it and maybe
> someone will have some thoughts.
> 
> I use PHP to connect to our many routers and get data using snmp. I have
> written a script that refreshes itself every 10 secs. It writes the data to
> a text file. The key element of this data is the Octet counters, or the
> amount of data that has been transfered both in and out. To keep it simple,
> I will only talk about outs. In order to find the amount od data being
> transfered, I have to compare two lines. Then run a calculation on that and
> then push that data into an array to plot on a chart later on.
> 
> Here is an example of the file the data is written to:
> OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
> OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031
> OctetsIn:4308716675|OctetsOut:4308782481|UnixTime:1041629044
> OctetsIn:4312595737|OctetsOut:4312685815|UnixTime:1041629058
> OctetsIn:4315910414|OctetsOut:4315961443|UnixTime:1041629072
> OctetsIn:4318948400|OctetsOut:4318975102|UnixTime:1041629085
> OctetsIn:4322040239|OctetsOut:4322091605|UnixTime:1041629098
> OctetsIn:4324981522|OctetsOut:4325033235|UnixTime:1041629111
> OctetsIn:4327971528|OctetsOut:4328029496|UnixTime:1041629125
> OctetsIn:4332318792|OctetsOut:4332379277|UnixTime:1041629138
> OctetsIn:4335594241|OctetsOut:4335635318|UnixTime:1041629153
> OctetsIn:4339008729|OctetsOut:4339048246|UnixTime:1041629166
> OctetsIn:4342539875|OctetsOut:4342591776|UnixTime:1041629180
> OctetsIn:4346070439|OctetsOut:4346127821|UnixTime:1041629193
> OctetsIn:4350288360|OctetsOut:4350355417|UnixTime:1041629206
> 
> I can open the file and read the contents line by line
> split up but the delimiters and get the data I needbut this is what has
> to happen.
> If PHP is on line 1, do nothing (it's needs two lines to compare against)
> 
> If it's on line 2, then subtract Line 1, OctetsOut from Line Line 2
> OctetsOut. Then do the same with the UnixTime. Now run a calculation on that
> data and push that into an array as the first data point. Now move on, with
> a loop I would assume, and do the same for lines 2 and 3, and so on, until
> we reach the end.
> 
> There could be 5 lines or 500 lines.
> 
> I can loop through the file and do everything, the biggest problem I am
> having is getting the data on the line PHP is currently on, and then
> subtracting the line prior to it. I just can't seem to get a grasp on it.
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] No Idea - Comparing Lines

2003-01-06 Thread Christopher J. Crane
Ok, this is the first time I will post a message without a line of code. I
am not sure how to go about this task. So I will describe it and maybe
someone will have some thoughts.

I use PHP to connect to our many routers and get data using snmp. I have
written a script that refreshes itself every 10 secs. It writes the data to
a text file. The key element of this data is the Octet counters, or the
amount of data that has been transfered both in and out. To keep it simple,
I will only talk about outs. In order to find the amount od data being
transfered, I have to compare two lines. Then run a calculation on that and
then push that data into an array to plot on a chart later on.

Here is an example of the file the data is written to:
OctetsIn:4300492881|OctetsOut:4300544503|UnixTime:1041629017
OctetsIn:4305184236|OctetsOut:4305234971|UnixTime:1041629031
OctetsIn:4308716675|OctetsOut:4308782481|UnixTime:1041629044
OctetsIn:4312595737|OctetsOut:4312685815|UnixTime:1041629058
OctetsIn:4315910414|OctetsOut:4315961443|UnixTime:1041629072
OctetsIn:4318948400|OctetsOut:4318975102|UnixTime:1041629085
OctetsIn:4322040239|OctetsOut:4322091605|UnixTime:1041629098
OctetsIn:4324981522|OctetsOut:4325033235|UnixTime:1041629111
OctetsIn:4327971528|OctetsOut:4328029496|UnixTime:1041629125
OctetsIn:4332318792|OctetsOut:4332379277|UnixTime:1041629138
OctetsIn:4335594241|OctetsOut:4335635318|UnixTime:1041629153
OctetsIn:4339008729|OctetsOut:4339048246|UnixTime:1041629166
OctetsIn:4342539875|OctetsOut:4342591776|UnixTime:1041629180
OctetsIn:4346070439|OctetsOut:4346127821|UnixTime:1041629193
OctetsIn:4350288360|OctetsOut:4350355417|UnixTime:1041629206

I can open the file and read the contents line by line
split up but the delimiters and get the data I needbut this is what has
to happen.
If PHP is on line 1, do nothing (it's needs two lines to compare against)

If it's on line 2, then subtract Line 1, OctetsOut from Line Line 2
OctetsOut. Then do the same with the UnixTime. Now run a calculation on that
data and push that into an array as the first data point. Now move on, with
a loop I would assume, and do the same for lines 2 and 3, and so on, until
we reach the end.

There could be 5 lines or 500 lines.

I can loop through the file and do everything, the biggest problem I am
having is getting the data on the line PHP is currently on, and then
subtracting the line prior to it. I just can't seem to get a grasp on it.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php