From 070ba3a7bb24881ce4ea663bd79c026d81f878b6 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Mon, 29 Jul 2024 17:35:01 +0530 Subject: [PATCH] [fix] Fixed timseries structure for storing signal metric #586 Updated timeseries migration script to also handle signal metrics. Fixes #586 Signed-off-by: Gagan Deep --- .github/workflows/ci.yml | 2 +- openwisp_monitoring/device/writer.py | 16 +++++++++------- openwisp_monitoring/monitoring/configuration.py | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6bb4f80..e4d9ca7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,7 @@ jobs: - name: Install python system packages run: | - pip install -U pip wheel setuptools + pip install -U pip wheel "setuptools~=71.0.0" - name: Install npm dependencies run: sudo npm install -g jshint stylelint diff --git a/openwisp_monitoring/device/writer.py b/openwisp_monitoring/device/writer.py index 8b0fdd7a..aeb12461 100644 --- a/openwisp_monitoring/device/writer.py +++ b/openwisp_monitoring/device/writer.py @@ -73,7 +73,6 @@ def write(self, data, time=None, current=False): self.write_device_metrics = [] for interface in data.get('interfaces', []): ifname = interface['name'] - extra_tags = Metric._sort_dict(device_extra_tags) if 'mobile' in interface: self._write_mobile_signal( interface, ifname, ct, self.device_data.pk, current, time=time @@ -100,7 +99,7 @@ def write(self, data, time=None, current=False): name=name, key='traffic', main_tags={'ifname': Metric._makekey(ifname)}, - extra_tags=extra_tags, + extra_tags=device_extra_tags, ) self._append_metric_data( metric, field_value, current, time=time, extra_values=extra_values @@ -121,7 +120,7 @@ def write(self, data, time=None, current=False): name=name, key='wifi_clients', main_tags={'ifname': Metric._makekey(ifname)}, - extra_tags=extra_tags, + extra_tags=device_extra_tags, ) # avoid tsdb overwrite clients client_time = time @@ -174,7 +173,7 @@ def _get_extra_tags(self, device): tags['location_id'] = str(device_location.location_id) if device_location.floorplan_id: tags['floorplan_id'] = str(device_location.floorplan_id) - return tags + return Metric._sort_dict(tags) def _get_mobile_signal_type(self, signal): if not signal: @@ -214,7 +213,8 @@ def _write_mobile_signal(self, interface, ifname, ct, pk, current=False, time=No content_type_id=ct.id, configuration='signal_strength', name='signal strength', - key=ifname, + key='signal', + main_tags={'ifname': Metric._makekey(ifname)}, ) self._append_metric_data( metric, signal_strength, current, time=time, extra_values=extra_values @@ -242,7 +242,8 @@ def _write_mobile_signal(self, interface, ifname, ct, pk, current=False, time=No content_type_id=ct.id, configuration='signal_quality', name='signal quality', - key=ifname, + key='signal', + main_tags={'ifname': Metric._makekey(ifname)}, ) self._append_metric_data( metric, signal_quality, current, time=time, extra_values=extra_values @@ -255,7 +256,8 @@ def _write_mobile_signal(self, interface, ifname, ct, pk, current=False, time=No content_type_id=ct.id, configuration='access_tech', name='access technology', - key=ifname, + key='signal', + main_tags={'ifname': Metric._makekey(ifname)}, ) self._append_metric_data( metric, diff --git a/openwisp_monitoring/monitoring/configuration.py b/openwisp_monitoring/monitoring/configuration.py index 15dbd4bd..f53d7128 100644 --- a/openwisp_monitoring/monitoring/configuration.py +++ b/openwisp_monitoring/monitoring/configuration.py @@ -471,7 +471,7 @@ def _get_access_tech(): 'type': 'scatter', 'fill': 'none', 'yaxis': {'zeroline': False}, - 'title': _('Signal Strength'), + 'title': _('Signal Strength: {ifname}'), 'colors': (DEFAULT_COLORS[3], DEFAULT_COLORS[0]), 'description': _('Signal Strength and Signal Power, measured in dBm.'), 'summary_labels': [ @@ -495,7 +495,7 @@ def _get_access_tech(): 'type': 'scatter', 'fill': 'none', 'yaxis': {'zeroline': False}, - 'title': _('Signal Quality'), + 'title': _('Signal Quality: {ifname}'), 'colors': (DEFAULT_COLORS[3], DEFAULT_COLORS[0]), 'description': _( _('Signal Quality and Signal to Noise Ratio (SNR), measured in dB.') @@ -518,7 +518,7 @@ def _get_access_tech(): 'charts': { 'access_tech': { 'type': 'bar', - 'title': _('Access Technology'), + 'title': _('Access Technology: {ifname}'), 'description': _( _( 'Shows the access technology (LTE, UTMS, CDMA1x, etc.) '