vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   vBMicrostats (https://vborg.vbsupport.ru/showthread.php?t=116027)

TECK 05-18-2006 10:00 PM

vBMicrostats
 
Finally, the vBMicroStats product for vBulletin 3.5.4 is here. :)
The previous versions of my mod were very solicited by vBulletin administrators...
I hope you will enjoy this new version as much you did the other ones.

Looking for VB 3.6.x version? It is here.

This mod with add at the bottom of each vBulletin (powered) page, the statistics listed below.
Also, it will help you troubleshoot and optimize your vBulletin board by viewing or comparing PHP/MySQL options and other statistics that are normally hidden in your forum pages.

Regular Users:
? Load time of specified page in microseconds
? Number of queries executed
? PHP percent page usage
? MySQL percent page usage

Administrators Only:
? Server memory usage per page (in Kb)
? DEBUG mode status
? Browser GZIP library compression status
? Server average loads
? Uncached templates (useful to troubleshoot the code)

The code modifications listed below were tested into a clean installed vBulletin board. They work 100%.
If you encounter any problems, feel free to post your questions here.

Step by step install instructions are posted into vbmicrostats.html file.
In order to perform an efficient modification of your files, I recommend you to use Dreamweaver (Coder Mode) or Textpad.
Both editors will allow you to complete all steps without any coding errors.

I tried to use the plugin system as much as I could, in order to avoid any unnecessary code modifications.
In order to set the right query execution time, you will need to perform 2 small code changes to each of the following files:
? class_core.php (folder /includes)
? init.php (folder /includes)

The code changes are very safe and designed not to interfere in any way with the vBulletin performance/functionality.
Make sure you modify, save and upload one file at the time to your server.
Then, simply run the product-plugin_vbmicrostats.xml file.

Once the product installed, don't forget to enable it.
Go to your vBulletin Options, click on BB MicroStats setting group and set all your options.

TECK 05-19-2006 02:44 AM

Division by Zero? View the fix.
Negative results? View the fix. I'm waiting a response from vBulletin Team, for a better fix.
Stats not showing in PhotoPost? View the fix.
Stats only for Administrators? View the fix.

Also, if you get results like:
Page generated in 3.35731196 seconds (9.05% PHP - [high]90.95%[/high] MySQL) with 30 queries
every time you refresh your php page, you probably use a bad piece of code.
vBulletin will never generate those extreme results.
Imagine this: the code uses only 10% the resources to read the actual PHP code and the rest of 90% is used only to scan the tables... WOW!
That means the code forces to read into the database for each user who visits the site at this percentage... if you have 1000 users viewing the page in the same time.. you can get a picture of it...
If you compare this with vBulletin, the software does the opposite, 90% PHP and 10% MySQL... the right way.

The Chief 05-19-2006 02:47 AM

awesome, I'll check it out :)

Boofo 05-19-2006 02:47 AM

Excellent work, sir. Been waiting for this. And welcome back! ;)

Kaleem 05-19-2006 02:50 AM

awesome :)

TECK 05-19-2006 03:11 AM

Thank you Boofo (and all my vBFriends)! Good to be back in the house.
BTW, the VB3.5.4 code made me pull my hair few times, trickier then I thought... since it's so different from VB2.
Now, back to my vBlog product... :)

Boofo 05-19-2006 03:15 AM

Quote:

Originally Posted by TECK
Thank you Boofo (and all my vBFriends)! Good to be back in the house.
BTW, the VB3.5.4 code made me pull my hair few times, trickier then I thought... since it's so different from VB2.
Now, back to my vBlog product... :)

The new code and ways of doing things will do that at first but once you get used to it, it is better than you thought it could ever be. ;)

I will suggest downloading and installing mtha's Advanced Product Manger though. It is the only thing to use for putting hacks together. Everything all in one place to work with. You won't regret it. ;)

DementedMindz 05-19-2006 03:27 AM

ok question mine dont center and it makes a table... check the screen shot out.. also is there anyway to make it display like this mod does https://vborg.vbsupport.ru/showthread.php?t=82900 at the bottom of the footer without the table?

firstimecaller 05-19-2006 03:38 AM

hmmm. all code mods installed, double checked, template modified, enabled, shows up on page, but no value for time displayed
Quote:

Page generated in seconds (85.50% PHP - 14.50% MySQL) with 10 queries

