Skip to content

Commit

Permalink
[feature] Added charts and metric (TCP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Jun 14, 2022
1 parent d61b21e commit bad881d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 21 deletions.
60 changes: 39 additions & 21 deletions openwisp_monitoring/check/classes/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ def check(self, store=True):
self.store_result(
{
'iperf_result': 0,
'sum_sent_bps': 0.0,
'sum_rec_bps': 0.0,
'sum_sent_bytes': 0.0,
'sum_rec_bytes': 0.0,
'sum_sent_retransmits': 0,
'sent_bps': 0.0,
'received_bps': 0.0,
'sent_bytes': 0.0,
'received_bytes': 0.0,
'retransmits': 0,
}
)
device_connection.disconnect()
return
else:
result_dict = self._get_iperf_result(res)
print('---- Command Output ----')
print(result_dict)
if store:
self.store_result(result_dict)
device_connection.disconnect()
return result_dict
else:
print(
Expand Down Expand Up @@ -88,21 +90,27 @@ def _get_iperf_result(self, res, mode=None):
"""
res_dict = json.loads(res)
if mode is None:
# Gbps = Gigabits per second
# GB = GigaBytes
sent_json = res_dict['end']['sum_sent']
recv_json = res_dict['end']['sum_received']
sent_bytes = sent_json['bytes']
sent_bytes_GB = sent_bytes / 1000000000
sent_bps = sent_json['bits_per_second']
sent_Gbps = sent_bps / 1000000000
received_bytes = recv_json['bytes']
received_bytes_GB = received_bytes / 1000000000
received_bps = recv_json['bits_per_second']
received_Gbps = received_bps / 1000000000
retransmits = sent_json['retransmits']

result = {
'iperf_result': 1,
'sum_sent_bps': round(
res_dict['end']['sum_sent']['bits_per_second'] / 1000000000, 2
),
'sum_rec_bps': round(
res_dict['end']['sum_received']['bits_per_second'] / 1000000000, 2
),
'sum_sent_bytes': round(
res_dict['end']['sum_sent']['bytes'] / 1000000000, 2
),
'sum_rec_bytes': round(
res_dict['end']['sum_received']['bytes'] / 1000000000, 2
),
'sum_sent_retransmits': res_dict['end']['sum_sent']['retransmits'],
'sent_bps': round(sent_Gbps, 2),
'received_bps': round(received_Gbps, 2),
'sent_bytes': round(sent_bytes_GB, 2),
'received_bytes': round(received_bytes_GB, 2),
'retransmits': retransmits,
}
return result
# For UDP
Expand All @@ -113,19 +121,29 @@ def store_result(self, result):
"""
store result in the DB
"""
pass
metric = self._get_metric()
copied = result.copy()
iperf_result = copied.pop('iperf_result')
metric.write(iperf_result, extra_values=copied)

def _get_metric(self):
"""
Gets or creates metric
"""
pass
metric, created = self._get_or_create_metric()
if created:
self._create_charts(metric)
return metric

def _create_charts(self, metric):
"""
Creates iperf related charts (Bandwith/Jitter)
"""
pass
charts = ['bitrate', 'transfer', 'retransmits']
for chart in charts:
chart = Chart(metric=metric, configuration=chart)
chart.full_clean()
chart.save()

def _create_alert_settings(self, metric):
pass
2 changes: 2 additions & 0 deletions openwisp_monitoring/check/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
'IPERF_SERVERS',
{
# Running on my local
# Some Public Iperf Servers : https://iperf.fr/iperf-servers.php#public-servers
# 'be63c4e5-a68a-4650-bfe8-733837edb8be': ['iperf.biznetnetworks.com'],
'be63c4e5-a68a-4650-bfe8-733837edb8be': ['192.168.5.109'],
# '<org-pk>': ['<ORG_IPERF_SERVER>']
},
Expand Down
23 changes: 23 additions & 0 deletions openwisp_monitoring/db/backends/influxdb/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@
"object_id = '{object_id}' GROUP BY time(1d)"
)
},
'bitrate': {
'influxdb': (
"SELECT MEAN(sent_bps) AS sent, "
"MEAN(received_bps) AS received FROM {key} WHERE "
"time >= '{time}' AND content_type = '{content_type}' AND "
"object_id = '{object_id}' GROUP BY time(1d)"
)
},
'transfer': {
'influxdb': (
"SELECT MEAN(sent_bytes) AS sent, "
"MEAN(received_bytes) AS received FROM {key} WHERE "
"time >= '{time}' AND content_type = '{content_type}' AND "
"object_id = '{object_id}' GROUP BY time(1d)"
)
},
'retransmits': {
'influxdb': (
"SELECT MEAN(retransmits) AS retransmits FROM {key} "
"WHERE time >= '{time}' AND content_type = '{content_type}' "
"AND object_id = '{object_id}' GROUP BY time(1d)"
)
},
}

default_chart_query = [
Expand Down
50 changes: 50 additions & 0 deletions openwisp_monitoring/monitoring/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,56 @@ def _get_access_tech():
}
},
},
'iperf': {
'label': _('Iperf'),
'name': 'Iperf',
'key': 'iperf',
'field_name': 'iperf_result',
'related_fields': [
'sent_bps',
'received_bps',
'sent_bytes',
'received_bytes',
'retransmits',
],
'charts': {
'bitrate': {
'type': 'stackedbar',
'title': _('Bandwidth'),
'description': _('Iperf3 bitrate in TCP mode.'),
'summary_labels': [
_('Sent bitrate'),
_('Received bitrate'),
],
'unit': _(' Gbps'),
'order': 280,
'query': chart_query['bitrate'],
'colors': (DEFAULT_COLORS[5], DEFAULT_COLORS[9]),
},
'transfer': {
'type': 'stackedbar',
'title': _('Transfer'),
'description': _('Iperf3 transfer in TCP mode.'),
'summary_labels': [
_('Sent bytes'),
_('Received bytes'),
],
'unit': _(' GB'),
'order': 290,
'query': chart_query['transfer'],
'colors': (DEFAULT_COLORS[2], DEFAULT_COLORS[4]),
},
'retransmits': {
'type': 'bar',
'title': _('Retransmits'),
'colors': (DEFAULT_COLORS[4]),
'description': _('No. of retransmits during Iperf3 test in TCP mode.'),
'unit': '',
'order': 300,
'query': chart_query['retransmits'],
},
},
},
}

DEFAULT_CHARTS = {}
Expand Down

0 comments on commit bad881d

Please sign in to comment.