PNG graph export and uploads working
This commit is contained in:
parent
8d5a4b4079
commit
7506cd017b
1 changed files with 24 additions and 26 deletions
|
|
@ -4,8 +4,9 @@ import base64
|
||||||
import Gnuplot
|
import Gnuplot
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import time
|
|
||||||
import mysql.connector as mariadb
|
import mysql.connector as mariadb
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
from functions.common import *
|
from functions.common import *
|
||||||
from numpy import *
|
from numpy import *
|
||||||
|
|
@ -92,7 +93,7 @@ TESTS = {
|
||||||
},
|
},
|
||||||
'iobenchmark': {
|
'iobenchmark': {
|
||||||
'Enabled': False,
|
'Enabled': False,
|
||||||
'Rates': {},
|
'Data': {},
|
||||||
'Results': {},
|
'Results': {},
|
||||||
'Status': {},
|
'Status': {},
|
||||||
},
|
},
|
||||||
|
|
@ -134,15 +135,19 @@ def disconnect_from_db():
|
||||||
|
|
||||||
def export_png_graph(name, dev):
|
def export_png_graph(name, dev):
|
||||||
"""Exports PNG graph using gnuplot, returns file path as str."""
|
"""Exports PNG graph using gnuplot, returns file path as str."""
|
||||||
max_rate = max(800, max(rates))
|
max_rate = max(TESTS['iobenchmark']['Data'][name]['Read Rates'])
|
||||||
out_path = '{}/iobenchmark.png'.format(global_vars['TmpDir'])
|
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)
|
plot_data = '{}/iobenchmark-{}-raw.log'.format(global_vars['LogDir'], name)
|
||||||
|
|
||||||
# Adjust Y-axis range to either 1000 or roughly max rate + 200
|
# 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
|
# Run gnuplot commands
|
||||||
g = Gnuplot.Gnuplot()
|
g = Gnuplot.Gnuplot()
|
||||||
|
g('reset')
|
||||||
g('set output "{}"'.format(out_path))
|
g('set output "{}"'.format(out_path))
|
||||||
g('set terminal png large size 660,300 truecolor font "Noto Sans,11"')
|
g('set terminal png large size 660,300 truecolor font "Noto Sans,11"')
|
||||||
g('set title "I/O Benchmark"')
|
g('set title "I/O Benchmark"')
|
||||||
|
|
@ -402,7 +407,6 @@ def osticket_get_ticket_name(ticket_id):
|
||||||
def osticket_needs_attention(ticket_id):
|
def osticket_needs_attention(ticket_id):
|
||||||
"""[DISABLED] Marks the ticket as "NEEDS ATTENTION" in osTicket."""
|
"""[DISABLED] Marks the ticket as "NEEDS ATTENTION" in osTicket."""
|
||||||
return # This function has been DISABLED due to a repurposing of that flag
|
return # This function has been DISABLED due to a repurposing of that flag
|
||||||
|
|
||||||
if not ticket_id:
|
if not ticket_id:
|
||||||
raise GenericError
|
raise GenericError
|
||||||
if not ost_db['Cursor']:
|
if not ost_db['Cursor']:
|
||||||
|
|
@ -594,7 +598,7 @@ def post_drive_results(ticket_number):
|
||||||
io_status = TESTS['iobenchmark']['Status'].get(name, None)
|
io_status = TESTS['iobenchmark']['Status'].get(name, None)
|
||||||
if TESTS['iobenchmark']['Enabled'] and io_status not in ['Denied', 'Skipped']:
|
if TESTS['iobenchmark']['Enabled'] and io_status not in ['Denied', 'Skipped']:
|
||||||
one_line_graph = generate_horizontal_graph(
|
one_line_graph = generate_horizontal_graph(
|
||||||
rates=TESTS['iobenchmark']['Data'][name]['Read Rates'],
|
rates=TESTS['iobenchmark']['Data'][name]['Merged Rates'],
|
||||||
oneline=True)
|
oneline=True)
|
||||||
for c in COLORS.values():
|
for c in COLORS.values():
|
||||||
one_line_graph = one_line_graph.replace(c, '')
|
one_line_graph = one_line_graph.replace(c, '')
|
||||||
|
|
@ -611,26 +615,19 @@ def post_drive_results(ticket_number):
|
||||||
|
|
||||||
# imgur
|
# imgur
|
||||||
try:
|
try:
|
||||||
url = upload_to_imgur(image_path)
|
url = upload_to_imgur(png_path)
|
||||||
|
report.append('Imgur: {}'.format(url))
|
||||||
except:
|
except:
|
||||||
# Oh well
|
# Oh well
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
report.append('Imgur: {}'.format(url))
|
|
||||||
|
|
||||||
# Nextcloud
|
# Nextcloud
|
||||||
try:
|
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:
|
except:
|
||||||
# Oh well
|
# Oh well
|
||||||
pass
|
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
|
# Post reply for drive
|
||||||
osticket_post_reply(
|
osticket_post_reply(
|
||||||
|
|
@ -828,9 +825,9 @@ def run_iobenchmark(ticket_number):
|
||||||
TESTS['iobenchmark']['Data'][name]['Read Rates'].append(
|
TESTS['iobenchmark']['Data'][name]['Read Rates'].append(
|
||||||
cur_rate)
|
cur_rate)
|
||||||
TESTS['iobenchmark']['Data'][name]['Graph'].append(
|
TESTS['iobenchmark']['Data'][name]['Graph'].append(
|
||||||
'{percent} {rate}'.format(
|
'{percent:0.1f} {rate}'.format(
|
||||||
percent=i/test_chunks*100,
|
percent=i/test_chunks*100,
|
||||||
rate=cur_rate/(1024**2)))
|
rate=int(cur_rate/(1024**2))))
|
||||||
if i % IO_VARS['Progress Refresh Rate'] == 0:
|
if i % IO_VARS['Progress Refresh Rate'] == 0:
|
||||||
# Update vertical graph
|
# Update vertical graph
|
||||||
update_io_progress(
|
update_io_progress(
|
||||||
|
|
@ -851,15 +848,16 @@ def run_iobenchmark(ticket_number):
|
||||||
min(TESTS['iobenchmark']['Data'][name]['Read Rates'])/(1024**2),
|
min(TESTS['iobenchmark']['Data'][name]['Read Rates'])/(1024**2),
|
||||||
max(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
|
TESTS['iobenchmark']['Data'][name]['Avg/Min/Max'] = avg_min_max
|
||||||
h_graph_rates = []
|
TESTS['iobenchmark']['Data'][name]['Merged Rates'] = []
|
||||||
pos = 0
|
pos = 0
|
||||||
width = int(test_chunks / IO_VARS['Graph Horizontal Width'])
|
width = int(test_chunks / IO_VARS['Graph Horizontal Width'])
|
||||||
for i in range(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
|
# 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)
|
TESTS['iobenchmark']['Data'][name]['Read Rates'][pos:pos+width])/width)
|
||||||
pos += 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)
|
report += '\n{}'.format(avg_min_max)
|
||||||
TESTS['iobenchmark']['Results'][name] = report
|
TESTS['iobenchmark']['Results'][name] = report
|
||||||
|
|
||||||
|
|
@ -1500,9 +1498,9 @@ def upload_to_imgur(image_path):
|
||||||
if not image_path:
|
if not image_path:
|
||||||
raise GenericError
|
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:
|
with open(image_path, 'rb') as f:
|
||||||
image_data = base64.b64encode(f.read())
|
image_data = base64.b64encode(f.read()).decode()
|
||||||
|
|
||||||
# POST image
|
# POST image
|
||||||
url = "https://api.imgur.com/3/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()
|
image_data = f.read()
|
||||||
|
|
||||||
# PUT image
|
# 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'],
|
base_url=BENCHMARK_SERVER['Url'],
|
||||||
ticket_number=ticket_number,
|
ticket_number=ticket_number,
|
||||||
dev_name=dev_name,
|
dev_name=dev_name,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue