PDA

View Full Version : Use MRTG to graph new posts and online users!


discore
28 Oct 2002, 22:44
Well this isn't really a hack so let's post it here.

If you're the type of person who would prefer everything had a graph, this "hack" is for you.

Example: http://flamevault.com/mrtg/board

The installation of this is a bit hardcore if you don't have MRTG, Perl, or a common Perl module (DBI) installed. A bit of Unix background could help too (oh yeh, it only works on Unix/Linux/etc servers for now).

See attachment for scripts, mrtg config, and installation instructions. I'll help as much as I can if you're having trouble installing so feel free to ask.

Updated 12-01-03 to fix errors discussed below!

Martz
24 Nov 2002, 18:08
I've actually got this working now! Sheesh, lots of dependancies, although that was the first time I have used cpan - updates things nice and easily.

I had to use force install DBD::mysql because for some reason it couldn't connect to mysql with the username and password it was trying with during testing.

Few tweaks and typo removals means I should now be working ok: http://forums.utassault.net/mrtg/vb/

Many thanks for this hack.

nester
08 Jun 2003, 04:03
I installed this.. no problem at all getting it to work.. but it seems to report way more sessions than really exist.

For example, my forum reports "Most users ever online was 55 on 04-24-2003 at 11:39 PM.", however, my mrtg stats page says "Max Online 66.0 Users"

Any idea on why this happens and/or how to fix it?

Dave#
27 Nov 2003, 13:54
Well this isn't really a hack so let's post it here.

If you're the type of person who would prefer everything had a graph, this "hack" is for you.

Example: http://flamevault.com/mrtg

The installation of this is a bit hardcore if you don't have MRTG, Perl, or a common Perl module (DBD::mysql) installed. A bit of Unix background could help too (oh yeh, it only works on Unix/Linux/etc servers for now).

See attachment for scripts, mrtg config, and installation instructions. I'll help as much as I can if you're having trouble installing so feel free to ask.

Well done - excellent work but I'm also getting incorrect values

274 users online is being reported as 146 :(

Erwin
28 Nov 2003, 01:08
Wow... good work integrating vB with MRTG...

Princeton
28 Nov 2003, 02:01
this is great feedback to administrators and users (if needed) .. however, can the images be directly linked (embedded) into another page?

Dave#
28 Nov 2003, 18:28
this is great feedback to administrators and users (if needed) .. however, can the images be directly linked (embedded) into another page?

for sures



http://www.fu-1.net/mrtg/posts-day.png

Erwin
29 Nov 2003, 00:43
That's so cool...

Dave#
29 Nov 2003, 07:16
That's so cool...

I know - I wish I knew why the online users graph data is wrong :(

Anybody heard from the author?


https://www.vbulletin.org/forum/

Dean C
29 Nov 2003, 09:38
Looks a bit complicated to me :p

Erwin
30 Nov 2003, 04:55
I know - I wish I knew why the online users graph data is wrong :(

Anybody heard from the author?


http://www.fu-1.net/mrtg/users-day.png
Wish I have time to look into this... I'm in the middle of law exams... try emailing the author - he may not visit here for a while...

Dave#
01 Dec 2003, 10:49
Wish I have time to look into this... I'm in the middle of law exams... try emailing the author - he may not visit here for a while...

yeah - have emailed him.

I amm just looking over the code and I still can't work out what the issue is

here is the query

"SELECT DISTINCT COUNT(*) FROM session LEFT JOIN user ON (user.userid=session.userid) WHERE session.userid>0 AND session.lastactivity>900"

This is giving me a result of 156 when there are infact 240 users online :(

discore
01 Dec 2003, 12:42
Hi! Glad to see some people are enjoying this little hack. Now if only it worked correctly!

I reviewed the script and figured out major flaw #1: It wasn't calculating guests, only registered users. That is now fixed, all online users are accounted for.

The second flaw is more complex. vB's "Who's Online" uses the Cookie Timeout from your vB options to decide who is currently online. This is by default set at 900 seconds (15 minutes). MRTG by nature runs every 5 minutes (300 seconds). To get truely accurate graphs you should set $cookie_expire in the .pl script to 300 seconds, hence only counting users who have been active in the last 5 minutes. This will report considerably less users than vB does, simply because you limit the time range. Alternately, to report what vB's "Who's Online" says, set this to whatever your Cookie Timeout is. It's up to you. Personally I prefer accuracy and use 300 seconds.

Furthermore, it's still slightly inaccurate if you set $cookie_timeout to your vB setting. I was testing it with $cookie_timeout set at 900 seconds (my vB setting) and Who's Online showed 13-15 users, but the .pl script reported 16-17. The query the .pl script uses to get these numbers is so straightforward it seems hard to make a mistake. Maybe a true vB guru can comment on who Who's Online numbers are gathered vs how the .pl script gets them.

At least it's much more accurate now that guests are counted :)

Here (http://flamevault.com/~discore/vbmrtg/updated.txt) is an updated copy of the .pl script. If you already had this working, this is the only file changed. I also fixed some typos in the other scripts and rewrote parts of the README file to be clearer for anyone who chooses to install this in the future. The attachment in the first post has been updated.

I'll keep an eye on this thread, but feel free to email (filter@discore.org) too.

Dave#
01 Dec 2003, 13:08
Thanks for the update - have put your updated code in the script - will see how that pans out.

Couple of comments now we have your attention :)

The script only allows one value for $data and this gets passed to mrtg - this is fine but I have modified your script to graph some other data like registered users, totposts and total threads

http://www.fu-1.net/mrtg/regusers.html
http://www.fu-1.net/mrtg/totposts.html
http://www.fu-1.net/mrtg/totthreads.html

I'd like to be able to graph threads/posts on the same graph but am struggling with the Perl :)

Also do you know how to to stop MRTG converting values into K ie 6.4K rather than 6,400?

Finally I am using this remotely so your script calls uptime on the box running mrtg not the mysql box :)

Again - thanks for doing this - VERY cool

discore
01 Dec 2003, 15:05
The script only allows one value for $data and this gets passed to mrtg - this is fine but I have modified your script to graph some other data like registered users, totposts and total threads

http://www.fu-1.net/mrtg/regusers.html
http://www.fu-1.net/mrtg/totposts.html
http://www.fu-1.net/mrtg/totthreads.html

I'd like to be able to graph threads/posts on the same graph but am struggling with the Perl :)

2 things is no problem. MRTG can't graph more than 2 things at a time (as far as I know). Maybe other graphing programs like Cricket are more flexible, not sure.

But we can at least combine Total Posts/Threads. Use this script (http://flamevault.com/~discore/modvbmrtg.txt) which adds a new "totaltp" section and makes displaying 2 numbers possible. Then add this to your MRTG config file:

# Total threads/posts
Target[totaltp]: `/etc/mrtg/vB.pl totaltp`
MaxBytes[totaltp]: 10000000
Title[totaltp]: Total Threads/Posts
PageTop[totaltp]: <H1>Total Threads/Posts</H1>
ShortLegend[totaltp]: Threads/Posts
YLegend[totaltp]: Threads/Posts
Legend1[totaltp]: Total Threads
Legend2[totaltp]: Total Posts
LegendI[totaltp]: Threads
LegendO[totaltp]: Posts
Options[totaltp]: growright,nopercent,gauge

Changing the the path to vB.pl of course. That will give you graphs that look like this (http://flamevault.com/mrtg/board/totaltp.html). Doesn't look that great with my board's 1:20ish thread to post ratio, but the new code and configuration should make further modifications easier.

Also do you know how to to stop MRTG converting values into K ie 6.4K rather than 6,400?

The best way I've found is by adding:

kMG[totaltp]: ,,

To the MRTG config. "totaltp" gets replaced by whatever label is appropiate. This doesn't change the digits on the YLegend (left side digits on the graphic), probably because they'd get too big to fit in the image. All of the configuration directives can be found here (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/reference.html). Maybe there's a better way.


Finally I am using this remotely so your script calls uptime on the box running mrtg not the mysql box :)

Hehe, you could maybe run SNMP on the database server and rewrite the script to get date/time of remote machine via SNMP, but that's quite a bit of work for something as arbitrary as uptime. You're probably best off simply adding "noinfo" to the Options for each label to supress the whole bit about uptime.

Erwin
02 Dec 2003, 01:21
I still think this qualifies as a hack. I am moving it... :)

Dave#
02 Dec 2003, 11:17
I still think this qualifies as a hack. I am moving it..

Now it takes me 10 minutes to find the thread :(

These forums really are sunforum hell :)

discore - many thanks for the update - this is really great :)

http://www.fu-1.net/mrtg/

Erwin
03 Dec 2003, 01:29
Looks great Dave. :)

Use the "Old Layout" link from the homepage. :)

