From e488e90d3143ba9b40937a102d9826bdcf817d97 Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Mon, 25 May 2020 20:15:59 +0200 Subject: [PATCH 2/3] Write used percentage in the memory metric and fix tests --- openwisp_monitoring/device/api/views.py | 6 ++++-- openwisp_monitoring/device/tests/__init__.py | 1 + openwisp_monitoring/device/tests/test_api.py | 18 +++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/openwisp_monitoring/device/api/views.py b/openwisp_monitoring/device/api/views.py index 4d64bf5..ebcd8aa 100644 --- a/openwisp_monitoring/device/api/views.py +++ b/openwisp_monitoring/device/api/views.py @@ -245,6 +245,7 @@ class DeviceMetricView(GenericAPIView): if 'memory' in data['resources']: memory = data['resources']['memory'] extra_values = { + 'free_memory': memory['free'], 'total_memory': memory['total'], 'buffered_memory': memory['buffered'], 'shared_memory': memory['shared'], @@ -255,10 +256,11 @@ class DeviceMetricView(GenericAPIView): object_id=pk, content_type=ct, key='memory', - field_name='free_memory', + field_name='used_percent', name='Resources: Memory', ) - metric.write(memory['free'], extra_values=extra_values) + used_percent = memory['free'] / memory['total'] + metric.write(used_percent, extra_values=extra_values) if created: self._create_resources_graph(metric, resource='memory') self._create_resources_threshold(metric, resource='memory') diff --git a/openwisp_monitoring/device/tests/__init__.py b/openwisp_monitoring/device/tests/__init__.py index 58ba4ed..ef5beac 100644 --- a/openwisp_monitoring/device/tests/__init__.py +++ b/openwisp_monitoring/device/tests/__init__.py @@ -43,6 +43,7 @@ class DeviceMonitoringTestCase(TestDeviceMonitoringMixin, TestCase): 'shared': 86016, 'free': 224497664, 'cached': 6774784, + 'available': 223397664, 'buffered': 974848, }, 'load': [0, 0, 0], diff --git a/openwisp_monitoring/device/tests/test_api.py b/openwisp_monitoring/device/tests/test_api.py index d5da660..0e1bec2 100644 --- a/openwisp_monitoring/device/tests/test_api.py +++ b/openwisp_monitoring/device/tests/test_api.py @@ -338,10 +338,12 @@ class TestDeviceApi(DeviceMonitoringTestCase): 'upload - Traffic: wlan0', 'download - Traffic: wlan1', 'upload - Traffic: wlan1', - 'Buffered_Memory - Memory', - 'Shared_Memory - Memory', - 'Used_Memory - Memory', - 'CPU_Load - CPU Load', + 'Available_Memory - Memory', + 'Free_Memory - Memory', + 'Total_Memory - Memory', + 'Average_15m - CPU Load', + 'Average_1m - CPU Load', + 'Average_5m - CPU Load', 'Disk_Usage - Disk Usage', ], ) @@ -356,9 +358,11 @@ class TestDeviceApi(DeviceMonitoringTestCase): '0.6', '3', '1.5', - '0.39', - '0.03', - '9.73', + '213.05', + '214.1', + '238.2', + '0', + '0', '0', '8.27', ], -- 2.17.1