Skip to main content

A simple port traffic monitor

Project description

# portstat

![]( ![]( ![](

A simple port traffic monitor

## Install

### Install pip

For Debian / Ubunut user

apt-get update
apt-get install python-pip

### Install portstat

pip install portstat

### System setting

Add the following line to `/etc/rc.local` to run portstat on the startup.

Notice that add it before `exit 0` .

/sbin/iptables -N PORTSTAT
/sbin/iptables -A INPUT -j PORTSTAT
/sbin/iptables -A OUTPUT -j PORTSTAT
/bin/bash /etc/portstat.rules

To upload the traffic information every minute, we should add the following line in `crontab -e`

* * * * * /usr/local/bin/portstat -u

Run it every 5 minutes like the following

*/5 * * * * /usr/local/bin/portstat -u

To activate the new iptables rules, please run the `/sbin/iptables` command manually or issue a `reboot` command.

After that, you have installed portstat successfully.

## Upgrade

Every new version I will upload it to pypi so that you can upgrade to the latest version with the following code.

pip install -U portstat

For some unexpectable reason, I can NOT promise that you can upgrade to the latest version without change your settings.

So, please come back to see what's new at every upgrade.

## Usage

usage: portstat [-h] [-c CONFIG] [-v | -s | -u]

A simple port traffic monitor

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Path of the config file.
-v, --version Show portstat version.
-s, --sync Sync the portstat settings and iptables.
-u, --upload Upload the port stat with webhook.

## Tutorial

First of all, you should install portstat as I mentioned above.

Create a conf in where you like, by default the path is `/etc/portstat.conf`, just remenber use `-c path` to declare the config file if you don't use the default path.
The conf file should looks like that:




`[name]` used to distinguish every port you want to monitor.

`Port=111` used to declare the port you want to monitor, it should be a int like `111` , or a range like `10000-10010`, or `80,81,8080,8888` .

`Webhook=` used to received the traffic information, portstat will post the information to the webhook like that


Then, save the config file.

Run `portstat -s` to create new iptables rules to monitor the port you just add.

Run `portstat -u` to upload to port traffic information to webhook manually.

## Contribution

- [Issue](
- [Pull Request](

## License

Licensed under the Apache License, Version 2.0

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for portstat, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size portstat-0.0.6.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page