DementedMindz 05-19-2006 03:40 AM

i was just getting ready to say the same thing lol

TECK 05-19-2006 03:44 AM

Your request is simple to fill. :)

There is a template, hidden in the plugin code. It's the best/fastest way to load it, plus it does eliminate other extra code modifications in files.
All you have to do is edit the following code, present in your vBMicroStats Global Hook plugin:
Code:

        $ms_output  = '<tr align="' . $stylevar['right'] . '">' . "\n";
        $ms_output .= '        <td class="tcat"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
        $ms_output .= '                <span class="smallfont">Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries</span>' . "\n";
        $ms_output .= '        </td>' . "\n";
        $ms_output .= '</tr>' . "\n";

        [... more code here, don't edit ...]

                $ms_output .= '<tr align="' . $stylevar['right'] . '">' . "\n";
                $ms_output .= '        <td class="alt1"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
                $ms_output .= '                <span class="smallfont">' . $memory_status . $debug_status . $gzip_status . $server_status . $templates_status . '</span>' . "\n";
                $ms_output .= '        </td>' . "\n";
                $ms_output .= '</tr>' . "\n";

That's what makes the table rows you saw in my screenshots.
The first code segment will set the regular user options, the second will take care of the administrator ones.
If you edit this html code the way you like it, you will obtain the result you want.

BTW, you can place the code:
Code:

<if condition="$show['microstats']">{microstats}</if>
anywhere you want, in your templates. :)

EDIT: The best way to edit the plugin code is to copy it all and paste it into your favorite editor.
Do all html changes, then paste it back and save it.

TECK 05-19-2006 03:47 AM

Quote:

Originally Posted by firstimecaller
hmmm. all code mods installed, double checked, template modified, enabled, shows up on page, but no value for time displayed

My bad, little typo in the code. :)
Open the vBMicroStats Global Hook plugin and find this code:
Code:

Page generated in ' . $totaltime . ' seconds
Replace it with:
Code:

Page generated in ' . $total_time . ' seconds
Sorry guys. I will upload the new version in a few moments...

firstimecaller 05-19-2006 03:56 AM

Thanks for sharing this TECK!

TECK 05-19-2006 04:00 AM

Version 1.0.1 released. Bug fixed.
You can uninstall/install the plugin if you like, instead of editing the code.

Boofo 05-19-2006 04:08 AM

I'm nor seeing anything for some reason. I dounble checked everything but nothing shows up. And it is all turned on.

EDIT: My fault. I added it to the wrong skin. Sorry. ;)

Boofo 05-19-2006 04:30 AM

Teck, is there any way to edit the html code for this so that it will make sense to us html dummies? I can't get it looking right on my site and I'm not sure what to do to fix it.

TECK 05-19-2006 04:31 AM

Sure, Bobby. :)
I will post an example here... in few minutes.

Boofo 05-19-2006 04:33 AM

Quote:

Originally Posted by TECK
Sure, Bobby. :)
I will post an example here... in few minutes.

Now that's what I call service. Thank you, sir. ;)

Here's my site URL so you can see my problem:

Fathers' Rights Forums

DementedMindz 05-19-2006 04:38 AM

yeah im playin with it to but im going crazy lol i have it where it centers the text but not the table... or i try and remove the table and the text goes poof

DementedMindz 05-19-2006 04:40 AM

also i see you have..
$ms_output = '<tr align="' . $stylevar['center'] . '">' . "\n";

now if i make it $ms_output = '<tr align="center">' . "\n"; is there any down fall? cause that makes it 100% html complaint... there is 2 spots where that is...

TECK 05-19-2006 04:49 AM

