Commit aa7e2a8c authored by Julius Metz's avatar Julius Metz

first plot generator basics, datetime added to data

parent cae10365
import plotly.io as pio import plotly.io as pio
import datetime
def cpu_plot(values, title=None): def cpu_plot(values, title=None, xtitle=None, ytitle=None):
plot = { plot = {
'data': [], 'data': [],
'layout': { 'layout': {
...@@ -9,15 +10,24 @@ def cpu_plot(values, title=None): ...@@ -9,15 +10,24 @@ def cpu_plot(values, title=None):
'title': { 'title': {
'text': title 'text': title
}, },
'xaxis': {
'title': xtitle,
},
'yaxis': {
'title': ytitle,
},
}, },
} }
for cmd, cmd_data in values.items(): for cmd, cmd_data in values.items():
CPU = cmd_data.get('CPU', [])
if not any(elem != '0' for elem in CPU):
continue
plot['data'].append( plot['data'].append(
{ {
'type': 'scatter', 'type': 'scatter',
'mode': 'markers', 'mode': 'markers',
'x': cmd_data.get('Time', []), 'x': cmd_data.get('datetime', []),
'y': cmd_data.get('CPU', []), 'y': cmd_data.get('CPU', []),
'name': cmd, 'name': cmd,
} }
......
import subprocess import subprocess
from pathlib import Path from pathlib import Path
import time import datetime
import click import click
import plots_generators import plots_generators
HEAD_BLACKLIST = ['Time', 'Date']
CONFIG = { CONFIG = {
'cpu_plot':{ 'cpu_plot':{
'title': 'CPU load', 'title': 'CPU load',
'xtitle': 'Date',
'ytitle': 'CPU load',
} }
} }
def datestr2date(datestr):
return datetime.date(
int(datestr[:4]),
int(datestr[4:6]),
int(datestr[6:8]),
)
def parse_file(path, collectl): def parse_file(path, collectl):
process = subprocess.run([collectl, '-P', '-p', path, '-sZ'], capture_output=True) process = subprocess.run([collectl, '-P', '-p', path, '-sZ'], capture_output=True)
output = process.stdout.decode().splitlines() output = process.stdout.decode().splitlines()
head = output.pop(0).split(' ') head = output.pop(0).split(' ')
head[0] = head[0][1:] head[0] = head[0][1:]
entrys_data = {} entrys_data = {}
tmp_date = None
tmp_time = None
for entry in output: for entry in output:
splited_entry = entry.split(' ', len(head)) splited_entry = entry.split(' ', len(head))
cmd = splited_entry[-1] cmd = splited_entry[-1]
if not cmd in entrys_data: if not cmd in entrys_data:
entrys_data[cmd] = {head_elem : [] for head_elem in head[:-1]} entrys_data[cmd] = {
head_elem : [] for head_elem in head[:-1] if head_elem not in HEAD_BLACKLIST
}
entrys_data[cmd]['datetime'] = []
for i, head_elem in enumerate(head[:-1]): for i, head_elem in enumerate(head[:-1]):
entrys_data[cmd][head_elem].append(splited_entry[i]) if head_elem == 'Date':
tmp_date = datestr2date(splited_entry[i])
if head_elem == 'Time':
tmp_time = datetime.time.fromisoformat(splited_entry[i])
if not head_elem in HEAD_BLACKLIST:
entrys_data[cmd][head_elem].append(splited_entry[i])
entrys_data[cmd]['datetime'].append(
datetime.datetime.combine(tmp_date, tmp_time),
)
return entrys_data return entrys_data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment