vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Microstats (only for admin) - load times, server loads, queries, uncached templates! (https://vborg.vbsupport.ru/showthread.php?t=59700)

Erwin 01-04-2004 10:00 PM

Microstats (only for admin) - load times, server loads, queries, uncached templates!
 
Version 1.0 - works for most servers
Updated 1.1 - optimized code
Updated 1.2 - added names of uncached templates!

Okay, the original was by TECK. This is NOT based on his code - it is based on vB3's native code. If TECK wants me to remove this, I will do so. This is just my version that I use for my private forums.

Information shown:
1) Page loading times
2) Number of Queries
3) Server Loads
4) Number of Any Uncached Templates
5) Name of Uncached Templates (NEW!)

By default only an Admin (usergroup 6) can see it. Feel free to modify this bit.

It's very easy to install.

Open includes/functions.php:

Find:

PHP Code:

// ####################################################################
    // temporary code
    
global $_TEMPLATEQUERIES$tempusagecache$DEVDEBUG$_SERVER$debug

UNDERNEATH, ADD:

Version 1.2 - more optimized but requires /proc on your server - try this, if server loads don't show up use Version 1.02 below

PHP Code:

// Microstats hack
if ($bbuserinfo[usergroupid]==6) {
                
$pageendtime microtime(); 
                
$starttime explode(' '$pagestarttime); 
                
$endtime explode(' '$pageendtime); 
                
$totaltime vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5); 
                
$loadavg = @file_get_contents("/proc/loadavg"); 
                if (
$loadavg) { 
                        
$regs explode(" ",$loadavg); 
                        
$serverload=' [Server Loads: <b>'.$regs[0].'</b> '.$regs[1].' : '.$regs[2].']'
                } 
                
$debughtml "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" iif($_TEMPLATEQUERIES" (<b>" sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)"'') . "$serverload</span></center>"
    
ksort($tempusagecache);
    foreach (
$tempusagecache AS $tempname => $times)
    {
    if (
$_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
    }
                
$vartext str_replace('</body>'"$debughtml\n</body>"$vartext); 
 
}
//Microstats Hack 



Version 1.02 - Use this if Version 1.1 doesn't work for you.

PHP Code:

// Microstats hack 
if ($bbuserinfo[usergroupid]==6) {
$pageendtime microtime(); 
$starttime explode(' '$pagestarttime); 
$endtime explode(' '$pageendtime); 
$totaltime vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5); 
if (
$stats=@exec('uptime')) { 
     
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs); 
     
$serverload=' [Server Loads: <b>'.$regs[1].'</b> ? '.$regs[2].' : '.$regs[3].']'
     } 
$debughtml "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" iif($_TEMPLATEQUERIES" (<b>" sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)"'') . "$serverload</span>"
$vartext str_replace('</body>'"$debughtml\n</body>"$vartext); 
    
ksort($tempusagecache);
    foreach (
$tempusagecache AS $tempname => $times)
    {
    if (
$_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
    }
}
//Microstats Hack 


Done! As simple as that. No need to enable debug mode.

If you want only yourself to have this information, change:
if ($bbuserinfo[usergroupid]==6) {
to
if ($bbuserinfo[userid]==1) {

And replace 1 with your userid.

To let everyone see it, remove that line, and the last } of the code above.

Below is a screenshot of how my forumhome microstats look. :)

EDIT: Thanks to kmike, I optimized the code. This should lessen the load when checking the server loads slightly.

Version 1.2 and 1.02 now has added code to show NAMES OF UNCACHED TEMPLATES! :)

DestinyIslands 01-05-2004 01:30 AM

Interesting ... I might use this

- DestinyIslands

MGM 01-05-2004 01:42 AM

Alright sweet, this should help out in lookin at page loads and such

/me clicks install

MGM out

Koutaru 01-05-2004 02:34 AM

Whoohoo. Will install :) Thanks Erwin!

Schorsch 01-05-2004 11:02 AM

thanks Erwin.

Dean C 01-05-2004 11:08 AM

Wow Erwin's on a modding spree :p Nice one :)!

xxskullxx 01-05-2004 01:18 PM

Nice job erwin!

ThePartyBorg 01-05-2004 07:25 PM

Oooo, installed it right away.

Tubbie 01-05-2004 08:19 PM

Nice and easy!

THX

Serge 01-06-2004 02:14 AM

If you are getting 2.55 is that bad for server load? I am on a shared server is that ok as it is shared or is that still bad?

EDIT: Actually server load seems to stay around the 2.0 range.

Gary King 01-06-2004 02:27 AM

Quote:

Originally Posted by Serge
If you are getting 2.55 is that bad for server load? I am on a shared server is that ok as it is shared or is that still bad?

EDIT: Actually server load seems to stay around the 2.0 range.

How many simultaneous users do you have when you get those load times? They are fairly bad, but not THAT bad.

Serge 01-06-2004 02:39 AM