Ok, here it is an example:
Code:

        $ms_output  = '<span class="smallfont">';
        $ms_output .= 'Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries';
        $ms_output .= '</span><br />' . "\n";

        [... code here, don't edit ...]

                $ms_output .= '<span class="smallfont">';
                $ms_output .= $memory_status . $debug_status . $gzip_status . $server_status . $templates_status;
                $ms_output .= '</span>' . "\n";

The mod will remove the table rows and display it as 2 regular text lines.
If you want the $ms_output template code even simplier, use this:
Code:

        $ms_output = 'Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries<br />';

        [... code here, don't edit ...]

                $ms_output .= $memory_status . $debug_status . $gzip_status . $server_status . $templates_status;

Then you can simply play with the regular template code:
Code:

<if condition="$show['microstats']">{microstats}</if>
the way you like it.
For example, to make your two new lines centered, use this:
Code:

<if condition="$show['microstats']">
        <div style="text-align: center;">{microstats}</div>
</if>

Let me know if I was clear...
If you have any other questions, go ahead and post them. :)

EasyTarget 05-19-2006 04:50 AM

is there a way to track down which hacks are the troublesome ones using this?

DementedMindz 05-19-2006 04:50 AM

much easier thank you

TECK 05-19-2006 04:54 AM

Bob, I looked at your site, it looks fine?
If you want to place the microstats after the vBulletin copyright (for example), use my second $ms_output template, listed above.

TECK 05-19-2006 04:55 AM

Quote:

Originally Posted by DementedMindz
much easier thank you

Now, post a better explained tutorial, since you done it.
And a screenshot. :)

DementedMindz 05-19-2006 05:00 AM

one sec im just moving around the text lol tryin to see where it looks best

TECK 05-19-2006 05:03 AM

Quote:

Originally Posted by EasyTarget
is there a way to track down which hacks are the troublesome ones using this?

Unfortunatelly no. vBMicroStats analyses the php page in ensemble, then spits the results.
However, there is a tricky way to see what's the "bad" mod in your source.
You need to enable only one mod at the time. Then simply view your pages with the specific mod enabled/disabled.

Compare your stats between the original vBulletin unmodded page and the one with the mod enabled. You will notice rightaway and erratic number of extra queries or abnormal percentages.... and complain to the mod creator. :)

That's why the users loved so much vBMicroStats, it was the first mod that told you what's really going on with your PHP code...
If you find a better way, please share it with the users here.

DementedMindz 05-19-2006 05:09 AM

ok quick question here is what i have so far...

Code:

