Here, this basic script should produce a rrd and a graph for every user on PPPoE.
First you need to install Net::SNMP and RRD::Simple
Under linux this is as simple as
# cpan Net::SNMP
# cpan RRD::Simple
#!/usr/bin/perl
##############################################################################
# Usergraph 1.0 ##############################################################
################################################################## By Freman #
############################# http://fremnet.net #############################
##############################################################################
#
# Copyright (C) 2006 Shannon Wynter
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U
#
# The GPL Can be found here: http://www.gnu.org/copyleft/gpl.html
#
##############################################################################
# Important variables
## RRDDir - The directory to store all your RRD files, this should be writable
my $RRDDir = "/var/db/usergraph/rrd";
## GraphImageDir - The directory to store all the Graph image files, this
## should also be writable
my $GraphImageDir = "/var/www/localhost/htdocs/rrdimages";
use strict;
use Net::SNMP;
use RRD::Simple;
sub fetchData {
my $Host = $_[0];
my ($session,$error) = Net::SNMP->session(
-hostname => $Host,
-version => 1,
-community => 'public',
);
die("Error: ".$error) if ($error);
# Collect the interfaces, inOctets and outOctets from the Mikrotik
my %Interfaces = %{$session->get_table(-baseoid => '1.3.6.1.2.1.2.2.1.2')};
my %InOctets = %{$session->get_table(-baseoid => '1.3.6.1.2.1.2.2.1.10')};
my %OutOctets = %{$session->get_table(-baseoid => '1.3.6.1.2.1.2.2.1.16')};
# Make a dir for the host if one doesn't exist
my $Dir = "$RRDDir/$Host";
mkdir($Dir) if (!-d $Dir);
my $rrd = RRD::Simple->new();
# Loop through all the interfaces
while (my($ID, $Name) = each(%Interfaces)) {
# Strip off all but the last block from the MIB
$ID =~ s/.+\.(\d+)$/$1/;
# Strip the extra garbage off pppoe interface names
$Name =~ s/<pppoe-(.*?)(?:-\d+)?>/$1/i if ($Name =~ /<pppoe/i);
my $File = "$Dir/$Name.rrd";
# Create a new file if it doesn't exist
if (!-e $File) {
$rrd->create(
$File,
bytesIn => "COUNTER",
bytesOut => "COUNTER"
);
}
# Update the data in the file
$rrd->update(
$File,
bytesIn => $InOctets{'1.3.6.1.2.1.2.2.1.10.'.$ID},
bytesOut => $OutOctets{'1.3.6.1.2.1.2.2.1.16.'.$ID}
);
# Attempt to make the images dir
mkdir("$GraphImageDir/$Host") if (!-d "$GraphImageDir/$Host");
# Draw individual graphs for the users
$rrd->graph(
$File,
destination => "$GraphImageDir/$Host",
basename => $Name,
sources => [ qw(bytesIn bytesOut) ],
source_colors => [ qw(ff0000 aa3333) ],
source_labels => [ ("bytesIn", "bytesOut") ],
source_drawtypes=> [ qw(AREA LINE) ],
line_thickness => 2,
extended_legend => 1,
title => "$Name - Bytes Per Second",
vertical_label => "Bytes/Sec"
);
}
}
die("Syntax: $0 <ipaddress>\nExample: $0 10.0.0.2\n\n") if (!@ARGV);
fetchData($ARGV[0]);
Simply save the file to disk, then add it to crontab.
Later if I have the time I'll knock up a script to graph all/selected users on the same graph.