Skip to content

Commit

Permalink
Merge pull request #44 from pafernanr/devel
Browse files Browse the repository at this point in the history
Include Host details and add restart events to Charts
  • Loading branch information
pafernanr authored May 15, 2024
2 parents c240bb8 + 3aedcbd commit 6636f60
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 17 deletions.
Binary file modified doc/sarcharts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions sarcharts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ def __init__(self):
self.args.outputpath + "/html")

def main(self):
# import ipdb; ipdb.set_trace()
if len(self.args.sarfilespaths) > 0:
sarfiles = util.get_filelist(self.args.sarfilespaths)
util.debug(self.args, 'D', "sarfiles: " + str(sarfiles))
charts = Sadf().sar_to_chartjs(self.args, sarfiles)
ChartJS().write_files(self.args, charts)
util.debug(self.args, '', "Open SarCharts in default browser.")
webbrowser.open(self.args.outputpath, 0, True)
else:
self.parser.print_help()
util.debug(self.args, 'E', "No valid `sa` files on provided path.")
if len(sarfiles) > 0:
util.debug(self.args, 'D', "sarfiles: " + str(sarfiles))
charts = Sadf().sar_to_chartjs(self.args, sarfiles)
ChartJS().write_files(self.args, charts)
util.debug(self.args, '', "Open SarCharts in default browser.")
webbrowser.open(self.args.outputpath, 0, True)
else:
self.parser.print_help()
util.debug(
self.args, 'E',
f"No valid `sa??` files in `{self.args.sarfilespaths}`.")
7 changes: 7 additions & 0 deletions sarcharts/html/js/chartjs-plugin-annotation.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sarcharts/lib/chartjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def write_files(self, args, charts):
"numberofcpus": nodecharts['number-of-cpus'],
"timezone": nodecharts['timezone'],
"details": csvdata,
"restarts": nodecharts['restarts'],
"pages": sorted(nodecharts['activities'].keys()),
"colors": self.colors,
"hostname": nodename,
Expand Down
15 changes: 11 additions & 4 deletions sarcharts/lib/sadf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ def sar_to_chartjs(self, args, sarfiles):
"number-of-cpus": hdata['number-of-cpus'],
"timezone": hdata['timezone'],
"xlabels": [],
"activities": {}
"activities": {},
"restarts": []
}
for istats in range(len(hdata['restarts'])):
for r in hdata['restarts'][istats].values():
date = f"{r['date']} {r['time']}"
if util.in_date_range(args, date):
charts[nodename]['restarts'].append(date)
charts[nodename]['xlabels'].append(date)
for istats in range(len(hdata['statistics'])):
for act, adata in hdata['statistics'][istats].items():
pbi += 1
Expand Down Expand Up @@ -180,9 +187,9 @@ def sar_to_chartjs(self, args, sarfiles):
"label": h,
"values": []
})
for i in range(len(fields[datastart:])):
charts[nodename]['activities'][activity]['datasets'][item][i]['values'].append({
for f in range(len(fields[datastart:])):
charts[nodename]['activities'][activity]['datasets'][item][f]['values'].append({
'x': fields[2],
'y': fields[i+datastart]
'y': fields[f+datastart]
})
return charts
2 changes: 2 additions & 0 deletions sarcharts/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


def debug(args, sev, msg):
if args.quiet:
return
C = {
'I': '\033[0;34m',
'D': '\033[01;36m',
Expand Down
37 changes: 34 additions & 3 deletions sarcharts/templates/chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<link rel="stylesheet" href="html/css/sarcharts.css" />
<link rel="stylesheet" href="html/css/ul-select.css" />
<script src="html/js/jquery.js"></script>
<script src="html/js/chart.umd.js"></script>
<script src="html/js/hammer.min.js"></script>
<script src="html/js/chartjs-plugin-zoom.min.js"></script>
<script src="html/js/ul-select.js"></script>
<script src="html/js/chart.umd.js"></script>
<script src="html/js/chartjs-plugin-zoom.min.js"></script>
<script src="html/js/chartjs-plugin-annotation.min.js"></script>

</head>
<body>
Expand All @@ -36,6 +37,29 @@
showChart($(this).text());
});


{% for i in range(restarts|length) %}
const restart{{ i }} = {
type: 'line',
borderColor: 'rgba(255, 0, 0, 0.4)',
borderWidth: 1,
display: (ctx) => ctx.chart.isDatasetVisible(1),
label: {
display: true,
content: 'restart',
position: 'start',
backgroundColor: 'transparent',
opacity: 0,
rotation: 90,
xAdjust: 5,
font: { size: 10 },
color: 'rgba(255, 0, 0, 0.4)'
},
scaleID: 'x',
value: '{{ restarts[i] }}'
};
{% endfor %}

function showChart(name) {
myChart.destroy();
myChart = new Chart(ctx, {
Expand All @@ -51,6 +75,13 @@
legend: {
position: 'top'
},
annotation: {
annotations: {
{% for i in range(restarts|length) %}
restart{{ i }}{{ ", " if not loop.last else "" }}
{% endfor %}
}
},
zoom: {
zoom: {
drag: {
Expand Down Expand Up @@ -99,7 +130,7 @@
selhost="{{ hostname }}"
$('#hostlist').ulSelect(function(elem) {
selhost=$(elem).text()
window.location = selhost+"_cpu-load.html"
window.location = selhost+"_{{ pages[0] }}.html"
});
selchart="{{ chart }}"
$('#chartlist').ulSelect(function(elem) {
Expand Down
7 changes: 6 additions & 1 deletion sarcharts/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<li><b>machine:</b> {{ machine}}</li>
<li><b>cpunumber:</b> {{ numberofcpus }}</li>
<li><b>starttime:</b> {{ xlabels[0] }} {{ timezone }}</li>
<li><b>endtime:</b> {{ xlabels[-1] }} {{ timezone }}</li></h3>
<li><b>endtime:</b> {{ xlabels[-1] }} {{ timezone }}</li>
</ul><!--
{% for r in restarts %}
<br> {{r}}
{% endfor %}
-->
</div>

0 comments on commit 6636f60

Please sign in to comment.