Monitor your AS upstream flows with as-stats

For BGP traffic engineering it's very important to know which Destination-AS takes which path on your Upstream links.

There is a great tool to visualize this: as-stats. It's too bad that this nice piece of software lacks some very important things: There is no init script available, it does not run as a daemon by itself, it's not packaged (neither as Debian nor as RPM package) and the directory structure does not follow any standard.

I took this piece of software to gain knowledge on how to create a simple Debian package with FPM and Rake and how to write a simple Upstart job for Ubuntu. Last but not least I created a Puppet module for it. Here is how I did it:

Rake and FPM

Rake is an equivalent to the widely known make, written in Ruby. The Rakefile is also written in Ruby. My very first Rakefile for building a Debian package of as-stats is on Github.

For using it, rake has to be installed (obviously): gem install rake and you're done. This assumes you have a running Ruby and GEM installation on your system.


  • rake clean: remove all created dirs
  • rake prepare[1.36]: downloads and prepares as-stats version 1.36
  • rake build: creates debian package

Now you have a simple Debian package, built with FPM, saved under packages/. If you want to know how you can use FPM for yourself, my co-worker has written a nice blog post about it: Hubot, Ubuntu and .deb Packages


We use Jenkins at work to build software. I've created a parametrized (for the version parameter) Jenkins job which pulls the Rakefile from Git, runs the above three commands and copies the new package to our repository. This allows me to build a new Package if a new version of as-stats arrives with one click in Jenkins. This is really nice.

Upstart job

Because as-stats did not contain a start script, I added an modern Upstart job to the Package. It's very easy to write one. This is how it looks for as-stats:

description "as-stats"
author "Tobias Brunner <>"
start on runlevel [2345]
stop on runlevel [06]
    . /etc/default/as-stats
    exec su -s /bin/sh -c 'exec "$0" "$@"' $USER -- exec /usr/local/bin/ -r $RRD_DIR -p $LISTEN_PORT -k /etc/as-stats/knownlinks -a $AS -s $SAMPLING
end script

This is enough to have a configurable (through /etc/default/as-stats) daemon.
It even runs as it's own user, this is more secure than running as root.

More information on how to create an Upstart job can be found on

Puppet Module

Now we have a nice little Debian package which can be installed and configured with Puppet. Therefor I've written a Puppet Module which also is on Github.

The usage is very simple:

$knowlinks = [
    { ip          => '',
      ifindex     => '15',
      tag         => 'uplink1',
      description => 'Uplink 1',
      color       => 'D41C0E' },
    { ip          => '',
      ifindex     => '23',
      tag         => 'uplink2',
      description => 'Uplink 2',
      color       => 'E45605' },
class { ::asstats:
  asnumber   => '1234',
  knownlinks => $knownlinks,

The variable $knownlinks is a Puppet Hash. I like this data type because it's very simple to iterate over it in an ERB template.


With this tools (Rake, FPM, Jenkins, Upstart, Puppet) it's very easy to deploy a software which is not distributed as package, nor has any startup scripts and even doesn't run as daemon by itself. This is why I love OpenSource.

You've successfully subscribed to Tobias Brunner aka tobru
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.