Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit e0f759a

Browse files
committed
mod_cpuinfo
1 parent 0936c89 commit e0f759a

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

src/assets/css/mod_cpuinfo.css

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
div#mod_cpuinfo {
2+
border-top: 1px solid rgba(190, 230, 193, 0.3);
3+
font-family: var(--font_main_light);
4+
letter-spacing: 1px;
5+
padding: 7px 0px;
6+
display: flex;
7+
}
8+
9+
div#mod_cpuinfo::before {
10+
content: "";
11+
border-left: 1px solid rgba(190, 230, 193, 0.3);
12+
align-self: flex-start;
13+
position: relative;
14+
left: -1px;
15+
top: -12px;
16+
height: 9px;
17+
}
18+
19+
div#mod_cpuinfo::after {
20+
content: "";
21+
border-right: 1px solid rgba(190, 230, 193, 0.3);
22+
position: relative;
23+
right: -1px;
24+
top: -12px;
25+
height: 9px;
26+
}
27+
28+
div#mod_cpuinfo > div#mod_cpuinfo_innercontainer {
29+
display: flex;
30+
flex-direction: column;
31+
align-items: center;
32+
justify-content: space-between;
33+
width: 100%;
34+
}
35+
36+
div#mod_cpuinfo > div > div {
37+
display: flex;
38+
flex-direction: row;
39+
align-items: center;
40+
justify-content: space-between;
41+
width: 100%;
42+
margin: 3px 0px;
43+
}
44+
45+
div#mod_cpuinfo h1 {
46+
font-size: 16px;
47+
margin: 0px;
48+
}
49+
50+
div#mod_cpuinfo em {
51+
font-family: var(--font_main);
52+
font-style: normal;
53+
}
54+
55+
div#mod_cpuinfo span {
56+
width: 1em;
57+
position: relative;
58+
top: 4px;
59+
right: 3px;
60+
text-align: center;
61+
overflow: hidden;
62+
display: inline-block;
63+
}
64+
65+
div#mod_cpuinfo i {
66+
font-style: normal;
67+
font-size: 14px;
68+
opacity: 0.5;
69+
}
70+
71+
div#mod_cpuinfo canvas {
72+
width: 76%;
73+
height: 45px;
74+
border-top: 1px dashed rgba(190, 230, 193, 0.3);
75+
border-bottom: 1px dashed rgba(190, 230, 193, 0.3);
76+
margin: 5px 0px;
77+
}

src/classes/cpuinfo.class.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
class Cpuinfo {
2+
constructor(parentId) {
3+
if (!parentId) throw "Missing parameters";
4+
5+
this.si = require("systeminformation");
6+
7+
// Create initial DOM
8+
this.parent = document.getElementById(parentId);
9+
this.parent.innerHTML += `<div id="mod_cpuinfo">
10+
<div id="mod_cpuinfo_innercontainer"></div>
11+
</div>`;
12+
this.container = document.getElementById("mod_cpuinfo_innercontainer");
13+
14+
// Init Smoothie
15+
let TimeSeries = require("smoothie").TimeSeries;
16+
let SmoothieChart = require("smoothie").SmoothieChart;
17+
18+
this.series = [];
19+
this.charts = [];
20+
this.si.cpu((data) => {
21+
let createCoresDOM = () => {
22+
return new Promise((resolve, reject) => {
23+
let timeId = setTimeout(reject, 1000); // Fail after 1s
24+
for (var i = 0; i < data.cores; i++) {
25+
// Create DOM
26+
this.container.innerHTML += `<div>
27+
<h1>CORE <em>#<span>${i}</span></em><br><i>% USED</i></h1>
28+
<canvas id="mod_cpuinfo_canvas_${i}" height="60"></canvas>
29+
</div>`;
30+
31+
if (i === data.cores-1) {
32+
clearTimeout(timeId); // Clear fail timer
33+
resolve(true);
34+
}
35+
}
36+
});
37+
};
38+
async function waitForCoresDOM() {
39+
let result = createCoresDOM();
40+
return await result;
41+
}
42+
waitForCoresDOM().then(() => {
43+
for (var i = 0; i < data.cores; i++) {
44+
// Create TimeSeries
45+
this.series.push(new TimeSeries());
46+
47+
// Create charts
48+
let serie = this.series[i];
49+
let chart = new SmoothieChart({
50+
limitFPS: 30,
51+
responsive: true,
52+
millisPerPixel: 50,
53+
grid:{
54+
fillStyle:'transparent',
55+
strokeStyle:'transparent',
56+
verticalSections:0,
57+
borderVisible:false
58+
},
59+
labels:{
60+
disabled: true
61+
},
62+
yRangeFunction: () => {
63+
return {min:0,max:100};
64+
}
65+
});
66+
67+
chart.addTimeSeries(serie, {lineWidth:1.7,strokeStyle:'#bee6c1'});
68+
chart.streamTo(document.getElementById(`mod_cpuinfo_canvas_${i}`), 500);
69+
70+
this.charts.push(chart);
71+
}
72+
73+
// Init updater
74+
this.updateInfo();
75+
this.infoUpdater = setInterval(() => {
76+
this.updateInfo();
77+
}, 500);
78+
}, () => {
79+
console.error("[mod_cpuinfo]: Error when creating DOM.");
80+
});
81+
});
82+
}
83+
updateInfo() {
84+
this.si.currentLoad((data) => {
85+
data.cpus.forEach((e, i) => {
86+
this.series[i].append(new Date().getTime(), e.load);
87+
});
88+
});
89+
}
90+
}
91+
92+
module.exports = {
93+
Cpuinfo
94+
};

0 commit comments

Comments
 (0)