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