mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 18:58:01 +00:00 
			
		
		
		
	make csv_to_influx work and make test_ipv4_variable_time work properly
Signed-off-by: Matthew Stidham <stidmatt@protonmail.com>
This commit is contained in:
		
							
								
								
									
										27
									
								
								py-scripts/csv_to_influx.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										27
									
								
								py-scripts/csv_to_influx.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -32,7 +32,8 @@ class CSVtoInflux(Realm): | ||||
|                  _proxy_str=None, | ||||
|                  _capture_signal_list=[], | ||||
|                  influxdb=None, | ||||
|                  df=None): | ||||
|                  #_influx_tag=[], | ||||
|                  target_csv=None): | ||||
|         super().__init__(lfclient_host=lfclient_host, | ||||
|                          lfclient_port=lfclient_port, | ||||
|                          debug_=debug, | ||||
| @@ -41,14 +42,18 @@ class CSVtoInflux(Realm): | ||||
|                          _proxy_str=_proxy_str, | ||||
|                          _capture_signal_list=_capture_signal_list) | ||||
|         self.influxdb = influxdb | ||||
|         self.df = df | ||||
|         self.target_csv = target_csv | ||||
|         #self.influx_tag = _influx_tag | ||||
|  | ||||
|     # Submit data to the influx db if configured to do so. | ||||
|     def post_to_influx(self): | ||||
|         dates = list(set(self.df['Date'])) | ||||
|         scriptname=self.df['test-id'][0] | ||||
|         df = pd.read_csv(self.target_csv, sep='\t') | ||||
|         df['Date'] = pd.to_datetime(df['Date'], unit='s') | ||||
|         df['Date'] = [str(timestamp.isoformat()) for timestamp in df['Date']] | ||||
|         dates = list(set(df['Date'])) | ||||
|         scriptname=df['test-id'][0] | ||||
|         for date in dates: | ||||
|             kpi2 = self.df[self.df['Date'] == date][['Date', 'test details', 'numeric-score','test-id']] | ||||
|             kpi2 = df[df['Date'] == date][['Date', 'test details', 'numeric-score', 'test-id']] | ||||
|             metrics = list(set(kpi2['test details'])) | ||||
|             targets = dict() | ||||
|             for k in metrics: | ||||
| @@ -57,6 +62,8 @@ class CSVtoInflux(Realm): | ||||
|             targets | ||||
|             tags = dict() | ||||
|             tags['script'] = scriptname | ||||
|             #for item in self.influx_tag: | ||||
|                 #tags[item[0]] = item[1] | ||||
|             for k in targets.keys(): | ||||
|                 self.influxdb.post_to_influx(k, targets[k], tags, date) | ||||
|  | ||||
| @@ -109,6 +116,7 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t | ||||
|     parser.add_argument('--influx_token', help='Token for the Influx database') | ||||
|     parser.add_argument('--influx_bucket', help='Name of the Influx bucket') | ||||
|     parser.add_argument('--target_csv', help='CSV file to record to influx database', required=True) | ||||
|     parser.add_argument('--influx_tag', action='append', nargs=2, help='--influx_tag <key> <val>   Can add more than one of these.') | ||||
|  | ||||
|     args = parser.parse_args() | ||||
|  | ||||
| @@ -122,12 +130,11 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t | ||||
|                                 _influx_org=args.influx_org, | ||||
|                                 _influx_token=args.influx_token, | ||||
|                                 _influx_bucket=args.influx_bucket) | ||||
|     df = pd.read_csv(args.target_csv) | ||||
|                                 #_influx_tag=args.influx_tag) | ||||
|  | ||||
|     csvtoinflux = CSVtoInflux(args=args, | ||||
|                               influxdb=influxdb, | ||||
|                               df=df) | ||||
|     csvtoinflux.record_kpi() | ||||
|     csvtoinflux = CSVtoInflux(influxdb=influxdb, | ||||
|                               target_csv=args.target_csv) | ||||
|     csvtoinflux.post_to_influx() | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|   | ||||
| @@ -269,6 +269,7 @@ python3 ./test_ipv4_variable_time.py | ||||
|     parser.add_argument('--influx_bucket', help='Password for your Influx database') | ||||
|     parser.add_argument('--influx_org', help='Name of your Influx database') | ||||
|     parser.add_argument('--influx_port', help='Port where your influx database is located', default=8086) | ||||
|     parser.add_argument('--influx_tag', action='append', nargs=2, help='--influx_tag <key> <val>   Can add more than one of these.') | ||||
|  | ||||
|     args = parser.parse_args() | ||||
|  | ||||
| @@ -386,25 +387,6 @@ python3 ./test_ipv4_variable_time.py | ||||
|             "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) | ||||
|     ip_var_test.start(False, False) | ||||
|     ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols, | ||||
|                                     sta_list=station_list, | ||||
|                                     # port_mgr_cols=port_mgr_cols, | ||||
|                                     report_file=report_f, | ||||
|                                     systeminfopath=systeminfopath, | ||||
|                                     duration_sec=Realm.parse_time(args.test_duration).total_seconds(), | ||||
|                                     monitor_interval_ms=monitor_interval, | ||||
|                                     created_cx=layer3connections, | ||||
|                                     output_format=output, | ||||
|                                     compared_report=compared_rept, | ||||
|                                     script_name='test_ipv4_variable_time', | ||||
|                                     arguments=args, | ||||
|                                     debug=args.debug) | ||||
|  | ||||
|     ip_var_test.stop() | ||||
|     if not ip_var_test.passes(): | ||||
|         print(ip_var_test.get_fail_message()) | ||||
|         ip_var_test.exit_fail() | ||||
|     LFUtils.wait_until_ports_admin_up(port_list=station_list) | ||||
|  | ||||
|     if args.influx_org is not None: | ||||
|         from influx2 import RecordInflux | ||||
| @@ -416,10 +398,36 @@ python3 ./test_ipv4_variable_time.py | ||||
|         devices=[station.split('.')[-1] for station in station_list] | ||||
|         tags=dict() | ||||
|         tags['script']='test_ipv4_variable_time' | ||||
|         grapher.monitor_port_data(longevity=5, | ||||
|                         devices=devices, | ||||
|                         monitor_interval=2, | ||||
|                         tags=tags) | ||||
|         try: | ||||
|             for k in args.influx_tag: | ||||
|                 tags[k[0]] = k[1] | ||||
|         except: | ||||
|             pass | ||||
|         grapher.monitor_port_data(longevity=Realm.parse_time(args.test_duration).total_seconds(), | ||||
|                                   devices=devices, | ||||
|                                   monitor_interval=Realm.parse_time(args.monitor_interval).total_seconds(), | ||||
|                                   tags=tags) | ||||
|     else: | ||||
|         ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols, | ||||
|                                         sta_list=station_list, | ||||
|                                         # port_mgr_cols=port_mgr_cols, | ||||
|                                         report_file=report_f, | ||||
|                                         systeminfopath=systeminfopath, | ||||
|                                         duration_sec=Realm.parse_time(args.test_duration).total_seconds(), | ||||
|                                         monitor_interval_ms=monitor_interval, | ||||
|                                         created_cx=layer3connections, | ||||
|                                         output_format=output, | ||||
|                                         compared_report=compared_rept, | ||||
|                                         script_name='test_ipv4_variable_time', | ||||
|                                         arguments=args, | ||||
|                                         debug=args.debug) | ||||
|  | ||||
|     ip_var_test.stop() | ||||
|     if not ip_var_test.passes(): | ||||
|         print(ip_var_test.get_fail_message()) | ||||
|         ip_var_test.exit_fail() | ||||
|     LFUtils.wait_until_ports_admin_up(port_list=station_list) | ||||
|  | ||||
|     ip_var_test.cleanup() | ||||
|     if ip_var_test.passes(): | ||||
|         ip_var_test.success() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Matthew Stidham
					Matthew Stidham