There were 9 but I was the only registered user on the rest where bots I'm guessing although I didn't check.

Alien 01-06-2004 02:46 AM

Nice job. :) Thanks!

Mijae 01-06-2004 03:38 AM

Are 26 queries for forumhome too bad?

Erwin 01-06-2004 03:52 AM

Quote:

Originally Posted by v0id
Are 26 queries for forumhome too bad?

Yes. Considering that on my heavily hacked forumhome I only use 8. :)

Mr. HillBilly 01-06-2004 06:48 AM

Quote:

Originally Posted by Erwin
Yes. Considering that on my heavily hacked forumhome I only use 8. :)

Yeah yeah know it all... some of us dont have all the php skills to reduce queries

Erwin 01-06-2004 08:08 AM

Quote:

Originally Posted by Mr. HillBilly
Yeah yeah know it all... some of us dont have all the php skills to reduce queries

It's not about skills in reducing queries - it's about modifying the very optimized vB3 code as little as possible. :) Don't install hacks that are not really necessary.

Mijae 01-06-2004 02:50 PM

How many queries does a normal non-modded forumhome page have?

I am going to upgrade to RC2 and then install the hacks again...

Serge 01-06-2004 07:25 PM

The normal install at least for me has 8. Today I was look though and I have 8 people on my forums me and 8 guest 7 of which are bots and my server load shows up at 5.01 I am running on a shared server but still 5.01 still sounds a little high does it to you all? Should I report this to my host?

Gary King 01-07-2004 12:50 PM

Quote:

Originally Posted by Serge
The normal install at least for me has 8. Today I was look though and I have 8 people on my forums me and 8 guest 7 of which are bots and my server load shows up at 5.01 I am running on a shared server but still 5.01 still sounds a little high does it to you all? Should I report this to my host?

Yeah sounds REALLY high.

Alien 01-07-2004 02:31 PM

How exactly would I adjust this so ANYONE can view it, not just admins?

Serge 01-07-2004 06:17 PM

Quote:

Originally Posted by Alien
How exactly would I adjust this so ANYONE can view it, not just admins?

I don't know if I'm allowed to repost but this is what you would do.

PHP Code:

    // Microstats hack 
   
$pageendtime microtime(); 
   
$starttime explode(' '$pagestarttime); 
   
$endtime explode(' '$pageendtime); 
   
$totaltime vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5); 
   if (
$stats=@exec('uptime')) { 
       
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs); 
       
$serverload=' [Server Loads: <b>'.$regs[1].'</b> ? '.$regs[2].' : '.$regs[3].']'
       } 
 
$debughtml "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" iif($_TEMPLATEQUERIES" (<b>" sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)"'') . "$serverload</span>"
   
$vartext str_replace('</body>'"$debughtml\n</body>"$vartext); 
   
//Microstats Hack 

Place that in the same EXACT place as you would have for the orginal hack all this did was took out the check for the admin part.

Serge 01-07-2004 06:19 PM

Actually if you know what I'm talking about just take the frist if line out and then delete the } at the very end before the comment. That will do it I will work on that post although I have no clue why that happened might be a bug.

EDIT: I fixed the post above when I copied Erwin's code it came though with the color on it as well in the WYSISWG and it left it on there as well and then when I changed everything to black it didn't work but in the end I got it fixed.

Alex 01-08-2004 02:13 PM

Could you add gzip stats to it? please!

TECK 01-08-2004 03:59 PM

Quote:

Originally Posted by Serge
I don't know if I'm allowed to repost but this is what you would do.

PHP Code:

    // Microstats hack 
   
$pageendtime microtime(); 
   
$starttime explode(' '$pagestarttime); 
   
$endtime explode(' '$pageendtime); 
   
$totaltime vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5); 
   if (
$stats=@exec('uptime')) { 
       
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs); 
       
$serverload=' [Server Loads: <b>'.$regs[1].'</b> ? '.$regs[2].' : '.$regs[3].']'
       } 
 
$debughtml "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" iif($_TEMPLATEQUERIES" (<b>" sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)"'') . "$serverload</span>"
   
$vartext str_replace('</body>'"$debughtml\n</body>"$vartext); 
   
//Microstats Hack 

Place that in the same EXACT place as you would have for the orginal hack all this did was took out the check for the admin part.

If you show the server load for everyone, you will kill your server.
Is for a reason I released originally this hack part for admins only...

Hope, this helps.

PS. Yes Erwin, you have my permission to publish any modifications for MicroStats and port it to VB3 software.
Thank you for asking.

Dark_Wizard 01-08-2004 04:06 PM

Nice hack Erwin! Great to have while developing my vbWar 3.0. Thanks!

Alien 01-09-2004 04:15 AM

Ahh, so this and even the one for vB2x were server killers, TECK? :)

I honestly never saw a difference in the server hmm.

I guess I can just set it up for admins to view if so...

