-
Notifications
You must be signed in to change notification settings - Fork 10
/
sensors.js
121 lines (115 loc) · 4.43 KB
/
sensors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var init = false;
function sensors_on_load() {
setInterval(get_sensors, 1000);
get_sensors();
}
function get_sensors() {
var proc = cockpit.spawn(["sensors", "-u"]);
proc.stream(sensors_output);
}
function sensors_output(data) {
var table = document.getElementById("sensors-table");
var current_adaptor = null;
var current_cpu = 0;
var current_gpu = 0;
var current_core = null;
var lines = data.split('\n');
for (var i = 0;i < lines.length;i++){
if (current_adaptor == null) {
if (lines[i].startsWith('coretemp')) {
current_adaptor = 'CPU' + parseInt(lines[i].split('-').pop())
if (init == false) {
var row = table.insertRow(-1);
var header = document.createElement("TH");
header.innerHTML = current_adaptor;
header.colSpan = "4";
row.append(header);
var row = table.insertRow(-1);
row.innerHTML = "<td></td><td>Current</td><td>Max.</td><td>Crit.</td>";
}
} else if (lines[i].startsWith('k10temp')) {
current_adaptor = 'CPU' + current_cpu;
if (init == false) {
var row = table.insertRow(-1);
var header = document.createElement("TH");
header.innerHTML = current_adaptor;
header.colSpan = "4";
row.append(header);
var row = table.insertRow(-1);
row.innerHTML = "<td></td><td>Current</td><td>Max.</td><td>Crit.</td>";
}
} else if (lines[i].startsWith('radeon')) {
current_adaptor = 'GPU' + current_gpu;
if (init == false) {
var row = table.insertRow(-1);
var header = document.createElement("TH");
header.innerHTML = current_adaptor;
header.colSpan = "4";
row.append(header);
var row = table.insertRow(-1);
row.innerHTML = "<td></td><td>Current</td><td>Max.</td><td>Crit.</td>";
}
} else if (lines[i].startsWith('cpu_thermal-virtual-0')) {
current_adaptor = 'temp' + current_cpu;
if (init == false) {
var row = table.insertRow(-1);
var header = document.createElement("TH");
header.innerHTML = current_adaptor;
header.colSpan = "4";
row.append(header);
var row = table.insertRow(-1);
row.innerHTML = "<td></td><td>Current</td><td>Max.</td><td>Crit.</td>";
}
}
} else if (lines[i] == '') {
current_adaptor = null;
current_core = null;
} else {
if (current_adaptor != null) {
if (lines[i].startsWith('Core') || lines[i].startsWith('temp')) {
current_core = lines[i].replace(':', '');
if (init == false) {
var row = table.insertRow(-1);
var name = row.insertCell(-1);
name.innerHTML = current_core
var temp_current = row.insertCell(-1);
temp_current.id = current_adaptor + '-' + current_core + '-current';
var temp_max = row.insertCell(-1);
temp_max.id = current_adaptor + '-' + current_core + '-max';
var temp_crit = row.insertCell(-1);
temp_crit.id = current_adaptor + '-' + current_core + '-crit';
}
} else if (lines[i].startsWith(" ") && current_core != null) {
var bits = lines[i].split(":");
var id = current_adaptor + '-' + current_core + '-current';
var temp_current = document.getElementById(id);
id = current_adaptor + '-' + current_core + '-max';
var temp_max = document.getElementById(id);
id = current_adaptor + '-' + current_core + '-crit';
var temp_crit = document.getElementById(id);
id = null;
if (bits[0].endsWith('input')) {
id = current_adaptor + '-' + current_core + '-current';
} else if (bits[0].endsWith('max')) {
id = current_adaptor + '-' + current_core + '-max';
} else if (bits[0].endsWith('crit')) {
id = current_adaptor + '-' + current_core + '-crit';
}
if (id != null) {
var elem = document.getElementById(id);
elem.innerHTML = bits[1];
}
if (parseFloat(temp_current.innerHTML) >= parseFloat(temp_crit.innerHTML)) {
temp_current.className = "crit";
} else if (parseFloat(temp_current.innerHTML) >= parseFloat(temp_max.innerHTML)) {
temp_current.className = "max";
} else {
temp_current.className = "";
}
}
}
}
}
init = true;
}
document.addEventListener('DOMContentLoaded', sensors_on_load)