webrats
02-16-2005, 12:44 AM
#!/usr/bin/perl -w
#
# vBulletin MRTG grapher by discore (tyler@xmission.com)
#
use strict;
use DBI;
################################################## ##############################
## CHANGE this stuff ##
################################################## ##############################
# MySQL info
my $sqluser = "USERNAME";
my $sqlpass = "PASSWORD";
my $sqlhost = "localhost"; # host of your database
my $database = "DATABASE";
# Your board's name
my $name = "Your Board Name";
# Your 'Timeout for Cookie'
#
# Set this to 300 if you want truely accurate graphs. This will report
# considerably less users online than vB does.
# Or, set this to whatever you "Timeout for Cookie" setting from your vB
# Options is to report online users the same way "Who's Online" does.
my $cookie_expire = "300";
# Location of 'uptime' program
my $uptime_bin = "/usr/bin/uptime";
################################################## ##############################
## Logically won't need to touch anything after here ##
################################################## ##############################
# connect to the database
my $dba = "DBI:mysql:database=$database;host=$sqlhost";
my $dbh = DBI->connect("$dba","$sqluser", "$sqlpass",{'RaiseError' => 1})
|| die "Could not connect to database: $!\n";
my $data; # output
# get number of posts in the last 5 minutes
if($ARGV[0] eq "posts") {
my $time = time()-300;
my $query = $dbh->selectrow_hashref("SELECT COUNT(*) AS count FROM post WHERE dateline>=$time");
my $totalnewposts = $query->{'count'};
$data = $totalnewposts;
}
# get number of online users
elsif($ARGV[0] eq "users") {
my $time = time()-$cookie_expire;
my $query = $dbh->selectrow_hashref("SELECT COUNT(*) AS sessions FROM session WHERE lastactivity>$time");
my $totalonline = $query->{'sessions'};
$data = $totalonline;
}
$dbh->disconnect();
# get uptime
my $uptime = `$uptime_bin`;
$uptime =~ /up (.*?),/;
$uptime = $1;
chomp($uptime);
# print out info for MRTG
print <<EOF;
$data
$data
$uptime
$name
EOF
#
# vBulletin MRTG grapher by discore (tyler@xmission.com)
#
use strict;
use DBI;
################################################## ##############################
## CHANGE this stuff ##
################################################## ##############################
# MySQL info
my $sqluser = "USERNAME";
my $sqlpass = "PASSWORD";
my $sqlhost = "localhost"; # host of your database
my $database = "DATABASE";
# Your board's name
my $name = "Your Board Name";
# Your 'Timeout for Cookie'
#
# Set this to 300 if you want truely accurate graphs. This will report
# considerably less users online than vB does.
# Or, set this to whatever you "Timeout for Cookie" setting from your vB
# Options is to report online users the same way "Who's Online" does.
my $cookie_expire = "300";
# Location of 'uptime' program
my $uptime_bin = "/usr/bin/uptime";
################################################## ##############################
## Logically won't need to touch anything after here ##
################################################## ##############################
# connect to the database
my $dba = "DBI:mysql:database=$database;host=$sqlhost";
my $dbh = DBI->connect("$dba","$sqluser", "$sqlpass",{'RaiseError' => 1})
|| die "Could not connect to database: $!\n";
my $data; # output
# get number of posts in the last 5 minutes
if($ARGV[0] eq "posts") {
my $time = time()-300;
my $query = $dbh->selectrow_hashref("SELECT COUNT(*) AS count FROM post WHERE dateline>=$time");
my $totalnewposts = $query->{'count'};
$data = $totalnewposts;
}
# get number of online users
elsif($ARGV[0] eq "users") {
my $time = time()-$cookie_expire;
my $query = $dbh->selectrow_hashref("SELECT COUNT(*) AS sessions FROM session WHERE lastactivity>$time");
my $totalonline = $query->{'sessions'};
$data = $totalonline;
}
$dbh->disconnect();
# get uptime
my $uptime = `$uptime_bin`;
$uptime =~ /up (.*?),/;
$uptime = $1;
chomp($uptime);
# print out info for MRTG
print <<EOF;
$data
$data
$uptime
$name
EOF