Giter Site home page Giter Site logo

ss-port-traffic-collect's Introduction

Shadowsocks port traffic collecting

Shadowsocks is able to configure multiple ports and passwords on a single instance. This program can collect traffic data for every port on shadowsocks and save the data to MySQL.

Features

  • No extra shadowsocks configuration
  • Dynamically adding iptables rules and MySQL tables
  • Accumulation and differential traffic data for front-end display

Usage

  • Edit config.json at your will

  • Run the program periodically using something like crontab

      # $PATH is needed
      * * * * * source /home/yourusername/.bash_profile && sudo $GOPATH/bin/ss-port-traffic-collect config.json
    

Technical explaination

Methods

  • Add iptables rules (addrule for short)
  • Create MySQL tables (createtable for short)
  • Calculate port traffic data (collectdata for short)
  • Record traffic data (savedata for short)

In order to avoid maintaining and syncing shadowsocks configuration changes, addrule will check your shadowsocks config file everytime to reflect newest config status, but will not add duplicated rules. createtable will also try to create every port table if it doesn't exist.

collectdata will read accumulated traffic data on a certain port, but will also maintain a file that contains the traffic data last time it read, so that the differential traffic data could be calculated. If traffic data on a port is reset, accumulated traffic data will also be reset, but differential traffic data can continue.

Procedures

The whole process can run concurrently, shown as follows:

    |addrule| -> |collectdata| -> |save|
    |createtable| --------------> |data|

Thanks to Golang's concurrent mechanism, the implemetation is quite simple and straghtforward.

Table structure

The program will generate a table for every port, the structure is as follows:

    | traffic_diff | BIGINT NOT NULL DEFAULT 0                       |
    | collect_time | TIMESTAMP DEFAULT CURRENT_TIMESTAMP PRIMARY KEY |

ss-port-traffic-collect's People

Contributors

shanehou avatar

Watchers

 avatar

Forkers

newacorn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.