Need Help.

Jator

Golden Member
Jun 14, 2000
1,445
7
81
Anyone here wanna help me implement a new feature to my stats page?

I need someone who knows PHP coding. What I want to do is grab the last entry in the console log file which has the latest proxy stats. This would have to be done dynamically so that this would be real time information.

If anyone can help, thanks.

Jay
 

Dale

Senior member
Oct 9, 1999
503
0
0
Jator your question is not excessively clear to me..

this is just a code snippet<br>
<?php
$file='/usr/src/proxyper306/conlog.log20001025.log';
$consolelog = file($file);
$num=sizeof($data);
$lastline=$num-1;
echo &quot;$consolelog[$lastline]\n&quot;;
?>

YIELDS on Linux/PHP4/PPROXY3.06

10/25/00 02:11:43,Status: 0 active clients (peak: 1, mean: 0.00)

which is what I thought you asked, a better display is the last 6 lines on mine, your mileage will depend on the proxy vers I guess

10/25/00 02:15:51,rc564 r=534/520, d=0/3, 19.1 Mkeys/sec, tot=8014
10/25/00 02:15:51,desII r=0/1, d=0/1, 0.0 Mkeys/sec, tot=0
10/25/00 02:15:51,ogr r=0/0, d=0/0, 0.0 Mnodes/sec, tot=0
10/25/00 02:15:51,csc r=0/2, d=0/1, 0.0 Mkeys/sec, tot=0
10/25/00 02:15:51,Status: Uptime: 1.08:59:59, 2 listeners, 0 uplinks
10/25/00 02:15:51,Status: 0 active clients (peak: 1, mean: 0.00)

anyway the key is the file() function...

<edit>speeled jator wrong : ( </edit>
l8r
Dale
 

Jator

Golden Member
Jun 14, 2000
1,445
7
81
Dale,

I have something similar to that here:

Last 6 lines

What I want to do is grab the last buffer status file for rc5, showing how many blocks are buffered, how many are sitting in the outfile, and how long the uptime has been.

HeavyIron set it up on his ppstats in Perl, which I will implement into mine as well. What I am wanting to add it to though is my Daily PHP stats page PHP Stats Page so that when I connect to this page not only do I get updated daily info on who's submitted, but I can also get real time info on my pproxy status.

Jay
 

Dale

Senior member
Oct 9, 1999
503
0
0
Jay what would help is what OS are you using? what proxy prg?(including version)

the one I use does not have a 'buffer status file' , only the log of finished blocks and the console log (which shows the info you are looking for)

it is a combination of lines ie:
'10/25/00 12:06:27 ,rc564 r=532/520, d=0/3, 19.7 Mkeys/sec, tot=10269 Uptime: 1.18:50:35'
or
10/25/00 12:06:27
Buff in - 532
Buff out - 0
Uptime: 1.18:50:35

if you have a 'buffer status file' just substitute the path/filename in the snippet above and print it out

OS,Progname/version,desired output

..Dale
 

nukefarmer

Senior member
May 7, 2000
351
0
0
i just put a small php script together that looks in the last x lines
of the console logfile.
It uses regular expressions to strip the info from uptime and rc5 lines. It only does uptime and rc5 lines now but can easily be extended to do other projects also.

Layout will probably be messed up completly but here it is:
-- edit: added active clients count --

<?php
$filename = &quot;logs/perproxy20000123.log&quot;; // console log filename

$linestoscan = 20; // check last 20 lines of the file

$logfile = file($filename);
$last = count($logfile);
$start = $last - $linestoscan;


for ($i=$start; $i<$last; $i++) {

// split status uptime line
if (eregi(&quot;(.*),Status: Uptime: (.*), ([0-9]+) listeners, ([0-9]+) uplinks&quot;,$logfile[$i],$data)) {
$timestamp = $data[1];
$uptime = $data[2];
$listeners = $data[3];
$uplinks = $data[4];
}

// active clients count
if (eregi(&quot;(.*),Status: ([0-9]+) active clients \(peak: ([0-9]+), mean: ([0-9,\.]+)\)&quot;,$logfile[$i],$data)) {
$timestamp = $data[1];
$clactive = $data[2];
$clpeak = $data[3];
$clmean = $data[4];
}

// split RC5 status lines
if (eregi(&quot;(.*),rc564 r=([0-9]+)/([0-9]+), d=([0-9]+)/([0-9]+), (.*), tot=([0-9]+)&quot;,$logfile[$i],$data)) {
$timestamp = $data[1];
$rc5ready = $data[2];
$rc5readymax = $data[3];
$rc5done = $data[4];
$rc5donemax = $data[5];
$rc5rate = $data[6];
$rc5total = $data[7];
}
}

echo &quot;<pre>&quot;;
echo &quot;Proxy Status of $timestamp\n\n&quot;;
echo &quot;Uptime : $uptime\n&quot;;
echo &quot;Load : $listeners listeners and $uplinks uplinks\n&quot;;
echo &quot; $clactive active clients (peak: $clpeak, mean: $clmean)\n\n&quot;;

echo &quot;RC5 in-buff status : $rc5ready of $rc5readymax\n&quot;;
echo &quot;RC5 out-buff status : $rc5done of $rc5donemax\n&quot;;
echo &quot;Current RC5 rate : $rc5rate ($rc5total blocks done since last restart)\n&quot;;
echo &quot;</pre>&quot;;
?>
 

Sloth

Senior member
Oct 21, 1999
243
0
0
Just an idea to keep in mind...

Depending on the timing the last 6 lines in your log might be from someone dumping blocks to your proxy. If your script pulls the info from the log at the &quot;wrong&quot; time then you will get garbage from the output.

Nukefarmer's stuff looks good (as though I understand an of it) but since he is only doing 20 lines it could still have the same problem.

S.
 

bphantom

Senior member
Oct 9, 1999
647
17
81
Sloth, that is the problem I faced if I wanted to read the last few lines of the conlog. I ended up just having my script read the entire log (ugh.. but I also need it to dynamically count server uplinks) and retrieve the last instance of the status update. On my pproxy, the status is updated every two minutes. So the pproxy status can easily be a few hundred lines from the bottom, depending on what sort of incoming/outgoing activity is occuring at the time.

Depending how busy your pproxy is though, you could probably estimate how far away the status update could be and adjust your code accordingly. So for Jay's, maybe have it look 500 lines back, and read forward until it finds the last instance.

Brad..
 

Jator

Golden Member
Jun 14, 2000
1,445
7
81
Woooohoooooo

Thanks NukeFarmer. It works. I'll start addining it to my web pages.

THanks a million.

Here is a sample.

Test
 

nukefarmer

Senior member
May 7, 2000
351
0
0
nice to see you got it working Jator :)

One thing though, the x Gnodes since restart value is obviously not correct. The value must mean something else, but i can't figure out what
 

Jator

Golden Member
Jun 14, 2000
1,445
7
81
I might just disable that portion. I only run the OGR because I am on the baby bovine list. THat and Viz might have a heart attack if I stopped feeding him. ;)