Martineau
Part of the Furniture
There was a query recently about how to detect DOWNLOAD throughput activity and BLOCK the device if deemed appropriate so I have revised my suggested solution.
Using the Traffic Analyzer reports, you can review device activity, but real-time monitoring may be useful.
So here is my shoddy QuotaMonitor.sh script to monitor/apply a DOWNLOAD (Rx) or UPLOAD (Tx) rate or Data Cap or apply QoS throttling.
EDIT: 13/12/2018 v1.04 Released see Release notes
EDIT: 30/11/2018 v1.03 Released see Release notes
EDIT: 27/11/2018 v1.02 Released see Release notes Thanks to @FreshJR for the example 'throttle' rules which is less harsh than a complete BLOCK!
It isn't foolproof by any means, and it may seemingly take a few seconds before the BLOCK is apparent - i.e. buffered streaming video will play until the next burst of the data stream is requested.
The default limits used by the script are:
Allow Download (Rx) maximum 50MB and Upload (Tx) maximum 10MB in 60 seconds with a Total Used Data cap applied of 50GB from the time the monitoring was initialised.
However, these arbitrary (unrealistic?) limits may be modified as required.
Prerequisites:
N/A
The example shows that I added 25 devices but for testing a couple of devices should suffice.
e.g. Create the monitoring rules for three devices
Image fullsize
I then started the real-time monitoring, but to speed up testing, I altered the Quota DOWNLOAD limit to max 500KB in (60 seconds), and also requested that devices that didn't receive/transmit any data during the interval would not be displayed on screen in the fixed scrollable window.
So immediately I started a web browser session on my HP-Envy13 laptop and easily exceeded the 500KB/min limit so the device was QoS throttled, and the monitor displayed the reason 'QoS - Rx' and continue to report the QoS throttling.
I then obviously removed the QoS throttling from my laptop
NOTE:The data is is not saved to disk (or SQL) at the moment, v1.03 allows use of the 'report=' option to save a .csv but the real-time data is only valid for as long as the iptables remain intact.
As usual all/any feedback appreciated.
Using the Traffic Analyzer reports, you can review device activity, but real-time monitoring may be useful.
So here is my shoddy QuotaMonitor.sh script to monitor/apply a DOWNLOAD (Rx) or UPLOAD (Tx) rate or Data Cap or apply QoS throttling.
EDIT: 13/12/2018 v1.04 Released see Release notes
EDIT: 30/11/2018 v1.03 Released see Release notes
EDIT: 27/11/2018 v1.02 Released see Release notes Thanks to @FreshJR for the example 'throttle' rules which is less harsh than a complete BLOCK!
It isn't foolproof by any means, and it may seemingly take a few seconds before the BLOCK is apparent - i.e. buffered streaming video will play until the next burst of the data stream is requested.
The default limits used by the script are:
Allow Download (Rx) maximum 50MB and Upload (Tx) maximum 10MB in 60 seconds with a Total Used Data cap applied of 50GB from the time the monitoring was initialised.
However, these arbitrary (unrealistic?) limits may be modified as required.
Prerequisites:
N/A
Code:
./QuotaMonitor.sh -h
#======================================================================================= © 2018 Martineau v1.04
#
# Monitor device traffic quotas and apply block if limit exceeded
#
# QuotaMonitor [help | -h] ['ip='{[ip_address[,...] | hostname[...] | auto | all ]} ['remove']] ['init'[qos]] ['reset' | 'resetdel'] ['unblock'] ['zero']
# ['monitor'] ['interval='{interval_seconds}] ['dlimit={interval_limit}'] ['ulimit={interval_limit}'] ['quota='['rx'|'tx'|'used']]
# ['cap='{cap_limit}] ['ignorezero'] ['actionrx='{script_name}] ['actiontx='{script_name}] ['actionused='{script_name}] ['nolog'] ['qos']
# ['report='{path_for_quota.csv}] ['once'] ['status'[ 'verbose']]
#
# QuotaMonitor init
# Create the two Quota Monitor Chains (MyQUOTAi/MyQUOTA) for DOWNLOAD/UPLOAD
# Individual device Quota limits may be defined in '/jffs/configs/QuotaLimits' but will be ignored if 'dlimit='/'ulimit=' specified
# e.g.
# #Hostname Rx Tx Cap
# HP-Envy13 300MB 20MB 100GB
# NOTE: Quota limits may only be applied to the same 'interval=' value
# QuotaMonitor status
# Show the contents of the two Chains. The USED var is derived from the RECV/XMIT byte count!
# QuotaMonitor ip=192.168.1.123,iphone,laptop
# Add three devices to be monitored
# QuotaMonitor ip=auto
# Attempt to auto discover all LAN devices and add them to the monitor list.
# QuotaMonitor monitor
# Start Rx/Tx and Total Used quota monitoring for the devices defined (default limits 50MB in 60 secs Capped @50GB)
# If the limits are exceeded, then the device is BLOCKED.
# QuotaMonitor monitor interval=10 dlimit=5mb cap=100MB
# Start Start Rx/Tx and Total Used quota monitoring for the devices defined in the Chains (uses 5MB in 10 secs Capped @100MB)
# QuotaMonitor monitor interval=10 dlimit=5mb cap=100MB ignorezero quota=
# Start Start Rx/Tx and Total Used quota monitoring for the devices, but devices which have not received/transmitted data are not displayed.
# This mode is useful for identifying suitable quota limits, as no quota metric (Rx,Tx or Used) is enforced
# Useful for testing, to prove if the Quota limits can be ENFORCED in real-time
# QuotaMonitor monitor actionRx=Quota_Rx.sh
# Start the Rx/Tx and Total Used Quota monitoring, but rather than BLOCK the device if the Rx quota is exceeded run script Quota_Rx.sh
# QuotaMonitor monitor qos
# Start the Rx/Tx and Total Used Quota monitoring, but rather than BLOCK the device if the Rx quota is exceeded apply QoS rules
# NOTE: 'initqos' must have been previously specified.
# QuotaMonitor ip=laptop unblock
# Unblock a specified device.
# QuotaMonitor ip=all unblockqos
# Unblock ALL devices that are currently throttled by QoS.
# QuotaMonitor ip=laptop remove
# Remove the device 'laptop' from the Quota Monitoring.
# NOTE: This will require a second instance of the script to allow uninterrupted monitoring
# QuotaMonitor reset
# Removes all devices from monitoring but retains the Chains.
# QuotaMonitor resetdel
# Deletes both chains and all iptables rules
# QuotaMonitor zero
# Resets the Quota counts to 0. Could be scheduled by a cron job every day @00:00 etc.
# QuotaMonitor monitor nolog
# Start the Rx/Tx and Total Used Quota monitoring, but do not record the output to Syslog
# QuotaMonitor monitor nolog report=/tmp/mnt/xxx/Quota.csv once quota=
# Start the Rx/Tx and Total Used Quota monitoring, but do not record the output to Syslog, instead write the results to '/tmp/mnt/xxx/Quota.csv'
# NOTE: **WARNING" If you schedule it via cron with the 'once' option YOU MUST SPECIFY 'quota=' otherwise it may apply the Quota BLOCK!
e.g. Create the monitoring rules for three devices
Code:
./QuotaMonitor.sh init ip=hp-envy13,hp-envy14,sga5
Image fullsize
I then started the real-time monitoring, but to speed up testing, I altered the Quota DOWNLOAD limit to max 500KB in (60 seconds), and also requested that devices that didn't receive/transmit any data during the interval would not be displayed on screen in the fixed scrollable window.
Code:
./QuotaMonitor.sh monitor dlimit=500k scroll= ignorezero
So immediately I started a web browser session on my HP-Envy13 laptop and easily exceeded the 500KB/min limit so the device was QoS throttled, and the monitor displayed the reason 'QoS - Rx' and continue to report the QoS throttling.
I then obviously removed the QoS throttling from my laptop
Code:
./QuotaMonitor.sh ip=hp-envy13 unblockqos
v1.04 Quota Monitoring.....
Quota Monitoring clients: hp-envy13 (10.88.8.111) UnBLOCKED
NOTE:
As usual all/any feedback appreciated.
Last edited: