diff --git a/py-scripts/csv_to_influx.py b/py-scripts/csv_to_influx.py index 62c9bfea..f710356f 100755 --- a/py-scripts/csv_to_influx.py +++ b/py-scripts/csv_to_influx.py @@ -39,17 +39,19 @@ class CSVtoInflux(): _capture_signal_list=[], influxdb=None, _influx_tag=[], - target_csv=None): + target_csv=None, + sep='\t'): self.influxdb = influxdb self.target_csv = target_csv.replace('/home/lanforge/html-reports/', '') self.influx_tag = _influx_tag + self.sep = sep def read_csv(self, file): csv = open(file).read().split('\n') rows = list() for x in csv: if len(x) > 0: - rows.append(x.split('\t')) + rows.append(x.split(self.sep)) return rows # Submit data to the influx db if configured to do so. @@ -57,6 +59,7 @@ class CSVtoInflux(): df = self.read_csv(self.target_csv) length = list(range(0, len(df[0]))) columns = dict(zip(df[0], length)) + print('columns: %s' % columns) influx_variables = ['script', 'short-description', 'test_details', 'Graph-Group', 'DUT-HW-version', 'DUT-SW-version', 'DUT-Serial-Num', 'testbed', 'Units'] csv_variables = ['test-id', 'short-description', 'test details', 'Graph-Group', @@ -64,6 +67,7 @@ class CSVtoInflux(): csv_vs_influx = dict(zip(csv_variables, influx_variables)) for row in df[1:]: tags = dict() + print("row: %s" % row) short_description = row[columns['short-description']] numeric_score = float(row[columns['numeric-score']]) date = row[columns['Date']] @@ -138,6 +142,7 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t # This argument is specific to this script, so not part of the generic influxdb parser args # method above. parser.add_argument('--target_csv', help='CSV file to record to influx database', default="") + parser.add_argument('--sep', help='character to split CSV by', default='\t') args = parser.parse_args() @@ -151,7 +156,8 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t csvtoinflux = CSVtoInflux(influxdb=influxdb, target_csv=args.target_csv, - _influx_tag=args.influx_tag) + _influx_tag=args.influx_tag, + sep=args.sep) csvtoinflux.post_to_influx() diff --git a/py-scripts/grafana_profile.py b/py-scripts/grafana_profile.py index 6577614b..a4e4ad1f 100755 --- a/py-scripts/grafana_profile.py +++ b/py-scripts/grafana_profile.py @@ -98,7 +98,9 @@ class UseGrafana(LFCliBase): graph_groups_file=None, testbed=None, datasource='InfluxDB', - from_date='now-1y'): + from_date='now-1y', + graph_height=8, + graph__width=12): options = string.ascii_lowercase + string.ascii_uppercase + string.digits uid = ''.join(random.choice(options) for i in range(9)) input1 = dict() @@ -137,8 +139,8 @@ class UseGrafana(LFCliBase): panel = dict() gridpos = dict() - gridpos['h'] = 8 - gridpos['w'] = 12 + gridpos['h'] = graph_height + gridpos['w'] = graph__width gridpos['x'] = 0 gridpos['y'] = 0 @@ -343,6 +345,8 @@ def main(): optional.add_argument('--kpi', help='KPI file(s) which you want to graph form', action='append', default=None) optional.add_argument('--datasource', help='Name of Influx database if different from InfluxDB', default='InfluxDB') optional.add_argument('--from_date', help='Date you want to start your Grafana dashboard from', default='now-1y') + optional.add_argument('--graph_height', help='Custom height for the graph on grafana dashboard', default=8) + optional.add_argument('--graph_width', help='Custom width for the graph on grafana dashboard', default=12) args = parser.parse_args() Grafana = UseGrafana(args.grafana_token, @@ -372,7 +376,9 @@ def main(): graph_groups_file=args.graph_groups_file, testbed=args.testbed, datasource=args.datasource, - from_date=args.from_date) + from_date=args.from_date, + graph_height=args.graph_height, + graph__width=args.graph_width) if __name__ == "__main__":