diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index 7817cde2..d6ca9535 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -4,8 +4,9 @@ import base64 import Gnuplot import json import math -import time import mysql.connector as mariadb +import requests +import time from functions.common import * from numpy import * @@ -92,7 +93,7 @@ TESTS = { }, 'iobenchmark': { 'Enabled': False, - 'Rates': {}, + 'Data': {}, 'Results': {}, 'Status': {}, }, @@ -134,15 +135,19 @@ def disconnect_from_db(): def export_png_graph(name, dev): """Exports PNG graph using gnuplot, returns file path as str.""" - max_rate = max(800, max(rates)) - out_path = '{}/iobenchmark.png'.format(global_vars['TmpDir']) + max_rate = max(TESTS['iobenchmark']['Data'][name]['Read Rates']) + max_rate /= (1024**2) + max_rate = max(800, max_rate) + out_path = '{}/iobenchmark-{}.png'.format(global_vars['LogDir'], name) plot_data = '{}/iobenchmark-{}-raw.log'.format(global_vars['LogDir'], name) # Adjust Y-axis range to either 1000 or roughly max rate + 200 - y_range = math.ceil(max_rate/100)*100 + 200 + ## Round up to the nearest 100 and then add 200 + y_range = (math.ceil(max_rate/100)*100) + 200 # Run gnuplot commands g = Gnuplot.Gnuplot() + g('reset') g('set output "{}"'.format(out_path)) g('set terminal png large size 660,300 truecolor font "Noto Sans,11"') g('set title "I/O Benchmark"') @@ -402,7 +407,6 @@ def osticket_get_ticket_name(ticket_id): def osticket_needs_attention(ticket_id): """[DISABLED] Marks the ticket as "NEEDS ATTENTION" in osTicket.""" return # This function has been DISABLED due to a repurposing of that flag - if not ticket_id: raise GenericError if not ost_db['Cursor']: @@ -594,7 +598,7 @@ def post_drive_results(ticket_number): io_status = TESTS['iobenchmark']['Status'].get(name, None) if TESTS['iobenchmark']['Enabled'] and io_status not in ['Denied', 'Skipped']: one_line_graph = generate_horizontal_graph( - rates=TESTS['iobenchmark']['Data'][name]['Read Rates'], + rates=TESTS['iobenchmark']['Data'][name]['Merged Rates'], oneline=True) for c in COLORS.values(): one_line_graph = one_line_graph.replace(c, '') @@ -611,26 +615,19 @@ def post_drive_results(ticket_number): # imgur try: - url = upload_to_imgur(image_path) + url = upload_to_imgur(png_path) + report.append('Imgur: {}'.format(url)) except: # Oh well pass - else: - report.append('Imgur: {}'.format(url)) # Nextcloud try: - url = upload_to_nextcloud(image_path, ticket_number, name) + url = upload_to_nextcloud(png_path, ticket_number, name) + report.append('Nextcloud: {}'.format(url)) except: # Oh well pass - else: - report.append('Nextcloud: {}'.format(url)) - - # TODO-REMOVE TESTING - with open('/home/twoshirt/__ost_report_{}.txt'.format(name), 'w') as f: - for line in report: - f.write('{}\n'.format(line.strip())) # Post reply for drive osticket_post_reply( @@ -828,9 +825,9 @@ def run_iobenchmark(ticket_number): TESTS['iobenchmark']['Data'][name]['Read Rates'].append( cur_rate) TESTS['iobenchmark']['Data'][name]['Graph'].append( - '{percent} {rate}'.format( + '{percent:0.1f} {rate}'.format( percent=i/test_chunks*100, - rate=cur_rate/(1024**2))) + rate=int(cur_rate/(1024**2)))) if i % IO_VARS['Progress Refresh Rate'] == 0: # Update vertical graph update_io_progress( @@ -851,15 +848,16 @@ def run_iobenchmark(ticket_number): min(TESTS['iobenchmark']['Data'][name]['Read Rates'])/(1024**2), max(TESTS['iobenchmark']['Data'][name]['Read Rates'])/(1024**2)) TESTS['iobenchmark']['Data'][name]['Avg/Min/Max'] = avg_min_max - h_graph_rates = [] + TESTS['iobenchmark']['Data'][name]['Merged Rates'] = [] pos = 0 width = int(test_chunks / IO_VARS['Graph Horizontal Width']) for i in range(IO_VARS['Graph Horizontal Width']): # Append average rate for WIDTH number of rates to new array - h_graph_rates.append(sum( + TESTS['iobenchmark']['Data'][name]['Merged Rates'].append(sum( TESTS['iobenchmark']['Data'][name]['Read Rates'][pos:pos+width])/width) pos += width - report = generate_horizontal_graph(h_graph_rates) + report = generate_horizontal_graph( + TESTS['iobenchmark']['Data'][name]['Merged Rates']) report += '\n{}'.format(avg_min_max) TESTS['iobenchmark']['Results'][name] = report @@ -1500,9 +1498,9 @@ def upload_to_imgur(image_path): if not image_path: raise GenericError - # Read image file and convert to base64 + # Read image file and convert to base64 then convert to str with open(image_path, 'rb') as f: - image_data = base64.b64encode(f.read()) + image_data = base64.b64encode(f.read()).decode() # POST image url = "https://api.imgur.com/3/image" @@ -1535,7 +1533,7 @@ def upload_to_nextcloud(image_path, ticket_number, dev_name): image_data = f.read() # PUT image - url = '{base_url}/{ticket_number}_iobenchmark_{dev_name}_{date}'.format( + url = '{base_url}/{ticket_number}_iobenchmark_{dev_name}_{date}.png'.format( base_url=BENCHMARK_SERVER['Url'], ticket_number=ticket_number, dev_name=dev_name,