Weasel
03 Dec 2003, 05:55
This hack does not take into consideration TABLE_PREFIX. booo.

Also anyone know what this means?

It still creates the log files and images though, I'm not sure if they work though because the images dont have any data to plot so far.


Rateup WARNING: /usr/bin/rateup could not read the primary log file for posts
Rateup WARNING: /usr/bin/rateup The backup log file for posts was invalid as wel
l
Rateup WARNING: /usr/bin/rateup Can't remove posts.old updating log file
Rateup WARNING: /usr/bin/rateup Can't rename posts.log to posts.old updating log
file
Rateup WARNING: /usr/bin/rateup could not read the primary log file for users
Rateup WARNING: /usr/bin/rateup The backup log file for users was invalid as wel
l
Rateup WARNING: /usr/bin/rateup Can't remove users.old updating log file
Rateup WARNING: /usr/bin/rateup Can't rename users.log to users.old updating log
file

Dave#
03 Dec 2003, 07:42
The rateup warning will happen the first time you run the script when the log files are first populated - it's normal

discore
03 Dec 2003, 14:01
This hack does not take into consideration TABLE_PREFIX. booo.

I'm not sure what you mean by that. Explain and I'll make it take TABLE_PREFIX into consideration if I can! :)

Weasel
04 Dec 2003, 03:41
I'm not sure what you mean by that. Explain and I'll make it take TABLE_PREFIX into consideration if I can! :)

vB 3 allows you to specify a table prefix in your includes/config.php file. This is used in front of all table names and is defined globally in global.php as TABLE_PREFIX. My table prefix is vb3_, so I had to go into your script and change it to vb3_post, vb3_session etc..

I realise that it's not that hard to edit your hack queries and it will be necessary to add another variable at the top of your script since you dont include gobal.php but it should still be done.

mlevenson
03 Apr 2004, 06:39
Does anyone have this working normally on VB3? There are some updated files on here but he links are no longer valid. Help, I loved having this on VB2, now I want it back on VB3.

webrats
25 Jan 2005, 14:15
bump for help with vb3

webrats
31 Jan 2005, 23:22
anyone update ????

webrats
15 Feb 2005, 21:18
anyone please update for vb3

webrats
16 Feb 2005, 01:02
well i have got it loggin online users
http://alpha.webrats.com/mrtg/online.html this is total users on guest and members

but i am havin a problem with total post threas etc

my script keeps adding a comma to the out put which screws up mrtg

if anyone could help convert my php to sh/perl that would be great

nexialys
16 Feb 2005, 02:02
wrong forum...

amykhar
16 Feb 2005, 02:17
wrong forum...
Not anymore, Nex. :D I merged it with the support thread.