Community discussions

MikroTik App
 
dannyboy
Member Candidate
Member Candidate
Topic Author
Posts: 195
Joined: Fri Sep 16, 2005 4:21 am
Location: Nicaragua/USA
Contact:

graphs using pppoe server

Sun Oct 22, 2006 11:41 pm

Hello,

I use pppoe for my clients to connect and I am testing out the graph tool. Its a great tool to find out who consumes the most bandwidth. The only problem that I have is that once that user disconnects and connects again the graphs strats from scratch. How can I make it so it saves the graph. I have selected to save on disk every five minutes but once I reboot or the client disconects its starts from scratch.

thanks,
DB
 
Freman
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Mon Oct 23, 2006 5:49 am

You might have to set up an rrdgraph and snmp script on a remote machine.

Part of the reason the graph resets is becaues every time a user connects they (in essence) get a different identifier - it's a little more complex then that, but that's the basics.
 
Freman
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Mon Oct 23, 2006 8:41 am

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.
 
dannyboy
Member Candidate
Member Candidate
Topic Author
Posts: 195
Joined: Fri Sep 16, 2005 4:21 am
Location: Nicaragua/USA
Contact:

Mon Oct 23, 2006 6:07 pm

Thanks a lot I will try
 
hrober
newbie
Posts: 41
Joined: Fri Jun 02, 2006 3:32 pm
Location: Brazil

Re: graphs using pppoe server

Wed Jan 06, 2010 4:59 pm

Freman,

Thanks a lot. It's really a very nice script.
 
dziadzi
just joined
Posts: 19
Joined: Wed Feb 24, 2010 2:32 pm

Re: graphs using pppoe server

Wed Oct 06, 2010 12:48 am

I'm using this script but I received some problems. Some users graphs are "fragmented" I suppose this due to the fact, that when user is disconnected, pppoe interface does not exist and paticular rrd database is not updated then. Did someone solve this problem somehow?
You do not have the required permissions to view the files attached to this post.
 
magnavox
Member
Member
Posts: 357
Joined: Thu Jun 14, 2007 1:03 pm

Re: graphs using pppoe server

Fri Oct 09, 2015 11:40 am

solved? :)

Who is online

Users browsing this forum: FurfangosFrigyes, sybadi and 84 guests