appstats 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/appstats/log_collector.rb +4 -2
- data/lib/appstats/tasks.rb +0 -1
- data/lib/appstats/version.rb +1 -1
- data/lib/daemons/appstats_log_collector +0 -0
- data/lib/daemons/appstats_log_collector.rb +0 -0
- data/lib/daemons/appstats_log_collector_ctl +2 -0
- data/spec/entry_spec.rb +4 -4
- data/spec/log_collector_spec.rb +20 -8
- data/spec/logger_spec.rb +16 -16
- metadata +5 -5
data/Gemfile.lock
CHANGED
@@ -15,7 +15,7 @@ module Appstats
|
|
15
15
|
begin
|
16
16
|
Appstats.log(:info,"Looking for logs in [#{remote_login[:user]}@#{remote_login[:host]}:#{path}] labelled [#{log_template}]")
|
17
17
|
Net::SSH.start(remote_login[:host], remote_login[:user], :password => remote_login[:password] ) do |ssh|
|
18
|
-
all_files = ssh.exec!("cd #{path} && ls | grep #{log_template}").split
|
18
|
+
all_files = ssh.exec!("cd #{path} && ls -tr | grep #{log_template}").split
|
19
19
|
load_remote_files(remote_login,path,all_files)
|
20
20
|
end
|
21
21
|
rescue Exception => e
|
@@ -35,7 +35,9 @@ module Appstats
|
|
35
35
|
Appstats.log(:info, "About to analyze #{all_files.size} file(s).")
|
36
36
|
all_files.each do |log_name|
|
37
37
|
filename = File.join(path,log_name)
|
38
|
-
if
|
38
|
+
if !log_name.match("(.*)#{Time.now.strftime('%Y-%m-%d')}.log").nil?
|
39
|
+
Appstats.log(:info, " - IGNORING CURRENT LOG FILE #{remote_login[:user]}@#{remote_login[:host]}:#{filename}")
|
40
|
+
elsif LogCollector.find_by_host_and_filename(remote_login[:host],filename).nil?
|
39
41
|
log_collector = LogCollector.create(:host => remote_login[:host], :filename => filename, :status => "unprocessed")
|
40
42
|
Appstats.log(:info, " - #{remote_login[:user]}@#{remote_login[:host]}:#{filename}")
|
41
43
|
count += 1
|
data/lib/appstats/tasks.rb
CHANGED
data/lib/appstats/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -9,6 +9,8 @@ gem 'activerecord', '>=3.0.0.beta4'
|
|
9
9
|
require 'active_support'
|
10
10
|
require 'active_record'
|
11
11
|
|
12
|
+
require File.dirname(__FILE__) + "/../appstats.rb"
|
13
|
+
|
12
14
|
# For some reason, ActiveSupport 3.0.0 doesn't load.
|
13
15
|
# Load needed extension directly for now.
|
14
16
|
require "active_support/core_ext/object"
|
data/spec/entry_spec.rb
CHANGED
@@ -143,18 +143,18 @@ module Appstats
|
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should understand an entry without contexts" do
|
146
|
-
entry = Entry.load_from_logger_entry("0.0.
|
146
|
+
entry = Entry.load_from_logger_entry("0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
147
147
|
Entry.count.should == @before_count + 1
|
148
148
|
entry.action.should == "address_search"
|
149
|
-
entry.raw_entry.should == "0.0.
|
149
|
+
entry.raw_entry.should == "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
150
150
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should understand contexts" do
|
154
|
-
entry = Entry.load_from_logger_entry("0.0.
|
154
|
+
entry = Entry.load_from_logger_entry("0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
155
155
|
Entry.count.should == @before_count + 1
|
156
156
|
entry.action.should == "address_filter"
|
157
|
-
entry.raw_entry.should == "0.0.
|
157
|
+
entry.raw_entry.should == "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
158
158
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
159
159
|
entry.contexts.size.should == 2
|
160
160
|
entry.contexts[0].context_key = "app_name"
|
data/spec/log_collector_spec.rb
CHANGED
@@ -4,6 +4,9 @@ module Appstats
|
|
4
4
|
describe LogCollector do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
+
@time = Time.parse('2010-01-03 10:20:30')
|
8
|
+
Time.stub!(:now).and_return(@time)
|
9
|
+
|
7
10
|
LogCollector.delete_all
|
8
11
|
@log_collector = Appstats::LogCollector.new
|
9
12
|
@login = { :host => "myhost.localnet", :user => "deployer", :password => "pass" }
|
@@ -53,12 +56,13 @@ module Appstats
|
|
53
56
|
it "should log all transactions" do
|
54
57
|
ssh = mock(Net::SSH)
|
55
58
|
Net::SSH.should_receive(:start).with("myhost.localnet","deployer",{ :password => "pass"}).and_yield(ssh)
|
56
|
-
ssh.should_receive(:exec!).with("cd /my/path/log && ls | grep mystats").and_return("
|
57
|
-
|
59
|
+
ssh.should_receive(:exec!).with("cd /my/path/log && ls -tr | grep mystats").and_return("mystats_2010-01-01.log\nmystats_2010-01-02.log\nmystats_2010-01-03.log")
|
60
|
+
|
58
61
|
Appstats.should_receive(:log).with(:info, "Looking for logs in [deployer@myhost.localnet:/my/path/log] labelled [mystats]")
|
59
|
-
Appstats.should_receive(:log).with(:info, "About to analyze
|
60
|
-
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/
|
61
|
-
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/
|
62
|
+
Appstats.should_receive(:log).with(:info, "About to analyze 3 file(s).")
|
63
|
+
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/mystats_2010-01-01.log")
|
64
|
+
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/mystats_2010-01-02.log")
|
65
|
+
Appstats.should_receive(:log).with(:info, " - IGNORING CURRENT LOG FILE deployer@myhost.localnet:/my/path/log/mystats_2010-01-03.log")
|
62
66
|
Appstats.should_receive(:log).with(:info, "Loaded 2 file(s).")
|
63
67
|
LogCollector.find_remote_files(@login,"/my/path/log","mystats").should == 2
|
64
68
|
end
|
@@ -66,14 +70,14 @@ module Appstats
|
|
66
70
|
it "should talk to remote server" do
|
67
71
|
ssh = mock(Net::SSH)
|
68
72
|
Net::SSH.should_receive(:start).with("myhost.localnet","deployer",{ :password => "pass"}).and_yield(ssh)
|
69
|
-
ssh.should_receive(:exec!).with("cd /my/path/log && ls | grep mystats").and_return("
|
73
|
+
ssh.should_receive(:exec!).with("cd /my/path/log && ls -tr | grep mystats").and_return("mystats_2010-01-01.log\nmystats_2010-01-02.log")
|
70
74
|
|
71
75
|
LogCollector.find_remote_files(@login,"/my/path/log","mystats").should == 2
|
72
76
|
LogCollector.count.should == @before_count + 2
|
73
77
|
|
74
78
|
log_collector = LogCollector.last
|
75
79
|
log_collector.host.should == "myhost.localnet"
|
76
|
-
log_collector.filename.should == "/my/path/log/
|
80
|
+
log_collector.filename.should == "/my/path/log/mystats_2010-01-02.log"
|
77
81
|
log_collector.status.should == "unprocessed"
|
78
82
|
end
|
79
83
|
|
@@ -98,7 +102,6 @@ module Appstats
|
|
98
102
|
Appstats.should_receive(:log).with(:info,"No remote logs to load.")
|
99
103
|
LogCollector.load_remote_files(@login,"/my/path/log",[]).should == 0
|
100
104
|
end
|
101
|
-
|
102
105
|
|
103
106
|
it "should log the files loaded" do
|
104
107
|
LogCollector.load_remote_files(@login,"/my/path/log",["app2"]).should == 1
|
@@ -110,6 +113,15 @@ module Appstats
|
|
110
113
|
Appstats.should_receive(:log).with(:info, "Loaded 2 file(s).")
|
111
114
|
LogCollector.load_remote_files(@login,"/my/path/log",["app1","app2","app3"]).should == 2
|
112
115
|
end
|
116
|
+
|
117
|
+
it "should ignore today's file" do
|
118
|
+
Appstats.should_receive(:log).with(:info, "About to analyze 3 file(s).")
|
119
|
+
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/app1")
|
120
|
+
Appstats.should_receive(:log).with(:info, " - deployer@myhost.localnet:/my/path/log/app2")
|
121
|
+
Appstats.should_receive(:log).with(:info, " - IGNORING CURRENT LOG FILE deployer@myhost.localnet:/my/path/log/app3_2010-01-03.log")
|
122
|
+
Appstats.should_receive(:log).with(:info, "Loaded 2 file(s).")
|
123
|
+
LogCollector.load_remote_files(@login,"/my/path/log",["app1","app2","app3_2010-01-03.log"]).should == 2
|
124
|
+
end
|
113
125
|
|
114
126
|
it "should create an unprocessed record per file" do
|
115
127
|
LogCollector.load_remote_files(@login,"/my/path/log",["app1","app2","app3"]).should == 3
|
data/spec/logger_spec.rb
CHANGED
@@ -127,29 +127,29 @@ module Appstats
|
|
127
127
|
|
128
128
|
it "should handle a statistics entry" do
|
129
129
|
expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
|
130
|
-
actual = Appstats::Logger.entry_to_hash("0.0.
|
130
|
+
actual = Appstats::Logger.entry_to_hash("0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
131
131
|
actual.should == expected
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should handle contexts" do
|
135
135
|
expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
|
136
|
-
actual = Appstats::Logger.entry_to_hash("0.0.
|
136
|
+
actual = Appstats::Logger.entry_to_hash("0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
137
137
|
actual.should == expected
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
141
141
|
expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
|
142
|
-
actual = Appstats::Logger.entry_to_hash("0.0.
|
142
|
+
actual = Appstats::Logger.entry_to_hash("0.0.15 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
|
143
143
|
actual.should == expected
|
144
144
|
|
145
145
|
expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
|
146
|
-
actual = Appstats::Logger.entry_to_hash("0.0.
|
146
|
+
actual = Appstats::Logger.entry_to_hash("0.0.15 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
|
147
147
|
actual.should == expected
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
151
151
|
expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
|
152
|
-
actual = Appstats::Logger.entry_to_hash("0.0.
|
152
|
+
actual = Appstats::Logger.entry_to_hash("0.0.15 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
|
153
153
|
actual.should == expected
|
154
154
|
end
|
155
155
|
|
@@ -158,66 +158,66 @@ module Appstats
|
|
158
158
|
describe "#entry_to_s" do
|
159
159
|
|
160
160
|
it "should handle a statistics entry" do
|
161
|
-
expected = "0.0.
|
161
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
162
162
|
actual = Appstats::Logger.entry_to_s("address_search")
|
163
163
|
actual.should == expected
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should handle numbers" do
|
167
|
-
expected = "0.0.
|
167
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
|
168
168
|
actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
|
169
169
|
actual.should == expected
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should handle default contexts" do
|
173
173
|
Appstats::Logger.default_contexts[:app_name] = "market"
|
174
|
-
expected = "0.0.
|
174
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
|
175
175
|
actual = Appstats::Logger.entry_to_s("address_search")
|
176
176
|
actual.should == expected
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should handle contexts (and sort them by symbol)" do
|
180
|
-
expected = "0.0.
|
180
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
181
181
|
actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
|
182
182
|
actual.should == expected
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
186
|
-
expected = "0.0.
|
186
|
+
expected = "0.0.15 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
|
187
187
|
actual = Appstats::Logger.entry_to_s("address:=search-n")
|
188
188
|
actual.should == expected
|
189
189
|
|
190
|
-
expected = "0.0.
|
190
|
+
expected = "0.0.15 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
|
191
191
|
actual = Appstats::Logger.entry_to_s("address::search==--n")
|
192
192
|
actual.should == expected
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
196
|
-
expected = "0.0.
|
196
|
+
expected = "0.0.15 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
|
197
197
|
actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
|
198
198
|
actual.should == expected
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should ignore spaces" do
|
202
|
-
expected = "0.0.
|
202
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
|
203
203
|
actual = Appstats::Logger.entry_to_s("address search")
|
204
204
|
actual.should == expected
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should convert newlines in action" do
|
208
|
-
expected = "0.0.
|
208
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
|
209
209
|
actual = Appstats::Logger.entry_to_s("address_\nsearch")
|
210
210
|
actual.should == expected
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should convert newlines in context" do
|
214
|
-
expected = "0.0.
|
214
|
+
expected = "0.0.15 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
|
215
215
|
actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
|
216
216
|
actual.should == expected
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should convert newlines based on the delimiter" do
|
220
|
-
expected = "0.0.
|
220
|
+
expected = "0.0.15 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
|
221
221
|
actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
|
222
222
|
actual.should == expected
|
223
223
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-07 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
requirements: []
|
208
208
|
|
209
209
|
rubyforge_project:
|
210
|
-
rubygems_version: 1.
|
210
|
+
rubygems_version: 1.5.0
|
211
211
|
signing_key:
|
212
212
|
specification_version: 3
|
213
213
|
summary: Provide usage statistics about how your application is being used
|