PDA

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


discore
10-27-2002, 10:00 PM
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
11-24-2002, 05:08 PM
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
06-08-2003, 03:03 AM
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#
11-27-2003, 12:54 PM
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
11-28-2003, 12:08 AM
Wow... good work integrating vB with MRTG...

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

Dave#
11-28-2003, 05:28 PM
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
11-28-2003, 11:43 PM
That's so cool...

Dave#
11-29-2003, 06:16 AM
That's so cool...

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

Anybody heard from the author?


https://vborg.vbsupport.ru/

Dean C
11-29-2003, 08:38 AM
Looks a bit complicated to me :p

Erwin
11-30-2003, 03:55 AM
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#
12-01-2003, 09:49 AM
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
12-01-2003, 11:42 AM
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#
12-01-2003, 12:08 PM
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
12-01-2003, 02:05 PM
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
12-02-2003, 12:21 AM
I still think this qualifies as a hack. I am moving it... :)

Dave#
12-02-2003, 10:17 AM
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
12-03-2003, 12:29 AM
Looks great Dave. :)

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

Weasel
12-03-2003, 04:55 AM
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#
12-03-2003, 06:42 AM
The rateup warning will happen the first time you run the script when the log files are first populated - it's normal

discore
12-03-2003, 01:01 PM
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
12-04-2003, 02:41 AM
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
04-03-2004, 05:39 AM
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
01-25-2005, 01:15 PM
bump for help with vb3

webrats
01-31-2005, 10:22 PM
anyone update ????

webrats
02-15-2005, 08:18 PM
anyone please update for vb3

webrats
02-16-2005, 12:02 AM
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
02-16-2005, 01:02 AM
wrong forum...

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