if ($vbulletin->options['vb_mstats_active'])
{
        $colspan = 1;
        if ($show['quickchooser'])
        {
                $colspan++;
        }
        if ($show['languagechooser'])
        {
                $colspan++;
        }

        $page_endtime = microtime();
        $start_time = explode(' ', $pagestarttime);
        $end_time = explode(' ', $page_endtime);
        $total_time = vb_number_format($end_time[0] - $start_time[0] + $end_time[1] - $start_time[1], $vbulletin->options['vb_mstats_decimal']);

        $query_time = $vbulletin->db->mstime_total;
        $query_count = $vbulletin->db->querycount;

        $php_percent = vb_number_format(((($total_time - $query_time) / $total_time) * 100), 2) . '% PHP';
        $sql_percent = vb_number_format((($query_time / $total_time) * 100), 2) . '% MySQL';

        $ms_output .= '                <span class="smallfont">Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries</span>' . "\n";

        if ($vbulletin->options['vb_mstats_adminactive'] AND $vbulletin->userinfo['usergroupid'] == 6)
        {
                $memory_status = '';
                if ($vbulletin->options['vb_mstats_memory'])
                {
                        if (!function_exists('memory_get_usage'))
                        {
                                function memory_get_usage()
                                {
                                        $mem_output = array();
                                        if (strtolower(substr(PHP_OS, 0, 3)) == 'win')
                                        {
                                                exec('tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $mem_output);
                                                return preg_replace( '/[^0-9]/', '', $output[5] ) * 1024;
                                        }
                                        else
                                        {
                                                $pid = getmypid();
                                                exec("ps -eo%mem,rss,pid | grep $pid", $mem_output);
                                                $mem_output = explode(' ', $mem_output[0]);
                                                return $mem_output[1] * 1024;
                                        }
                                }
                        }
                        $memory_status = vb_number_format((memory_get_usage() / 1024), 2) . 'KB Used | ';
                }

                $debug_status = '';
                if ($vbulletin->options['vb_mstats_debug'])
                {
                        $debug_status = 'DEBUG Mode OFF | ';
                        if ($vbulletin->debug)
                        {
                                $debug_status = 'DEBUG Mode ON | ';
                        }
                }

                $gzip_status = '';
                if ($vbulletin->options['vb_mstats_gzip'])
                {
                        $gzip_status = 'GZIP OFF | ';
                        if ($vbulletin->options['gzipoutput'] AND !$vbulletin->nozip)
                        {
                                $gzip_status = 'GZIP ON (level ' . $vbulletin->options['gziplevel'] . ') | ';
                        }
                }

                $server_status = '';
                if ($vbulletin->options['vb_mstats_server'])
                {
                        if ($stats = @exec('uptime 2>&1') AND trim($stats) != '' AND preg_match("#: ([\d.,]+),?\s+([\d.,]+),?\s+([\d.,]+)$#", $stats, $regs))
                        {
                                $regs[1] = vb_number_format($regs[1], 2);
                                $regs[2] = vb_number_format($regs[2], 2);
                                $regs[3] = vb_number_format($regs[3], 2);
                                $server_status = '<strong>' . $regs[1] . '</strong> : ' . $regs[2] . ' : ' . $regs[3] . ' | ';
                        }
                }

                $templates_status = '';
                if ($vbulletin->options['vb_mstats_templates'])
                {
                        $templates_status = 'NO Uncached Templates';
                        if ($_TEMPLATEQUERIES)
                        {
                                $templates_status  = '<select class="smallfont" size="1">' . "\n";
                                $templates_status .= '<optgroup label="Uncached Templates: ' . sizeof($_TEMPLATEQUERIES) . '">' . "\n";
                                if (is_array($tempusagecache))
                                {
                                        global $vbcollapse;
       
                                        ksort($tempusagecache);
                                        foreach ($tempusagecache AS $tempname => $times)
                                        {
                                                if ($_TEMPLATEQUERIES["$tempname"])
                                                {
                                                        $templates_status .= '<option class="alt2" selected="selected">' . $tempname . ' (' . $times . ')</option>' . "\n";
                                                }
                                                else
                                                {
                                                        $templates_status .= '<option>' . $tempname . ' (' . $times . ')</option>' . "\n";
                                                }
                                        }
                                }
                                $templates_status .= '</optgroup>' . "\n";
                                $templates_status .= '</select>';
                        }
                }
                $ms_output .= '<tr align="' . $stylevar['right'] . '">' . "\n";
                $ms_output .= '        <td class="alt1"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
                $ms_output .= '                <span class="smallfont">' . $memory_status . $debug_status . $gzip_status . $server_status . $templates_status . '</span>' . "\n";
                $ms_output .= '        </td>' . "\n";
                $ms_output .= '</tr>' . "\n";
        }

        $output = str_replace('{microstats}', $ms_output, $output);
}


ok now when i remove the bottom table it all groups in one line... im tryin to keep it 2 lines like you have it but when i remove the admins alt1
Code:

        $ms_output .= '        <td class="alt1"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
thats when it all groups where should i add a break?

Boofo 05-19-2006 05:12 AM

Quote:

Originally Posted by TECK
Bob, I looked at your site, it looks fine?
If you want to place the microstats after the vBulletin copyright (for example), use my second $ms_output template, listed above.

Here's what I see.

EDIT: Ok, I now see what you mean. Am working on it now. Thank you, sir. ;)

DementedMindz 05-19-2006 05:14 AM

here is my screen shot so far of what i have going on... just tryin to figure out the admin table now

DementedMindz 05-19-2006 05:17 AM

here is what i mean if i remove the admin table the alt1 it groups both lines into one...

TECK 05-19-2006 05:19 AM

Bob, post here the actual html code from the page source, not footer template. Start from the beginning of microstats code to the end of footer.
I will fix it, something is wrong with the row colspan, in my mod.

EasyTarget 05-19-2006 05:24 AM

working good for me, though if I view the same exact page without any changes sometimes I'll get php close to 90% and every once in awhile I'll get the sql at like 70%.

TECK 05-19-2006 05:30 AM

Quote:

Originally Posted by DementedMindz
here is my screen shot so far of what i have going on... just tryin to figure out the admin table now

Patience, you are almost there ... :)
First segment of code is ok, but try this instead.
Find:
Code:

        $ms_output .= '                <span class="smallfont">Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries</span>' . "\n";
Replace it with:
Code:

        $ms_output .= 'Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries<br />';
Next, find:
Code:

                $ms_output .= '<tr align="' . $stylevar['right'] . '">' . "\n";
                $ms_output .= '        <td class="alt1"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
                $ms_output .= '                <span class="smallfont">' . $memory_status . $debug_status . $gzip_status . $server_status . $templates_status . '</span>' . "\n";
                $ms_output .= '        </td>' . "\n";
                $ms_output .= '</tr>' . "\n";

