I/O graph export/upload sections working
This commit is contained in:
parent
12ea0fdd53
commit
2c0093aa9a
3 changed files with 41 additions and 27 deletions
|
|
@ -5,7 +5,6 @@ import re
|
|||
import time
|
||||
|
||||
from collections import OrderedDict
|
||||
from functions.png_graph import *
|
||||
from functions.osticket import *
|
||||
from functions.sensors import *
|
||||
from functions.tmux import *
|
||||
|
|
@ -1061,7 +1060,6 @@ def run_io_benchmark(state, test):
|
|||
try:
|
||||
test.merged_rates = []
|
||||
test.read_rates = []
|
||||
test.vertical_graph = []
|
||||
test.dev.calc_io_dd_values()
|
||||
|
||||
# Run dd read tests
|
||||
|
|
@ -1088,10 +1086,6 @@ def run_io_benchmark(state, test):
|
|||
|
||||
# Add rate to lists
|
||||
test.read_rates.append(cur_rate)
|
||||
test.vertical_graph.append(
|
||||
'{percent:0.1f} {rate}'.format(
|
||||
percent=(i/test.dev.dd_chunks)*100,
|
||||
rate=int(cur_rate/(1024**2))))
|
||||
|
||||
# Show progress
|
||||
if i % IO_VARS['Progress Refresh Rate'] == 0:
|
||||
|
|
@ -1176,10 +1170,6 @@ def run_io_benchmark(state, test):
|
|||
elif not 'N/A' in test.status:
|
||||
test.update_status('Unknown')
|
||||
|
||||
# Save log
|
||||
with open(test.io_benchmark_out.replace('.', '-raw.'), 'a') as f:
|
||||
f.write('\n'.join(test.vertical_graph))
|
||||
|
||||
# Done
|
||||
update_progress_pane(state)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,23 +2,34 @@
|
|||
|
||||
import base64
|
||||
import Gnuplot
|
||||
import json
|
||||
import math
|
||||
import requests
|
||||
|
||||
from functions.common import *
|
||||
|
||||
# Functions
|
||||
def export_png_graph(name, dev):
|
||||
def export_io_graph(disk):
|
||||
"""Exports PNG graph using gnuplot, returns file path as str."""
|
||||
max_rate = max(TESTS['iobenchmark']['Data'][name]['Read Rates'])
|
||||
max_rate /= (1024**2)
|
||||
read_rates = disk.tests['I/O Benchmark'].read_rates
|
||||
max_rate = max(read_rates) / (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)
|
||||
out_path = '{}/iobenchmark-{}.png'.format(
|
||||
global_vars['LogDir'], disk.name)
|
||||
plot_data = '{}/iobenchmark-{}-plot.data'.format(
|
||||
global_vars['LogDir'], disk.name)
|
||||
|
||||
# Adjust Y-axis range to either 1000 or roughly max rate + 200
|
||||
## Round up to the nearest 100 and then add 200
|
||||
y_range = (math.ceil(max_rate/100)*100) + 200
|
||||
|
||||
# Save plot data to file for Gnuplot
|
||||
with open(plot_data, 'w') as f:
|
||||
for i in range(len(read_rates)):
|
||||
_percent = ( (i+1) / len(read_rates) ) * 100
|
||||
_rate = int( read_rates[i] / (1024**2) )
|
||||
f.write('{:0.1f} {}\n'.format(_percent, _rate))
|
||||
|
||||
# Run gnuplot commands
|
||||
g = Gnuplot.Gnuplot()
|
||||
g('reset')
|
||||
|
|
@ -27,12 +38,9 @@ def export_png_graph(name, dev):
|
|||
g('set title "I/O Benchmark"')
|
||||
g('set yrange [0:{}]'.format(y_range))
|
||||
g('set style data lines')
|
||||
g('plot "{data}" title "{size} ({tran}) {model} {serial}"'.format(
|
||||
data=plot_data,
|
||||
size=dev['lsblk'].get('size', '???b'),
|
||||
tran=dev['lsblk'].get('tran', '???'),
|
||||
model=dev['lsblk'].get('model', 'Unknown Model'),
|
||||
serial=dev['lsblk'].get('serial', 'Unknown Serial'),
|
||||
g('plot "{}" title "{}"'.format(
|
||||
plot_data,
|
||||
disk.description.replace('_', ' '),
|
||||
))
|
||||
|
||||
# Cleanup
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from functions.common import *
|
||||
from functions.io_graph import *
|
||||
from settings.osticket import *
|
||||
|
||||
# STATIC VARIABLES
|
||||
|
|
@ -122,7 +122,7 @@ class osTicket():
|
|||
# Done
|
||||
return out_report
|
||||
|
||||
def generate_report(self, dev):
|
||||
def generate_report(self, dev, ticket_id):
|
||||
"""Generate device report for osTicket, returns list."""
|
||||
report = []
|
||||
results = self.get_device_overall_results(dev)
|
||||
|
|
@ -141,9 +141,25 @@ class osTicket():
|
|||
for name, test in dev.tests.items():
|
||||
report.extend(self.convert_report(name, test))
|
||||
if name == 'I/O Benchmark':
|
||||
# TODO: Create PNG graph and upload to imgur/Nextcloud
|
||||
report.append('Imgur: TODO')
|
||||
report.append('Nextcloud: TODO')
|
||||
# Create PNG graph
|
||||
try:
|
||||
graph_file = export_io_graph(dev)
|
||||
except (AttributeError, KeyError):
|
||||
report.append('Failed to export graph')
|
||||
else:
|
||||
# Upload to Imgur
|
||||
try:
|
||||
url = upload_to_imgur(graph_file)
|
||||
report.append('Imgur: {}'.format(url))
|
||||
except Exception:
|
||||
report.append('Imgur: Failed to upload graph')
|
||||
|
||||
# Upload to Nextcloud
|
||||
try:
|
||||
url = upload_to_nextcloud(graph_file, ticket_id, dev.name)
|
||||
report.append('Nextcloud: {}'.format(url))
|
||||
except Exception:
|
||||
report.append('Nextcloud: Failed to upload graph')
|
||||
report.append(' ')
|
||||
|
||||
# Volumes
|
||||
|
|
@ -295,7 +311,7 @@ class osTicket():
|
|||
|
||||
def post_device_results(self, dev, ticket_id):
|
||||
"""Generate osTicket friendly report and post as response to ticket."""
|
||||
response = self.generate_report(dev)
|
||||
response = self.generate_report(dev, ticket_id)
|
||||
self.post_response(response, ticket_id)
|
||||
|
||||
def post_response(self, response, ticket_id):
|
||||
|
|
|
|||
Loading…
Reference in a new issue