pawel-slowik / network-stats

Save Linux network traffic statistics into a SQLite database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

This script periodically reads Linux network traffic statistics from /proc/net/dev and saves the data into a SQLite database.

Installation

There is no installation script yet. Just copy the networkstats.py file into /usr/local/bin or wherever you want it. The script requires Python 3.x to run. Only the Python standard library is required, there's no need to install any additional modules.

Usage

Run:

/usr/local/bin/networkstats.py /path/networkstats.db

Run with --help for a list of options.

Running as a system wide daemon

The script intentionally does not behave like a Unix daemon, because:

  1. implementing correct daemon behaviour is complicated and
  2. there are wrappers and other tools that add that functionality.

For example, you could use daemonize like this:

daemonize \
-p /var/run/network-stats.pid \
-l /var/lock/network-stats.lock \
-u network-stats \
/usr/local/bin/networkstats.py /var/db/network-stats/network-stats.db

Displaying statistics

Take a look at the example queries in examples/*.sql files. Enter queries at the SQLite console, e.g.:

$ sqlite3 -header -column /var/db/network-stats/network-stats.db

sqlite> .read examples/last_week.sql

week_date   traffic_MiB
----------  -----------
2019-01-11  220
2019-01-12  757
2019-01-13  552
2019-01-14  950
2019-01-15  337
2019-01-16  214
2019-01-17  386

About

Save Linux network traffic statistics into a SQLite database

License:MIT License


Languages

Language:Python 100.0%