GithubHelp home page GithubHelp logo

vadimmarkov / mikrotik-traffic-counter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muhannad0/mikrotik-traffic-counter

0.0 0.0 0.0 49 KB

Home Page: https://mikrotik-traffic-counter.vercel.app

PHP 100.00%

mikrotik-traffic-counter's Introduction

Simple Mikrotik Traffic Counter

A simple PHP application to collect interface statistics from Mikrotik router and display the usage (upload/download). You can host this application anywhere on the network or Internet.

Features

  • Collect tx/rx stats from routerboard.
  • Display hourly graph.
  • Display daily/weekly/monthly summary.

Usage

Setup the Mikrotik router to collect and send the stats to the application first.

  1. Create firewall mangle rules that will collect the traffic stats.
/ip firewall mangle
  add chain=forward src-address=192.168.88.0/24 out-interface=pppoe-out1 action=passthrough comment=local-wan-tx
  add chain=forward dst-address=192.168.88.0/24 in-interface=pppoe-out1 action=passthrough comment=local-wan-rx

Here, I am monitoring usage for a specific subnet, going through a PPP connection for Internet.

  1. Add the following script that will get the data and send it to the application.
:local wantxcomment "local-wan-tx"
:local wanrxcomment "local-wan-rx"
:local sysnumber [/system routerboard get value-name=serial-number]
:local txbytes [/ip firewall mangle get [/ip firewall mangle find comment="$wantxcomment"] bytes]
:local rxbytes [/ip firewall mangle get [/ip firewall mangle find comment="$wanrxcomment"] bytes]
/tool fetch url=("http://<server ip/url>/collector.php\?sn=$sysnumber&tx=$txbytes&rx=$rxbytes") mode=http keep-result=no
/ip firewall mangle reset-counters [/ip firewall mangle find comment="$wantxcomment"]
/ip firewall mangle reset-counters [/ip firewall mangle find comment="$wanrxcomment"]
:log info ("cleared counters for all mangle rules")

Edit the <server ip/url> to match where application is hosted.

  1. Set a scheduler to run the script at 1 hour intervals.
/system scheduler add name="upload-traffic-count-local" interval=1h on-event=<script name>

Edit the <script name> to match the actual script.

  1. View in application after script is run.

Sample Screenshot

Screenshot

Author

Mohamed Muhannad (@monde_)

Acknowledgements

mikrotik-traffic-counter's People

Contributors

muhannad0 avatar

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.