Browse code

Cpu mod: fetch cpu load

Cinan Rakosnik authored on 15/12/2012 at 23:55:36
Showing 2 changed files
... ...
@@ -8,6 +8,8 @@ module Rubysermon
8 8
 			@cpu_count = File.readlines("/proc/stat").select { |line|
9 9
 				line =~ /^cpu[\d]/
10 10
 			}.length
11
+
12
+			@load = 0
11 13
 		end
12 14
 
13 15
 		def load_options
... ...
@@ -15,7 +17,7 @@ module Rubysermon
15 15
 		end
16 16
 
17 17
 		def results
18
-
18
+			@load = File.read("/proc/loadavg").split(" ").first.to_s
19 19
 		end
20 20
 
21 21
 		def notify?
... ...
@@ -15,4 +15,7 @@ class Cpu_test < MiniTest::Unit::TestCase
15 15
 		assert_match(/^CPU Load In Time \(CPUs: [\d]+\)$/, @cpu.graph_name)
16 16
 	end
17 17
 
18
+	def test_cpu_load
19
+		assert_match(/^\d\.\d{2}$/, @cpu.results())
20
+	end
18 21
 end
19 22
\ No newline at end of file