-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo.js
More file actions
34 lines (28 loc) · 1.02 KB
/
sysinfo.js
File metadata and controls
34 lines (28 loc) · 1.02 KB
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
const update_delay = 2500; // in milliseconds
const api_endpoint = "https://psibien.dev/api/sysinfo";
var fetch_data = true;
// fetch API endpoint and populate content
async function updateTemp() {
if (fetch_data) {
const res = await fetch(`${api_endpoint}?ts=${Date.now()}`);
const data = await res.json();
temp.textContent = data.cpu_temp.toFixed(2) + "°C";
disk.textContent = data.disk.percent.toFixed(1) + "%";
mem.textContent = data.memory.percent.toFixed(1) + "%";
uptime.textContent = formatUptime(data.uptime_sec);
}
}
setInterval(updateTemp, update_delay);
// format seconds to proper time
function formatUptime(seconds) {
const days = Math.floor(seconds / 86400);
seconds %= 86400;
const hours = Math.floor(seconds / 3600);
seconds %= 3600;
const minutes = Math.floor(seconds / 60);
let str = "";
if (days) str += `${days}d`;
if (hours) str += `${hours}h`;
if (minutes || (!days && !hours)) str += `${minutes}m`;
return str;
}