Browse code

Logging output

Cinan Rakosnik authored on 17/12/2012 at 02:56:38
Showing 3 changed files
... ...
@@ -3,6 +3,7 @@ require_relative "rubysermon/mod_loader"
3 3
 require_relative "rubysermon/mod_template"
4 4
 require_relative "rubysermon/configurator"
5 5
 require_relative "rubysermon/db"
6
+require_relative "rubysermon/output_driver_template"
6 7
 
7 8
 require "date"
8 9
 
... ...
@@ -12,17 +13,23 @@ module Rubysermon
12 12
 	MOD_PATH = "#{LIB_PATH}/rubysermon/mod"
13 13
 
14 14
 	class App
15
+
16
+		#todo: refactor
15 17
 		def initialize
16 18
 			@config 		= { repeat: 60,
17 19
 								config_path: "#{LIB_PATH}/rubysermon/config.json",
18 20
 								db_path: "/tmp/rubysermon_history.db",
19
-								history_size: 90
21
+								history_size: 90,
22
+								output: "Dummy"
20 23
 			}
21 24
 
22 25
 			@running_mods	= []
23 26
 			@enabled_mods	= []
24 27
 			@db				= nil
25 28
 
29
+			require "#{LIB_PATH}/rubysermon/output_drivers/#{@config[:output].downcase}"
30
+			@output_driver	= (Rubysermon.const_get(@config[:output])).new
31
+
26 32
 			@results		= []
27 33
 
28 34
 			check_args()
... ...
@@ -101,6 +108,7 @@ module Rubysermon
101 101
 		end
102 102
 
103 103
 		def save_results(mod, time, result)
104
+			#results should be specialized object
104 105
 			mod_results = @results[mod]
105 106
 
106 107
 			if mod_results.size >= @config[:history_size]
... ...
@@ -117,7 +125,9 @@ module Rubysermon
117 117
 		end
118 118
 
119 119
 		def make_output
120
-
120
+			@results.each do |mod, mod_results|
121
+				@output_driver.log(mod, mod_results)
122
+			end
121 123
 		end
122 124
 	end
123 125
 end
124 126
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+{
1
+  "modules" : [
2
+    "cpu"
3
+  ],
4
+
5
+  "refresh": 2
6
+}
0 7
\ No newline at end of file
... ...
@@ -62,4 +62,22 @@ class Rubysermon_test < MiniTest::Unit::TestCase
62 62
 
63 63
 		assert_equal("Wrong config file path. Exiting.", exception.message)
64 64
 	end
65
+
66
+	def test_results_cpu
67
+		skip("Use thread instead of sleep")
68
+		#depends on cpu module
69
+
70
+		ARGV[0] = "#{TEST_PATH}/fixtures/dummy_results.json"
71
+		@app = Rubysermon::App.new
72
+
73
+
74
+		thread = Thread.new do
75
+			@app.run()
76
+		end
77
+
78
+		sleep(2)
79
+		thread.kill()
80
+
81
+		#todo check stdout
82
+	end
65 83
 end
66 84
\ No newline at end of file