Replace it with:
Code:

$ms_output .= $memory_status . $debug_status . $gzip_status . $server_status . $templates_status;
Then, use this code in your footer template:
Code:

        $vbphrase[powered_by_vbulletin]<if condition="$show['microstats']"><br />
        {microstats}</if>


Mr Chad 05-19-2006 05:34 AM

Quote:

Originally Posted by TECK
Patience, you are almost there ... :)
First segment of code is ok, but try this instead.
Find:
Code:

        $ms_output .= '                <span class="smallfont">Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries</span>' . "\n";
Replace it with:
Code:

        $ms_output .= 'Page generated in ' . $total_time . ' seconds (' . $php_percent . ' - ' . $sql_percent . ') with ' . $query_count . ' queries<br />';
Next, find:
Code:

                $ms_output .= '<tr align="' . $stylevar['right'] . '">' . "\n";
                $ms_output .= '        <td class="alt1"' . iif($show['quickchooser'] OR $show['languagechooser'], ' colspan="' . $colspan . '"') . '>' . "\n";
                $ms_output .= '                <span class="smallfont">' . $memory_status . $debug_status . $gzip_status . $server_status . $templates_status . '</span>' . "\n";
                $ms_output .= '        </td>' . "\n";
                $ms_output .= '</tr>' . "\n";

Replace it with:
Code:

$ms_output .= $memory_status . $debug_status . $gzip_status . $server_status . $templates_status;
Then, use this code in your footer template:
Code:

        $vbphrase[powered_by_vbulletin]<if condition="$show['microstats']"><br />
        {microstats}</if>


where are you putting this code?

DementedMindz 05-19-2006 05:35 AM

lol i just got it before i refreshed the page lol thank you very much here is my code in my vBMicroStats Global Hook if anyone wants it like this hope you dont mind if so ill remove it.... just remember members only see the top code not the bottom one...

also i placed my <if condition="$show['microstats']">{microstats}</if> in the copyright part of the footer like this

Code:

<div align="center">
        <div class="smallfont" align="center">
        <!-- Do not remove this copyright notice -->
<br />
        $vbphrase[powered_by_vbulletin]       
        <br />
<!-- Do not remove this copyright notice -->
</div>
       
        <div class="smallfont" align="center">
        <!-- Do not remove $cronimage or your scheduled tasks will cease to function -->
        $cronimage
        <!-- Do not remove $cronimage or your scheduled tasks will cease to function -->
       
        $vboptions[copyrighttext]
<if condition="$show['microstats']">{microstats}</if>
        </div>
</div>


TECK 05-19-2006 05:39 AM

Quote:

Originally Posted by EasyTarget
working good for me, though if I view the same exact page without any changes sometimes I'll get php close to 90% and every once in awhile I'll get the sql at like 70%.

Something is wrong with a mod installed, probably. :)
MySQL is a very smart language. If you run a query for the first time, it will execute it and also store it in the memory, in case you will need to perform it again. That saves server resources.
If you don't use it for a certain period of time, the process is dumped automatically.

This is where you see the critical points in your PHP pages. If every time you load a new page that have wierd mods enabled, MicroStats will warn you with the actual results, creating rightaway a question mark in your mind about the quality of the code you installed.

The best way to see what are the "clean" results of your PHP/MySQL code is to install MicroStats into an unmodded vBulletin test board. Then you can compare the clean results with your board results...

TECK 05-19-2006 05:41 AM

Quote:

Originally Posted by DementedMindz
just remember members only see the top code not the bottom one...

Hmm 24 queries? That's a lot! vBulletin have only 9 queries on the main page.
Watch the server load, it's close to the sky. The bold numbers should not be higher then 1.00, yours are over 3.00.
Are you on a shared server? If you are, contact your host and let them know.
Someone is eating a lot of CPU there...

DementedMindz 05-19-2006 05:43 AM

lol im doing a backup thats why... but the queries you are seeing is from my vbadvanced page...

TECK 05-19-2006 05:44 AM

Quote:

Originally Posted by Mr Chad
where are you putting this code?

The $ms_output code you place it into your vBMicroStats Global Hook plugin.
The second, into your footer template, or any other template you like. ;)


All times are GMT. The time now is 04:54 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.01598 seconds
  • Memory Usage 1,899KB
  • 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
  • (21)bbcode_code_printable
  • (12)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