File tree Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 1
1
name : hardware
2
- version : 0.2.0
2
+ version : 0.2.1
3
3
4
4
authors :
5
5
Original file line number Diff line number Diff line change @@ -6,6 +6,6 @@ describe Hardware::CPU do
6
6
end
7
7
8
8
it " checks the percentage used" do
9
- (0 < Hardware ::CPU .used <= 100 ).should be_true
9
+ (0 <= Hardware ::CPU .used <= 100 ).should be_true
10
10
end
11
11
end
Original file line number Diff line number Diff line change 1
1
require " ./hardware/*"
2
2
3
3
module Hardware
4
- VERSION = " 0.2.0 "
4
+ VERSION = " 0.2.1 "
5
5
end
Original file line number Diff line number Diff line change 1
1
module Hardware::CPU
2
2
def self.info
3
3
cpu = File .read(" /proc/stat" ).lines.first[5 ..- 1 ].split(' ' ).map & .to_i
4
+ # Array: user nice system idle iowait irq softirq steal guest guest_nice
4
5
{
5
- used: cpu[0 ] + cpu[1 ] + cpu[2 ],
6
- idle: cpu[3 ],
7
- total: cpu[ 0 ] + cpu[ 1 ] + cpu[ 2 ] + cpu[ 3 ] ,
6
+ used: used = cpu[0 ] + cpu[1 ] + cpu[2 ] + cpu[ 5 ] + cpu[ 6 ] + cpu[ 7 ],
7
+ idle: idle = cpu[3 ] + cpu[ 4 ],
8
+ total: used + idle ,
8
9
}
9
10
end
10
11
@@ -14,6 +15,6 @@ module Hardware::CPU
14
15
proc1 = info
15
16
16
17
# 100 * Usage / Total
17
- 100 * ((proc1[:used ] - proc0[:used ]).to_f32 / (proc1[:total ] - proc0[:total ]).to_f32)
18
+ ( 100 * ((proc1[:used ] - proc0[:used ]).to_f32 / (proc1[:total ] - proc0[:total ]))).round
18
19
end
19
20
end
You can’t perform that action at this time.
0 commit comments