Skip to content

Commit 0e29013

Browse files
committed
Initial commit
0 parents  commit 0e29013

File tree

12 files changed

+256
-0
lines changed

12 files changed

+256
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rpmui
2+
rpmui-linux*

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2020 moson-mo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# rpmui
2+
## Renoir power metrics UI
3+
</br>
4+
5+
A simple UI app showing some Renoir power metrics.</br>
6+
It consists of </br>
7+
- A small executable making use of WebKit in order to render HTML</br>
8+
- The HTML/JS frontend which fetches and displays power metrics via [Chart.js]("https://www.chartjs.org/").
9+
10+
The HTML page (main.html) can also be opened directly in your browser instead.
11+
12+
![rpmui](https://github.com/moson-mo/rpmui/raw/master/screenshots/rpmui.png?inline=true)
13+
</br>
14+
15+
## How to install
16+
17+
#### Manual
18+
19+
Binaries are available from the [releases](https://github.com/moson-mo/rpmui/releases) page.</br>
20+
21+
## How to build
22+
23+
* Install go from your package manager or download it from the [Golang](https://golang.org/dl/) site.
24+
* Clone repo with `git clone https://github.com/moson-mo/rpmui.git`
25+
* Change to rpmui dir: `cd rpmui`
26+
* Build with `go build`
27+
</br>
28+
29+
## How to customize
30+
31+
In the default configuration, the graphs have been made for an 8-core AMD Renoir model.</br>
32+
You can customize *main.html* to your own needs...
33+
</br>
34+
35+
## Dependencies / Prerequisites
36+
37+
* [rpms](https://gitlab.com/moson-mo/rpms/) - Renoir power metrics server
38+
</br>

main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/kardianos/osext"
7+
"github.com/webview/webview"
8+
)
9+
10+
func main() {
11+
path, err := osext.ExecutableFolder()
12+
if err != nil {
13+
log.Fatal(err)
14+
}
15+
w := webview.New(false)
16+
defer w.Destroy()
17+
w.SetTitle("Renoir Power Metrics")
18+
w.SetSize(800, 600, webview.HintNone)
19+
w.Navigate("file://" + path + "/web/main.html")
20+
w.Run()
21+
}

screenshots/rpmui.png

136 KB
Loading

web/chart.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script src="js/jquery-3.5.1.min.js"></script>
6+
<script src="js/Chart.min.js"></script>
7+
<script src="js/chart.js"></script>
8+
<link rel="stylesheet" href="css/chart.css" />
9+
</head>
10+
11+
<body>
12+
<div id="container">
13+
<canvas id="chart"></canvas>
14+
</div>
15+
</body>
16+
17+
</html>

web/css/chart.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
body {
2+
font-family: monospace;
3+
}
4+
5+
#container {
6+
position: absolute;
7+
margin: auto;
8+
top: 0;
9+
right: 0;
10+
bottom: 0;
11+
left: 0;
12+
height: 95%;
13+
width: 95%;
14+
}

web/css/main.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
body {
2+
font-family: monospace;
3+
}
4+
5+
#container {
6+
position: absolute;
7+
margin: auto;
8+
top: 0;
9+
right: 0;
10+
bottom: 0;
11+
left: 0;
12+
height: 100%;
13+
width: 100%;
14+
}
15+
16+
iframe {
17+
border: 0px;
18+
}
19+
20+
.chart {
21+
height: 100%;
22+
width: 50%;
23+
float: left;
24+
}
25+
26+
.sub-container {
27+
width: 100%;
28+
height: 50%;
29+
}

web/js/Chart.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/js/chart.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
function getUrlVars() {
2+
var vars = {};
3+
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
4+
vars[key] = decodeURIComponent(value);
5+
});
6+
return vars;
7+
}
8+
9+
function getRandomColor() {
10+
var letters = '0123456789ABCDEF'.split('');
11+
var color = '#';
12+
for (var i = 0; i < 6; i++) {
13+
color += letters[Math.floor(Math.random() * 16)];
14+
}
15+
return color;
16+
}
17+
18+
$(document).ready(function () {
19+
var dat = [[]];
20+
var colors = ["#E74C3C", "#3498DB", "#2ECC71", "#F39C12", "#2C3E50"]
21+
22+
var vars = getUrlVars();
23+
24+
if (vars["metrics"] === undefined || vars["metrics"][0] === "undefined") {
25+
$("#container").html("Please specify the metrics for the chart by adding a query parameter \"metrics\".</br>Multiple metrics can be separated by comma.</br></br>Example: ?metrics=SOCKET POWER,PPT FAST LIMIT,PPT SLOW LIMIT")
26+
return;
27+
}
28+
29+
var metrics = vars["metrics"].split(',');
30+
var title = vars["title"]
31+
32+
var chart = new Chart($("#chart"), {
33+
type: 'line',
34+
options: {
35+
animation: {
36+
duration: 0,
37+
},
38+
responsive: true,
39+
maintainAspectRatio: false,
40+
title: {
41+
text: title,
42+
display: true,
43+
},
44+
scales: {
45+
yAxes: [{
46+
ticks: {
47+
min: 0,
48+
},
49+
}]
50+
},
51+
}
52+
});
53+
54+
for (var x = 0; x < metrics.length; x++) {
55+
dat[x] = [];
56+
var col = "";
57+
if (x > colors.length) {
58+
col = getRandomColor();
59+
} else {
60+
col = colors[x];
61+
}
62+
chart.data.datasets.push(
63+
{
64+
label: metrics[x],
65+
fill: false,
66+
data: dat[x],
67+
borderColor: col
68+
}
69+
);
70+
}
71+
72+
var i = 1;
73+
window.setInterval(function () {
74+
$.ajax({
75+
url: "http://127.0.0.1:8090/pmtab"
76+
,
77+
success: function (result) {
78+
for (var x = 0; x < metrics.length; x++) {
79+
dat[x].push(result[metrics[x]].Value);
80+
}
81+
chart.data.labels.push("");
82+
if (dat[0].length > 30) {
83+
dat.forEach(function (el) {
84+
el.shift();
85+
});
86+
chart.data.labels.shift();
87+
}
88+
chart.update();
89+
i++;
90+
}
91+
});
92+
}, 1000);
93+
});

0 commit comments

Comments
 (0)