manuelkasper / AS-Stats

A simple tool to generate per-AS traffic graphs from NetFlow/sFlow records
BSD 2-Clause "Simplified" License
195 stars 67 forks source link

AS-Stats v1.6 (2014-09-12)

A simple tool to generate per-AS traffic graphs from NetFlow/sFlow records
by Manuel Kasper mk@neon1.net for Monzoon Networks AG

Update 2017-02-15

I currently don't have time to maintain AS-Stats. There have been some (merged) contributions since the last release, so you may want to download the latest repository version instead of the v1.6 release. Also, Nicolas Debrigode has released a more modern Web UI for AS-Stats: https://github.com/nidebr/as-stats-gui

How it works

A Perl script (asstatd.pl) collects NetFlow v8/v9 AS aggregation records or sFlow v5 samples from one or more routers. It caches them for about a minute (to prevent excessive writes to RRD files), identifies the link that each record refers to (by means of the SNMP in/out interface index), maps it to a corresponding "known link" and RRD data source, and then runs RRDtool. To avoid losing new records while the RRD files are updated, the update task is run in a separate process.

For each AS, a separate RRD file is created as needed. It contains two data sources for each link - one for inbound and one for outbound traffic. In generated per-AS traffic graphs, inbound traffic is shown as positive, while outbound traffic is shown as negative values.

Another Perl script, rrd-extractstats.pl, is meant to run about once per hour. It sums up per-AS and link traffic during the last 24 hours, sorts the ASes by total traffic (descending) and writes the results to a text file. This is then used to display the "top N AS" and other stats by the provided PHP scripts.

Prerequisites

Considerations

Thoughts on a location for RRD files: RRD files are small in size, but there are a lot of them. You will see a performance gain on a filesystem like XFS over EXT3/4. Consider what filesystem you put the RRD files on if performance is a factor for your needs.

Installation

Adding a new link

Adding a new link involves adding two new data sources to all RRD files. This is a bit of a PITA since RRDtool itself doesn't provide a command to do that. A simple (but slow) Perl script that is meant to be used with RRDtool's XML dump/restore feature is provided (add_ds_proc.pl, add_ds.sh). Note that asstatd.pl should be stopped while modifying RRD files, to avoid breaking them with concurrent modifications.

Before you follow the instructions below:

Instructions for adding a new link:

  1. Edit your known links file and add your new link (see above for syntax)
    Example:

    10.1.17.10      33      router-newlink  Friendlyname     1F78B4  1
  2. Edit the script tools/add_ds_proc.pl

    Change this line:
    my $newlinkname = 'newlink';

    To have the same ID in your knownlinks file:
    my $newlinkname = 'router-newlink';

  3. Edit the script tools/add_ds.sh

    Make sure the path to add_ds_proc.pl is correct.

  4. cd into the rrd folder:
    cd rrd

  5. Run the script
    /path/to/add_ds.sh

    This will take a while (around 20 minutes), so go get a cup of coffee.

  6. Start the collector back up again, and watch for new graphs!

You can also read the RRD files with the command rrdtool info file.rrd, which will show you the data sourced in each one.

Changing the RRAs

By default, the created RRDs keep data as follows:

* 48 hours at 5 minute resolution
* 1 week at 1 hour resolution
* 1 month at 4 hour resolution
* 1 year at 1 day resolution

If you want to change that, modify the getrrdfile() function in asstatd.pl and delete any old RRD files.

Support

A mailing list is available at https://groups.google.com/d/forum/as-stats-users. Please do not send requests for help/support directly to the author.

Donations

To do