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 need....but 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

Reply via email to