mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 11:18:03 +00:00
Option to paste data from test_ipv4_variable_time to influx database
Signed-off-by: lanforge <stidmatt@gmail.com>
This commit is contained in:
@@ -21,13 +21,8 @@ class RecordInflux(LFCliBase):
|
|||||||
_influx_user=None,
|
_influx_user=None,
|
||||||
_influx_passwd=None,
|
_influx_passwd=None,
|
||||||
_influx_db=None,
|
_influx_db=None,
|
||||||
_longevity=None,
|
|
||||||
_monitor_interval=None,
|
|
||||||
_target_kpi=None,
|
|
||||||
_devices=None,
|
|
||||||
_debug_on=False,
|
_debug_on=False,
|
||||||
_exit_on_fail=False
|
_exit_on_fail=False):
|
||||||
):
|
|
||||||
super().__init__(_influx_host,
|
super().__init__(_influx_host,
|
||||||
_port,
|
_port,
|
||||||
_debug=_debug_on,
|
_debug=_debug_on,
|
||||||
@@ -37,10 +32,6 @@ class RecordInflux(LFCliBase):
|
|||||||
self.influx_user = _influx_user
|
self.influx_user = _influx_user
|
||||||
self.influx_passwd = _influx_passwd
|
self.influx_passwd = _influx_passwd
|
||||||
self.influx_db = _influx_db
|
self.influx_db = _influx_db
|
||||||
self.longevity = _longevity
|
|
||||||
self.stations = _devices
|
|
||||||
self.monitor_interval = _monitor_interval
|
|
||||||
self.target_kpi = _target_kpi
|
|
||||||
|
|
||||||
def posttoinflux(self,station,key,response,client):
|
def posttoinflux(self,station,key,response,client):
|
||||||
json_body = [
|
json_body = [
|
||||||
@@ -58,26 +49,29 @@ class RecordInflux(LFCliBase):
|
|||||||
]
|
]
|
||||||
client.write_points(json_body)
|
client.write_points(json_body)
|
||||||
|
|
||||||
def getdata(self):
|
def getdata(self,
|
||||||
|
devices=None,
|
||||||
|
target_kpi=None,
|
||||||
|
longevity=None,
|
||||||
|
monitor_interval=None):
|
||||||
url = 'http://'+self.host+':8080/port/1/1/'
|
url = 'http://'+self.host+':8080/port/1/1/'
|
||||||
client = InfluxDBClient(self.host,
|
client = InfluxDBClient(self.host,
|
||||||
8086,
|
8086,
|
||||||
self.influx_user,
|
self.influx_user,
|
||||||
self.influx_passwd,
|
self.influx_passwd,
|
||||||
self.influx_db)
|
self.influx_db)
|
||||||
end = datetime.datetime.now() + datetime.timedelta(0, self.longevity)
|
end = datetime.datetime.now() + datetime.timedelta(0, longevity)
|
||||||
while datetime.datetime.now() < end:
|
while datetime.datetime.now() < end:
|
||||||
stations = self.stations
|
for station in devices:
|
||||||
for station in stations:
|
|
||||||
url1 = url + station
|
url1 = url + station
|
||||||
response = json.loads(requests.get(url1).text)
|
response = json.loads(requests.get(url1).text)
|
||||||
if self.target_kpi is None:
|
if target_kpi is None:
|
||||||
for key in response['interface'].keys():
|
for key in response['interface'].keys():
|
||||||
self.posttoinflux(station, key, response, client)
|
self.posttoinflux(station, key, response, client)
|
||||||
else:
|
else:
|
||||||
targets=self.target_kpi+['ip','ipv6 address','alias','mac']
|
targets = target_kpi+['ip','ipv6 address','alias','mac']
|
||||||
response['interface']={your_key: response['interface'][your_key] for your_key in targets}
|
response['interface']={your_key: response['interface'][your_key] for your_key in targets}
|
||||||
for key in response['interface'].keys():
|
for key in response['interface'].keys():
|
||||||
self.posttoinflux(station, key, response, client)
|
self.posttoinflux(station, key, response, client)
|
||||||
|
|
||||||
time.sleep(self.monitor_interval)
|
time.sleep(monitor_interval)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import pprint
|
import pprint
|
||||||
from pprint import pprint
|
|
||||||
from lfdata import LFDataCollection
|
from lfdata import LFDataCollection
|
||||||
from base_profile import BaseProfile
|
from base_profile import BaseProfile
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -56,12 +56,11 @@ def main():
|
|||||||
_port=args.mgr_port,
|
_port=args.mgr_port,
|
||||||
_influx_db=args.influx_db,
|
_influx_db=args.influx_db,
|
||||||
_influx_user=args.influx_user,
|
_influx_user=args.influx_user,
|
||||||
_influx_passwd=args.influx_passwd,
|
_influx_passwd=args.influx_passwd)
|
||||||
_longevity=longevity,
|
grapher.getdata(longevity=longevity,
|
||||||
_devices=args.device,
|
devices=args.device,
|
||||||
_monitor_interval=monitor_interval,
|
monitor_interval=monitor_interval,
|
||||||
_target_kpi=args.target_kpi)
|
target_kpi=args.target_kpi)
|
||||||
grapher.getdata()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if sys.version_info[0] != 3:
|
|||||||
|
|
||||||
if 'py-json' not in sys.path:
|
if 'py-json' not in sys.path:
|
||||||
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
|
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from LANforge import LFUtils
|
from LANforge import LFUtils
|
||||||
from realm import Realm
|
from realm import Realm
|
||||||
@@ -139,25 +139,6 @@ class IPV4VariableTime(Realm):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
optional = []
|
|
||||||
optional.append({'name': '--mode', 'help': 'Used to force mode of stations'})
|
|
||||||
optional.append({'name': '--ap', 'help': 'Used to force a connection to a particular AP'})
|
|
||||||
optional.append({'name': '--output_format', 'help': 'choose either csv or xlsx'})
|
|
||||||
optional.append({'name': '--report_file', 'help': 'where you want to store results', 'default': None})
|
|
||||||
optional.append({'name': '--a_min', 'help': '--a_min bps rate minimum for side_a', 'default': 256000})
|
|
||||||
optional.append({'name': '--b_min', 'help': '--b_min bps rate minimum for side_b', 'default': 256000})
|
|
||||||
optional.append(
|
|
||||||
{'name': '--test_duration', 'help': '--test_duration sets the duration of the test', 'default': "2m"})
|
|
||||||
optional.append({'name': '--layer3_cols', 'help': 'Columns wished to be monitored from layer 3 endpoint tab',
|
|
||||||
'default': ['name', 'tx bytes', 'rx bytes','tx rate','rx rate']})
|
|
||||||
optional.append({'name': '--port_mgr_cols', 'help': 'Columns wished to be monitored from port manager tab',
|
|
||||||
'default': ['ap', 'ip', 'parent dev']})
|
|
||||||
optional.append(
|
|
||||||
{'name': '--compared_report', 'help': 'report path and file which is wished to be compared with new report',
|
|
||||||
'default': None})
|
|
||||||
optional.append({'name': '--monitor_interval',
|
|
||||||
'help': 'how frequently do you want your monitor function to take measurements; 250ms, 35s, 2h',
|
|
||||||
'default': '10s'})
|
|
||||||
parser = Realm.create_basic_argparse(
|
parser = Realm.create_basic_argparse(
|
||||||
prog='test_ipv4_variable_time.py',
|
prog='test_ipv4_variable_time.py',
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
@@ -266,8 +247,27 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
Elapsed | 'elapsed'
|
Elapsed | 'elapsed'
|
||||||
Destination Addr | 'destination addr'
|
Destination Addr | 'destination addr'
|
||||||
Source Addr | 'source addr'
|
Source Addr | 'source addr'
|
||||||
''',
|
''')
|
||||||
more_optional=optional)
|
|
||||||
|
parser.add_argument('--mode', help='Used to force mode of stations')
|
||||||
|
parser.add_argument('--ap', help='Used to force a connection to a particular AP')
|
||||||
|
parser.add_argument('--output_format', help='choose either csv or xlsx')
|
||||||
|
parser.add_argument('--report_file', help='where you want to store results', default=None)
|
||||||
|
parser.add_argument('--a_min', help='--a_min bps rate minimum for side_a', default=256000)
|
||||||
|
parser.add_argument('--b_min', help='--b_min bps rate minimum for side_b', default=256000)
|
||||||
|
parser.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="2m")
|
||||||
|
parser.add_argument('--layer3_cols', help='Columns wished to be monitored from layer 3 endpoint tab',
|
||||||
|
default=['name', 'tx bytes', 'rx bytes', 'tx rate', 'rx rate'])
|
||||||
|
parser.add_argument('--port_mgr_cols', help='Columns wished to be monitored from port manager tab',
|
||||||
|
default=['ap', 'ip', 'parent dev'])
|
||||||
|
parser.add_argument('--compared_report', help='report path and file which is wished to be compared with new report',
|
||||||
|
default=None)
|
||||||
|
parser.add_argument('--monitor_interval',
|
||||||
|
help='how frequently do you want your monitor function to take measurements; 250ms, 35s, 2h',
|
||||||
|
default='10s')
|
||||||
|
parser.add_argument('--influx_user', help='Username for your Influx database', required=True)
|
||||||
|
parser.add_argument('--influx_passwd', help='Password for your Influx database', required=True)
|
||||||
|
parser.add_argument('--influx_db', help='Name of your Influx database', required=True)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
|
|
||||||
if args.report_file is None:
|
if args.report_file is None:
|
||||||
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':',
|
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':',
|
||||||
'-') + '_test_ipv4_variable_time' # create path name
|
'-') + '_test_ipv4_variable_time' # create path name
|
||||||
try:
|
try:
|
||||||
path = os.path.join('/home/lanforge/report-data/', new_file_path)
|
path = os.path.join('/home/lanforge/report-data/', new_file_path)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
@@ -291,14 +291,15 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
path = os.path.join(curr_dir_path, new_file_path)
|
path = os.path.join(curr_dir_path, new_file_path)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
systeminfopath=str(path)+'/systeminfo.txt'
|
systeminfopath = str(path) + '/systeminfo.txt'
|
||||||
|
|
||||||
if args.output_format in ['csv', 'json', 'html', 'hdf','stata', 'pickle', 'pdf', 'png', 'parquet',
|
if args.output_format in ['csv', 'json', 'html', 'hdf', 'stata', 'pickle', 'pdf', 'png', 'parquet',
|
||||||
'xlsx']:
|
'xlsx']:
|
||||||
report_f = str(path) + '/data.' + args.output_format
|
report_f = str(path) + '/data.' + args.output_format
|
||||||
output = args.output_format
|
output = args.output_format
|
||||||
else:
|
else:
|
||||||
print('Not supporting this report format or cannot find report format provided. Defaulting to csv data file output type, naming it data.csv.')
|
print(
|
||||||
|
'Not supporting this report format or cannot find report format provided. Defaulting to csv data file output type, naming it data.csv.')
|
||||||
report_f = str(path) + '/data.csv'
|
report_f = str(path) + '/data.csv'
|
||||||
output = 'csv'
|
output = 'csv'
|
||||||
|
|
||||||
@@ -314,14 +315,14 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
# Retrieve last data file
|
# Retrieve last data file
|
||||||
compared_rept = None
|
compared_rept = None
|
||||||
if args.compared_report:
|
if args.compared_report:
|
||||||
compared_report_format=args.compared_report.split('.')[-1]
|
compared_report_format = args.compared_report.split('.')[-1]
|
||||||
#if compared_report_format not in ['csv', 'json', 'dta', 'pkl','html','xlsx','parquet','h5']:
|
# if compared_report_format not in ['csv', 'json', 'dta', 'pkl','html','xlsx','parquet','h5']:
|
||||||
if compared_report_format != 'csv':
|
if compared_report_format != 'csv':
|
||||||
print(ValueError("Cannot process this file type. Please select a different file and re-run script."))
|
print(ValueError("Cannot process this file type. Please select a different file and re-run script."))
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
compared_rept=args.compared_report
|
compared_rept = args.compared_report
|
||||||
|
|
||||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
|
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
|
||||||
radio=args.radio)
|
radio=args.radio)
|
||||||
ip_var_test = IPV4VariableTime(host=args.mgr,
|
ip_var_test = IPV4VariableTime(host=args.mgr,
|
||||||
@@ -347,7 +348,6 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
if not ip_var_test.passes():
|
if not ip_var_test.passes():
|
||||||
print(ip_var_test.get_fail_message())
|
print(ip_var_test.get_fail_message())
|
||||||
ip_var_test.exit_fail()
|
ip_var_test.exit_fail()
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
layer3connections = ','.join([[*x.keys()][0] for x in ip_var_test.json_get('endp')['endpoint']])
|
layer3connections = ','.join([[*x.keys()][0] for x in ip_var_test.json_get('endp')['endpoint']])
|
||||||
@@ -381,12 +381,13 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
monitor_interval = Realm.parse_time(args.monitor_interval).total_seconds()
|
monitor_interval = Realm.parse_time(args.monitor_interval).total_seconds()
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
print(str(error))
|
print(str(error))
|
||||||
print(ValueError("The time string provided for monitor_interval argument is invalid. Please see supported time stamp increments and inputs for monitor_interval in --help. "))
|
print(ValueError(
|
||||||
|
"The time string provided for monitor_interval argument is invalid. Please see supported time stamp increments and inputs for monitor_interval in --help. "))
|
||||||
exit(1)
|
exit(1)
|
||||||
ip_var_test.start(False, False)
|
ip_var_test.start(False, False)
|
||||||
ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols,
|
ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols,
|
||||||
sta_list=station_list,
|
sta_list=station_list,
|
||||||
#port_mgr_cols=port_mgr_cols,
|
# port_mgr_cols=port_mgr_cols,
|
||||||
report_file=report_f,
|
report_file=report_f,
|
||||||
systeminfopath=systeminfopath,
|
systeminfopath=systeminfopath,
|
||||||
duration_sec=Realm.parse_time(args.test_duration).total_seconds(),
|
duration_sec=Realm.parse_time(args.test_duration).total_seconds(),
|
||||||
@@ -403,6 +404,18 @@ python3 ./test_ipv4_variable_time.py
|
|||||||
print(ip_var_test.get_fail_message())
|
print(ip_var_test.get_fail_message())
|
||||||
ip_var_test.exit_fail()
|
ip_var_test.exit_fail()
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
if args.influx_db is not None:
|
||||||
|
from influx import RecordInflux
|
||||||
|
grapher = RecordInflux(_influx_host=args.mgr,
|
||||||
|
_port=args.mgr_port,
|
||||||
|
_influx_db=args.influx_db,
|
||||||
|
_influx_user=args.influx_user,
|
||||||
|
_influx_passwd=args.influx_passwd)
|
||||||
|
devices=[station.split('.')[-1] for station in station_list]
|
||||||
|
grapher.getdata(longevity=5,
|
||||||
|
devices=devices,
|
||||||
|
monitor_interval=2,
|
||||||
|
target_kpi=['bps rx'])
|
||||||
ip_var_test.cleanup()
|
ip_var_test.cleanup()
|
||||||
if ip_var_test.passes():
|
if ip_var_test.passes():
|
||||||
ip_var_test.success()
|
ip_var_test.success()
|
||||||
|
|||||||
Reference in New Issue
Block a user