-
Notifications
You must be signed in to change notification settings - Fork 41
/
load.jsx
40 lines (35 loc) · 1.05 KB
/
load.jsx
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
const command = 'sysctl -n vm.loadavg hw.ncpu';
const refreshFrequency = 10000
const render = ({output, error}) => {
if (output.length === 0) {
return false;
}
output = output.split('\n');
const ncpu = parseInt(output[1], 10);
const load = output[0].replace('{ ', '').replace(' }', '').split(' ');
const load_class = [
{ ['class']: getClass(load[0], ncpu) },
{ ['class']: getClass(load[1], ncpu) },
{ ['class']: getClass(load[2], ncpu) },
];
return (
<div class='screen'>
<div class="pecanload">
◇ <span { ...load_class[0] }>{load[0]} </span>
<span { ...load_class[1] }>{load[1]} </span>
<span { ...load_class[2] }>{load[2]}</span>
</div>
</div>
)
};
const getClass = (load, ncpu) => {
console.log(load, ncpu);
if (load >= ncpu) {
return 'heavy';
} else if (load >= ncpu / 2) {
return 'moderate';
} else {
return 'light';
}
};
export { command, refreshFrequency, render };