From 2ebf894c3c705955e5478e88248c8b3dc8705c8d Mon Sep 17 00:00:00 2001 From: Ivan Pavlina Date: Mon, 11 May 2020 15:06:54 +0200 Subject: [PATCH 1/5] Adding logging for near or exceeded accounting entries compared to set threshold. Should help with debugging broken accounting calculations --- .../mikrotik_router/mikrotik_controller.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index c01438d..6da4fa6 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1179,6 +1179,19 @@ class MikrotikControllerData: ], ) + threshold = self.api.path("/ip/accounting")[0].get('threshold') + entry_count = len(accounting_data) + + if entry_count is threshold: + _LOGGER.warning(f'Accounting entries count reached the threshold of {threshold}!' + ' Some entries were not saved by Mikrotik so accounting calculation won\'t be correct.' + ' Consider shortening update interval or' + ' increasing the accounting threshold value in Mikrotik.') + elif entry_count > threshold * 0.9: + _LOGGER.info(f'Accounting entries count ({entry_count} reached 90% of the threshold,' + f' currently set to {threshold}! Consider shortening update interval or' + ' increasing the accounting threshold value in Mikrotik.') + for item in accounting_data.values(): source_ip = str(item.get("src-address")).strip() destination_ip = str(item.get("dst-address")).strip() From bade52165ca0a4d636585c59fa11b34a86e55bdf Mon Sep 17 00:00:00 2001 From: Ivan Pavlina Date: Mon, 11 May 2020 15:15:28 +0200 Subject: [PATCH 2/5] Fix strings definitions to pass Black Code Format Check --- .../mikrotik_router/mikrotik_controller.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 6da4fa6..0eb4c21 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1179,18 +1179,18 @@ class MikrotikControllerData: ], ) - threshold = self.api.path("/ip/accounting")[0].get('threshold') + threshold = self.api.path("/ip/accounting")[0].get("threshold") entry_count = len(accounting_data) if entry_count is threshold: - _LOGGER.warning(f'Accounting entries count reached the threshold of {threshold}!' - ' Some entries were not saved by Mikrotik so accounting calculation won\'t be correct.' - ' Consider shortening update interval or' - ' increasing the accounting threshold value in Mikrotik.') + _LOGGER.warning(f"Accounting entries count reached the threshold of {threshold}!" + " Some entries were not saved by Mikrotik so accounting calculation won't be correct." + " Consider shortening update interval or" + " increasing the accounting threshold value in Mikrotik.") elif entry_count > threshold * 0.9: - _LOGGER.info(f'Accounting entries count ({entry_count} reached 90% of the threshold,' - f' currently set to {threshold}! Consider shortening update interval or' - ' increasing the accounting threshold value in Mikrotik.') + _LOGGER.info(f"Accounting entries count ({entry_count} reached 90% of the threshold," + f" currently set to {threshold}! Consider shortening update interval or" + " increasing the accounting threshold value in Mikrotik.") for item in accounting_data.values(): source_ip = str(item.get("src-address")).strip() From bbc312452778619cb14fce7b207e51463151c9a4 Mon Sep 17 00:00:00 2001 From: Ivan Pavlina Date: Mon, 11 May 2020 15:18:17 +0200 Subject: [PATCH 3/5] Another try to pass Black :D --- .../mikrotik_router/mikrotik_controller.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 0eb4c21..a089d4f 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1183,14 +1183,18 @@ class MikrotikControllerData: entry_count = len(accounting_data) if entry_count is threshold: - _LOGGER.warning(f"Accounting entries count reached the threshold of {threshold}!" - " Some entries were not saved by Mikrotik so accounting calculation won't be correct." - " Consider shortening update interval or" - " increasing the accounting threshold value in Mikrotik.") + _LOGGER.warning( + f"Accounting entries count reached the threshold of {threshold}!" + " Some entries were not saved by Mikrotik so accounting calculation won't be correct." + " Consider shortening update interval or" + " increasing the accounting threshold value in Mikrotik." + ) elif entry_count > threshold * 0.9: - _LOGGER.info(f"Accounting entries count ({entry_count} reached 90% of the threshold," - f" currently set to {threshold}! Consider shortening update interval or" - " increasing the accounting threshold value in Mikrotik.") + _LOGGER.info( + f"Accounting entries count ({entry_count} reached 90% of the threshold," + f" currently set to {threshold}! Consider shortening update interval or" + " increasing the accounting threshold value in Mikrotik." + ) for item in accounting_data.values(): source_ip = str(item.get("src-address")).strip() From 72c04c8144cd88107e6a9e53dc2e4738eb22bfec Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Tue, 12 May 2020 01:08:46 +0200 Subject: [PATCH 4/5] updated accounting docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2b7edc9..f8f14d7 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Feature is present in Winbox IP-Accounting. Make sure that threshold is set to r More information about Accounting can be found on [Mikrotik support page](https://wiki.mikrotik.com/wiki/Manual:IP/Accounting). +NOTE: Accounting does not count in FastTracked packets. + ![Accounting sensor](https://raw.githubusercontent.com/tomaae/homeassistant-mikrotik_router/master/docs/assets/images/ui/accounting_sensor.png) # Install integration From 451f63740c949ddbf51074d8943db10be5d1df80 Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Tue, 12 May 2020 01:10:32 +0200 Subject: [PATCH 5/5] updated simple queue docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f8f14d7..b94752e 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Control simple queues. More information about simple queues can be found on [Mikrotik support page](https://wiki.mikrotik.com/wiki/Manual:Queue#Simple_Queues). +NOTE: FastTracked packets are not processed by Simple Queues. + ![Queue switch](https://raw.githubusercontent.com/tomaae/homeassistant-mikrotik_router/master/docs/assets/images/ui/queue_switch.png) ## Host Tracking