MikroTik-Router-Traffic-Monitoring
所属分类:Julia编程
开发工具:HTML
文件大小:0KB
下载次数:0
上传日期:2017-03-15 13:19:08
上 传 者:
sh-1993
说明: 使用具有sqlite、php_and_...的web服务器,监视和存储MikroTik路由器接口上的总流量...
(Monitors and stores the total amount of traffic on a MikroTik router interface using a web-server with sqlite, php and d3.js)
文件列表:
LICENSE (35141, 2017-03-15)
mikrotik-traffic-send-script.txt (360, 2017-03-15)
traffic-monitor.png (29698, 2017-03-15)
var/ (0, 2017-03-15)
var/www/ (0, 2017-03-15)
var/www/mikrotik-traffic-status/ (0, 2017-03-15)
var/www/mikrotik-traffic-status/d3.v4.min.js (212384, 2017-03-15)
var/www/mikrotik-traffic-status/traffic-aggregator.php (1018, 2017-03-15)
var/www/mikrotik-traffic-status/traffic-monitor.html (3007, 2017-03-15)
var/www/mikrotik-traffic-status/traffic-receiver.php (1102, 2017-03-15)
# Traffic Monitoring for MikroTik Routers
Monitors and stores the total amount of traffic on a MikroTik router interface using a web-server with sqlite, php and d3.js
## MikroTik Script
A MikroTik router can be configured to send traffic values with a script.
In System -> Scripts a script needs to be placed to read traffic values from an interface (port) like ether1.
- create a new script with name "send-traffic" with "read" and "test" policy enabled
- insert the contents of mikrotik-traffic-send-script.txt
- change ether1 to the interface where traffic is to be measured and the url to the location of your php script
In System -> Scheduler a schedule needs to be created to execute the script
- Interval (e.g. every 10 minutes): 00:10:00
- On Event: send-traffic
- Policies "read" and "test"
Note that traffic count is restarted on reboot, so that a maximum of 10 minutes (as set in "Interval") of traffic can get lost.
Tested with MikroTik hAP ac running RouterOS 6.37.
## Server-Setup
HTTP(S) server setup to receive and store traffic values
Required: HTTP(S) server (e.g. nginx with php7.0-fpm) and sqlite3
### Database
A sqlite database needs to be created to store traffic values, e.g. in file /var/mikrotik-traffic.sqlite.
- A schema needs to be created to store timestamp, transceived (tx) and received (rx) bytes as well as dtx and drx (differences to the previous values):
- ```sqlite3 /var/mikrotik-traffic.sqlite "create table traffic(timestamp int, tx int, rx int, dtx int, drx int)"```
- This file will be written by the http(s) server and belongs to its user or group, e.g. www-data:
- ```chown www-data.www-data /var/mikrotik-traffic.sqlite```
### HTML and PHP
HTML an PHP files need to be available from the web. The directory var/www/mikrotik-traffic-status contains:
traffic-receiver.php
- to handle http(s) requests from the MikroTik router and to write traffic values to file /var/mikrotik-traffic.sqlite
- This script will also store the IP of the MikroTik router in /var/mikrotik-ip.txt (for applications like dynamic DNS)
traffic-aggregator.php
- to read mikrotik-traffic.sqlite and
- aggregate (in the given example) monthly traffic figures for transceived (tx) and received (rx) bytes
traffic-monitor.html
- calls traffic-aggregator.php
- shows a graph rendered in JavaScript using d3.js (file d3.v4.min.js - see https://d3js.org/)
Note that it does make sense to obfuscate the names of the php scripts when using HTTPS.
![alt tag](https://github.com/fhaer/MikroTik-Router-Traffic-Monitoring/blob/master/traffic-monitor.png)
近期下载者:
相关文件:
收藏者: