This script retrieves Downstream and Upstream attainable rates from a DSL modem via SNMP, calculates proposed Queue Tree Max Limits for Mikrotik RouterOS, and sets these limits. Configuration is loaded from a JSON file or environment variables.
The max limit is calculated as a percentage of the current rate - in this case, 10% of headroom is allowed for to suit a CAKE/FQ-CODEL queue.
- Dependencies
- Installation
- Configuration
- Usage
- Example crontab entry
- Example Log Output
- Author
- License
- pysnmp: SNMP library for Python (pysnmp)
- routeros_api: MikroTik RouterOS API for Python (routeros_api)
-
Clone the repository:
git clone https://github.com/naturalnetworks/mtqosadj.git
-
Create a Python Virtual Environment
cd mtqosadj python3 -m venv .venv source .venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
Edit config.json
to set SNMP and RouterOS parameters. Alternatively, use environment
variables for sensitive information.
Run the script with the necessary permissions to read SNMP information from the DSL modem and set Queue Tree Max Limits on the MikroTik RouterOS.
/path/to/mtqosadj/.venv/bin/python3 /path/to/mtqosadj/main.py
*/30 * * * * user cd /path/to/mtqosadj && /path/to/mtqosadj/.venv/bin/python3 /path/to/mtqosadj/main.py
INFO: Download/Upload Queue CURRENT Max Limit: 45609063/9738548
INFO: Setting Queue "download" Max Limit to 45609063
INFO: Setting Queue "upload" Max Limit to 9738548
INFO: Download/Uploads Queue APPLIED Max Limits: 45609063/9738548 (45609.06/9738.55 kbps)