scout 5.8.8 → 5.8.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +4 -0
- data/lib/scout/streamer.rb +59 -30
- data/lib/scout/streamer_daemon.rb +7 -5
- data/lib/scout/version.rb +1 -1
- data/test/streamer_test.rb +60 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8225b7bb56901315cf31c6e6d4308b3d2102d60
|
4
|
+
data.tar.gz: e38d3ec3d1c97ddf4a06c1ae5e79c63c16e8fba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f338aa1e81174c811d63c08ab5f01c801b4d4ad9ab34b78762764ae937c7ef6bb5f2ae6ae0c9010c017081c416da96149269e1cb678e111a177c50f697b95d3
|
7
|
+
data.tar.gz: 915f66476f32bc8fd1f3547861a5bbe764761c864988a78593dbcb7ff1724bea2b2ce1a46be2a12b234505656676fc947edc95b41f175c3aa3cef3b658e5eb87
|
data/CHANGELOG.markdown
CHANGED
data/lib/scout/streamer.rb
CHANGED
@@ -9,7 +9,7 @@ module Scout
|
|
9
9
|
|
10
10
|
# * history_file is the *path* to the history file
|
11
11
|
# * plugin_ids is an array of integers
|
12
|
-
def initialize(history_file, streaming_key, p_app_id, p_key, p_secret, plugin_ids, hostname, http_proxy, logger = nil)
|
12
|
+
def initialize(history_file, streaming_key, p_app_id, p_key, p_secret, plugin_ids, system_metric_collectors, hostname, http_proxy, logger = nil)
|
13
13
|
@@continue_streaming = true
|
14
14
|
@history_file = history_file
|
15
15
|
@history = Hash.new
|
@@ -42,40 +42,16 @@ module Scout
|
|
42
42
|
# main loop. Continue running until global $continue_streaming is set to false OR we've been running for MAX DURATION
|
43
43
|
iteration=1 # use this to log the data at a couple points
|
44
44
|
while(streamer_start_time+MAX_DURATION > Time.now && @@continue_streaming) do
|
45
|
-
plugins=
|
46
|
-
selected_plugins.each_with_index do |plugin_hash,i|
|
47
|
-
# create an actual instance of the plugin
|
48
|
-
plugin=get_instance_of(plugin_hash)
|
45
|
+
plugins = gather_plugin_reports(selected_plugins)
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
data = {}
|
53
|
-
begin
|
54
|
-
Timeout.timeout(30, PluginTimeoutError) do
|
55
|
-
data = plugin.run
|
56
|
-
end
|
57
|
-
rescue Timeout::Error, PluginTimeoutError
|
58
|
-
error "Plugin took too long to run."
|
59
|
-
end
|
60
|
-
|
61
|
-
duration=((Time.now-start_time)*1000).to_i
|
62
|
-
|
63
|
-
id_and_name = plugin_hash['id_and_name']
|
64
|
-
@history["last_runs"][id_and_name] = start_time
|
65
|
-
@history["memory"][id_and_name] = data[:memory]
|
66
|
-
|
67
|
-
plugins << {:duration=>duration,
|
68
|
-
:fields=>plugin.reports.inject{|memo,hash|memo.merge(hash)},
|
69
|
-
:name=>plugin_hash['name'],
|
70
|
-
:id=>plugin_hash['id'],
|
71
|
-
:class=>plugin_hash['code_class']}
|
72
|
-
end
|
47
|
+
system_metric_data = gather_system_metric_reports(system_metric_collectors)
|
73
48
|
|
74
49
|
bundle={:hostname=>hostname,
|
75
50
|
:server_time=>Time.now.strftime("%I:%M:%S %p"),
|
76
51
|
:server_unixtime => Time.now.to_i,
|
77
52
|
:num_processes=>`ps -e | wc -l`.chomp.to_i,
|
78
|
-
:plugins=>plugins
|
53
|
+
:plugins=>plugins,
|
54
|
+
:system_metrics => system_metric_data}
|
79
55
|
|
80
56
|
# stream the data via pusherapp
|
81
57
|
begin
|
@@ -104,6 +80,59 @@ module Scout
|
|
104
80
|
|
105
81
|
private
|
106
82
|
|
83
|
+
def gather_plugin_reports(selected_plugins)
|
84
|
+
plugins = []
|
85
|
+
selected_plugins.each_with_index do |plugin_hash, i|
|
86
|
+
# create an actual instance of the plugin
|
87
|
+
plugin = get_instance_of(plugin_hash)
|
88
|
+
start_time = Time.now
|
89
|
+
|
90
|
+
data = {}
|
91
|
+
begin
|
92
|
+
Timeout.timeout(30, PluginTimeoutError) do
|
93
|
+
data = plugin.run
|
94
|
+
end
|
95
|
+
rescue Timeout::Error, PluginTimeoutError
|
96
|
+
error "Plugin took too long to run."
|
97
|
+
end
|
98
|
+
duration = ((Time.now-start_time) * 1000).to_i
|
99
|
+
|
100
|
+
id_and_name = plugin_hash['id_and_name']
|
101
|
+
@history["last_runs"][id_and_name] = start_time
|
102
|
+
@history["memory"][id_and_name] = data[:memory]
|
103
|
+
|
104
|
+
plugins << { :duration => duration,
|
105
|
+
:fields => plugin.reports.inject{|memo,hash|memo.merge(hash)},
|
106
|
+
:name => plugin_hash['name'],
|
107
|
+
:id => plugin_hash['id'],
|
108
|
+
:class => plugin_hash['code_class'] }
|
109
|
+
end
|
110
|
+
plugins
|
111
|
+
end
|
112
|
+
|
113
|
+
def gather_system_metric_reports(system_metric_collectors)
|
114
|
+
system_metric_data = {}
|
115
|
+
all_collectors = { :disk => ServerMetrics::Disk,
|
116
|
+
:cpu => ServerMetrics::Cpu,
|
117
|
+
:memory => ServerMetrics::Memory,
|
118
|
+
:network => ServerMetrics::Network,
|
119
|
+
:process => ServerMetrics::Processes }
|
120
|
+
|
121
|
+
realtime_collectors = all_collectors.select { |key, klass| system_metric_collectors.include?(key) }
|
122
|
+
realtime_collectors.each_pair do |key, klass|
|
123
|
+
begin
|
124
|
+
collector_previous_run = @history[:server_metrics][key]
|
125
|
+
collector = collector_previous_run.is_a?(Hash) ? klass.from_hash(collector_previous_run) : klass.new() # continue with last run, or just create new
|
126
|
+
system_metric_data[key] = collector.run
|
127
|
+
@history[:server_metrics][key] = collector.to_hash # store its state for next time
|
128
|
+
rescue Exception => e
|
129
|
+
raise if e.is_a?(SystemExit)
|
130
|
+
error "Problem running server/#{key} metrics: #{e.message}: \n#{e.backtrace.join("\n")}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
system_metric_data
|
134
|
+
end
|
135
|
+
|
107
136
|
# Compile instances of the plugins specified in the passed plugin_ids
|
108
137
|
def compile_plugins(all_plugins,plugin_ids)
|
109
138
|
num_classes_compiled=0
|
@@ -199,4 +228,4 @@ module Scout
|
|
199
228
|
end
|
200
229
|
|
201
230
|
end
|
202
|
-
end
|
231
|
+
end
|
@@ -11,17 +11,19 @@ module Scout
|
|
11
11
|
:sync_log => true,
|
12
12
|
:working_dir => File.dirname(history_file)}
|
13
13
|
|
14
|
-
# streamer command might look like: start,A0000000000123,a,b,c,1,3
|
14
|
+
# streamer command might look like: start,A0000000000123,a,b,c,1,3,cpu,memory
|
15
15
|
tokens = streamer_command.split(",")
|
16
16
|
tokens.shift # gets rid of the "start"
|
17
17
|
streaming_key = tokens.shift
|
18
18
|
p_app_id = tokens.shift
|
19
19
|
p_key = tokens.shift
|
20
20
|
p_secret = tokens.shift
|
21
|
-
|
21
|
+
numerical_tokens = tokens.select { |token| token =~ /\A\d+\Z/ }
|
22
|
+
system_metric_collectors = (tokens - numerical_tokens).map(&:to_sym)
|
23
|
+
plugin_ids = numerical_tokens.map(&:to_i)
|
22
24
|
|
23
25
|
# we use STDOUT for the logger because daemon_spawn directs STDOUT to a log file
|
24
|
-
streamer_args = [history_file,streaming_key,p_app_id,p_key,p_secret,plugin_ids,hostname,http_proxy,Logger.new(STDOUT)]
|
26
|
+
streamer_args = [history_file,streaming_key,p_app_id,p_key,p_secret,plugin_ids,system_metric_collectors,hostname,http_proxy,Logger.new(STDOUT)]
|
25
27
|
if File.exists?(streamer_pid_file)
|
26
28
|
Scout::StreamerDaemon.restart(daemon_spawn_options, streamer_args)
|
27
29
|
else
|
@@ -45,8 +47,8 @@ module Scout
|
|
45
47
|
|
46
48
|
# this method is called by DaemonSpawn's class start method.
|
47
49
|
def start(streamer_args)
|
48
|
-
history,streaming_key,p_app_id,p_key,p_secret,plugin_ids,hostname,http_proxy,log = streamer_args
|
49
|
-
@scout = Scout::Streamer.new(history, streaming_key, p_app_id, p_key, p_secret, plugin_ids, hostname, http_proxy, log)
|
50
|
+
history,streaming_key,p_app_id,p_key,p_secret,plugin_ids,system_metric_collectors,hostname,http_proxy,log = streamer_args
|
51
|
+
@scout = Scout::Streamer.new(history, streaming_key, p_app_id, p_key, p_secret, plugin_ids, system_metric_collectors, hostname, http_proxy, log)
|
50
52
|
end
|
51
53
|
|
52
54
|
# this method is called by DaemonSpawn's class stop method.
|
data/lib/scout/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
begin
|
3
|
+
require 'pry'
|
4
|
+
rescue LoadError
|
5
|
+
# not using pry
|
6
|
+
end
|
7
|
+
# must be loaded after
|
8
|
+
$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
|
9
|
+
$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/..' )
|
10
|
+
require 'lib/scout'
|
11
|
+
require 'mocha/setup'
|
12
|
+
|
13
|
+
class StreamerTest < Test::Unit::TestCase
|
14
|
+
def test_reports_system_metrics
|
15
|
+
stub_history_file
|
16
|
+
plugin_ids_stub = []
|
17
|
+
system_metric_collectors = [:disk]
|
18
|
+
|
19
|
+
mock_pusher do
|
20
|
+
streamer = Scout::Streamer.new(:history_file_stub, :streaming_key_stub, :pusher_app_id_stub, :pusher_key_stub, :pusher_secret_stub, plugin_ids_stub, system_metric_collectors, :hostname_stub, :http_proxy_stub)
|
21
|
+
end
|
22
|
+
|
23
|
+
response = Pusher::Channel.streamer_data.first
|
24
|
+
assert_equal [:disk], response[:system_metrics].keys
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def stub_history_file
|
30
|
+
File.stubs(:read).with(:history_file_stub).returns(YAML.dump({:server_metrics => {}}))
|
31
|
+
File.stubs(:dirname).with(:history_file_stub).returns('tmp')
|
32
|
+
end
|
33
|
+
|
34
|
+
# this with a block to mock the pusher call. You can access the streamer data through the Pusher::Channel.streamer_data
|
35
|
+
# Must be called with a code block
|
36
|
+
def mock_pusher(num_runs=1)
|
37
|
+
# redefine the trigger! method, so the streamer doesn't loop indefinitely. We can't just mock it, because
|
38
|
+
# we need to set the $continue_streaming=false
|
39
|
+
$num_runs_for_mock_pusher=num_runs
|
40
|
+
Pusher::Channel.module_eval do
|
41
|
+
alias orig_trigger! trigger!
|
42
|
+
def self.streamer_data;@@streamer_data;end # for getting the data back out
|
43
|
+
def trigger!(event_name, data, socket=nil)
|
44
|
+
$num_run_for_tests = $num_run_for_tests ? $num_run_for_tests+1 : 1
|
45
|
+
@@streamer_data_temp ||= Array.new
|
46
|
+
@@streamer_data_temp << data
|
47
|
+
if $num_run_for_tests >= $num_runs_for_mock_pusher
|
48
|
+
Scout::Streamer.continue_streaming=false
|
49
|
+
$num_run_for_tests=nil
|
50
|
+
@@streamer_data = @@streamer_data_temp.clone
|
51
|
+
@@streamer_data_temp = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
yield # must be called with a block
|
56
|
+
Pusher::Channel.module_eval do
|
57
|
+
alias trigger! orig_trigger!
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.8.
|
4
|
+
version: 5.8.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Lewis
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- scout.gemspec
|
82
82
|
- test/plugins/disk_usage.rb
|
83
83
|
- test/scout_test.rb
|
84
|
+
- test/streamer_test.rb
|
84
85
|
- vendor/httpclient/README.txt
|
85
86
|
- vendor/httpclient/bin/httpclient
|
86
87
|
- vendor/httpclient/lib/hexdump.rb
|