Over a million developers have joined DZone.

Traffic Meter By Xorkrus :)

DZone's Guide to

Traffic Meter By Xorkrus :)

Free Resource
// harsh but worker

use DBD::mysql;
use DBI;
$nowdate = `date +'%Y%m%d'`;chop($nowdate);
$host = ('localhost');
$dbase = ('tmbx');
$user = ('tmbx');
$pass = ('tmbx');
$tzinb = `cat /proc/net/dev | grep ppp0 | awk '{printf \$2}'`;
$tzoutb = `cat /proc/net/dev | grep ppp0 | awk '{printf \$10}'`;
$trc = DBI->trace(0);
        my $dbh = DBI->connect("DBI:mysql:$dbase;$host", "$user", "$pass",{'RaiseError' => 1});
        $lsn = $dbh->prepare("SELECT MAX(sn) FROM session") or die print "$DBI::errstr\n";
        my $ref = $lsn->fetchrow_hashref();
        $mlsn = $ref->{'MAX(sn)'};
        my $oth = $dbh->prepare("SELECT * FROM session WHERE sn='$mlsn'") or die print "$DBI::errstr\n";
        my $refa = $oth->fetchrow_hashref();
        $tinb = $refa->{'inb'};
        $toutb = $refa->{'outb'};
        $tdate = $refa->{'date'};
        $nsn = $mlsn+1;
        $tndate = `echo $tdate | sed -e 's/-//'|sed -e 's/-//'`;chop($tndate);
if ($tzinb > $tinb && $tndate < $nowdate) {
        $nzinb = $tzinb-$tinb;
        $nzoutb = $tzoutb-$toutb;
        my $sth = $dbh->prepare("INSERT INTO session (date, sn, inb, outb) VALUES ('$nowdate', '$nsn', '$nzinb', '$nzoutb')") or die print "$DBI::errstr\n";
if ($tzinb > $tinb && $tndate == $nowdate) {
        my $sth = $dbh->prepare("UPDATE session SET date='$nowdate', sn='$mlsn', inb='$tzinb', outb='$tzoutb' WHERE sn='$mlsn';") or die print "$DBI::errstr\n";
if ($tzinb < $tinb) {
        my $sth = $dbh->prepare("INSERT INTO session (date, sn, inb, outb) VALUES ('$nowdate', '$nsn', '$tzinb', '$tzoutb');") or die print "$DBI::errstr\n";
sub DayRef {
        my $ath = $dbh->prepare("SELECT SUM(inb), SUM(outb) FROM session WHERE date='$ddate'") or die print "$DBI::errstr\n";
        my $aref = $ath->fetchrow_hashref();
        $mtinb = $aref->{'SUM(inb)'};
        $mtoutb = $aref->{'SUM(outb)'};
        my $ath2 = $dbh->prepare("INSERT INTO traffic (date,inb,outb) VALUES ('$ddate','$mtinb','$mtoutb')") or die print "$DBI::errstr\n";

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}