Serge: Thanks for that help tho, much appreciated.

coKe67 01-10-2004 10:52 AM

Thanks Erwin,
nice & easy:squareeyed:

Vigile 01-11-2004 11:06 AM

Page generated in 0.25738 seconds with 12 queries (3 queries for uncached templates)

Ok.. call me a knob if ya want, but what is the '3 queries for uncached templates' part trying to tell me? I'm presuming its something I need to fix.

Erwin 01-11-2004 11:20 AM

Quote:

Originally Posted by Vigile
Page generated in 0.25738 seconds with 12 queries (3 queries for uncached templates)

Ok.. call me a knob if ya want, but what is the '3 queries for uncached templates' part trying to tell me? I'm presuming its something I need to fix.

You have 3 uncached templates, which is causing that page to have 3 extra unnecessary queries. You need to add these templates to the template cache by editing that PHP file. To know which templates, you need to switch debug to on. My hack tells you how many templates are uncached, but not which ones.

Vigile 01-11-2004 11:48 AM

Quote:

Originally Posted by Erwin
You have 3 uncached templates, which is causing that page to have 3 extra unnecessary queries. You need to add these templates to the template cache by editing that PHP file. To know which templates, you need to switch debug to on. My hack tells you how many templates are uncached, but not which ones.

Sorry, I know Im getting outside the confines of this topic thread, but Im was able to drop 2 of them but they are being caused by an eval statement to my phpinclude, so I can drop in a variable $shadow instead of long drawn out code. Is there an easy fix for this that wont generate a query? Mind you.. I have added $shadow to about 70 templates so far. So one less query (and an easy fix for it) would be a good thing.

all I've done is
PHP Code:

eval('$shadow = "' fetch_template('shadow') . '";'); 

any help appreciated. If ya want to cut this and move to a proper forum, please do.

Erwin 01-11-2004 09:32 PM

Quote:

Originally Posted by Vigile
Sorry, I know Im getting outside the confines of this topic thread, but Im was able to drop 2 of them but they are being caused by an eval statement to my phpinclude, so I can drop in a variable $shadow instead of long drawn out code. Is there an easy fix for this that wont generate a query? Mind you.. I have added $shadow to about 70 templates so far. So one less query (and an easy fix for it) would be a good thing.

all I've done is
PHP Code:

eval('$shadow = "' fetch_template('shadow') . '";'); 

any help appreciated. If ya want to cut this and move to a proper forum, please do.

Instead of adding it to all your templates, if it's in your phpinclude, add it to global.php in the forum directory (at least that's where you do it in vB2, not sure about vB3).

Roderik 01-12-2004 02:37 PM

Works great!

Code:

Page generated in 0.09473 seconds with 8 queries [Server Loads: 0.00 - 0.02 - 0.07]
changed the code to fit my 150px sidebar, see modified code below.

PHP Code:

    // Microstats hack
    
if ($bbuserinfo[usergroupid]==6) {
        
$pageendtime microtime();
        
$starttime explode(' '$pagestarttime);
        
$endtime explode(' '$pageendtime);
        
$totaltime vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5);
        if (
$stats=@exec('uptime')) {
            
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs);
            
$serverload=' [Server Loads: <b>'.$regs[1].'</b> - '.$regs[2].' - '.$regs[3].']';
        }
        
$debughtml "<table width=\"100%\" cellpadding=\"0\" cellspading=\"0\" border=\"0\"><tr><td width=\"150\" nowrap=\"nowrap\">&nbsp;</td><td algin=\"center\" class=\"smallfont\"><center>Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" iif($_TEMPLATEQUERIES" (<b>" sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)"'') . "$serverload</center></td></tr></table>";
        
$vartext str_replace('</body>'"$debughtml\n</body>"$vartext);
    }
    
//Microstats Hack 


Limitter 01-13-2004 11:17 AM

thanks Erwin very nice & easy

L.

Gary King 01-18-2004 09:29 PM

Maybe you should phrases for this hack, by the way :D

corn 01-19-2004 09:08 AM

* clicks install*

The_Wanderer 01-21-2004 01:33 PM

just the hack i was looking for ^^

muse.mu 01-21-2004 03:30 PM

Parse error: parse error in /home/xxxxx/public_html/xxxxxx/includes/functions.php on line 1782

Fatal error: Call to undefined function: is_browser() in /home/xxxxxx/public_html/xxxxxx/global.php on line 59

=/

NTLDR 01-21-2004 03:41 PM

Don't edit functions.php with Dreamweaver.

muse.mu 01-21-2004 05:52 PM

Quote:

Originally Posted by NTLDR
Don't edit functions.php with Dreamweaver.


argh. thanks a bunch for the heads up! that is like....the only thing i use :S

can you suggest an alternative please?


All times are GMT. The time now is 04:50 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01674 seconds
  • Memory Usage 1,900KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (8)bbcode_php_printable
  • (11)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete