appstats 0.0.16 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appstats (0.0.16)
4
+ appstats (0.1.0)
5
5
  daemons
6
6
  net-scp
7
7
  rails (>= 2.3.0)
@@ -0,0 +1,19 @@
1
+ class AddSeparatedEntryTimes < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :appstats_entries, :year, :int
4
+ add_column :appstats_entries, :month, :int
5
+ add_column :appstats_entries, :day, :int
6
+ add_column :appstats_entries, :hour, :int
7
+ add_column :appstats_entries, :minute, :int
8
+ add_column :appstats_entries, :second, :int
9
+ end
10
+
11
+ def self.down
12
+ remove_column :appstats_entries, :year
13
+ remove_column :appstats_entries, :month
14
+ remove_column :appstats_entries, :day
15
+ remove_column :appstats_entries, :hour
16
+ remove_column :appstats_entries, :minute
17
+ remove_column :appstats_entries, :second
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ class AddIndexes < ActiveRecord::Migration
2
+ def self.up
3
+ add_index :appstats_log_collectors, :host
4
+ add_index :appstats_entries, :action
5
+ add_index :appstats_entries, :year, :name => "index_entries_by_year"
6
+ add_index :appstats_entries, [:year,:month], :name => "index_entries_by_month"
7
+ add_index :appstats_entries, [:year,:month,:day], :name => "index_entries_by_day"
8
+ add_index :appstats_entries, [:year,:month,:day,:hour], :name => "index_entries_by_hour"
9
+ add_index :appstats_entries, [:year,:month,:day,:hour,:minute], :name => "index_entries_by_minute"
10
+ add_index :appstats_contexts, [:context_key,:context_value]
11
+ add_index :appstats_contexts, [:context_key,:context_int]
12
+ add_index :appstats_contexts, [:context_key,:context_float]
13
+ end
14
+
15
+ def self.down
16
+ remove_index :appstats_log_collectors, :host
17
+ remove_index :appstats_entries, :action
18
+ remove_index :appstats_entries, :name => "index_entries_by_year"
19
+ remove_index :appstats_entries, :name => "index_entries_by_month"
20
+ remove_index :appstats_entries, :name => "index_entries_by_day"
21
+ remove_index :appstats_entries, :name => "index_entries_by_hour"
22
+ remove_index :appstats_entries, :name => "index_entries_by_minute"
23
+ remove_index :appstats_contexts, [:context_key,:context_value]
24
+ remove_index :appstats_contexts, [:context_key,:context_int]
25
+ remove_index :appstats_contexts, [:context_key,:context_float]
26
+ end
27
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110204183259) do
13
+ ActiveRecord::Schema.define(:version => 20110207200431) do
14
14
 
15
15
  create_table "appstats_contexts", :force => true do |t|
16
16
  t.string "context_key"
@@ -22,6 +22,10 @@ ActiveRecord::Schema.define(:version => 20110204183259) do
22
22
  t.datetime "updated_at"
23
23
  end
24
24
 
25
+ add_index "appstats_contexts", ["context_key", "context_float"], :name => "index_appstats_contexts_on_context_key_and_context_float"
26
+ add_index "appstats_contexts", ["context_key", "context_int"], :name => "index_appstats_contexts_on_context_key_and_context_int"
27
+ add_index "appstats_contexts", ["context_key", "context_value"], :name => "index_appstats_contexts_on_context_key_and_context_value"
28
+
25
29
  create_table "appstats_entries", :force => true do |t|
26
30
  t.string "action"
27
31
  t.datetime "occurred_at"
@@ -29,8 +33,21 @@ ActiveRecord::Schema.define(:version => 20110204183259) do
29
33
  t.datetime "created_at"
30
34
  t.datetime "updated_at"
31
35
  t.integer "appstats_log_collector_id"
36
+ t.integer "year"
37
+ t.integer "month"
38
+ t.integer "day"
39
+ t.integer "hour"
40
+ t.integer "minute"
41
+ t.integer "second"
32
42
  end
33
43
 
44
+ add_index "appstats_entries", ["action"], :name => "index_appstats_entries_on_action"
45
+ add_index "appstats_entries", ["year", "month", "day", "hour", "minute"], :name => "index_entries_by_minute"
46
+ add_index "appstats_entries", ["year", "month", "day", "hour"], :name => "index_entries_by_hour"
47
+ add_index "appstats_entries", ["year", "month", "day"], :name => "index_entries_by_day"
48
+ add_index "appstats_entries", ["year", "month"], :name => "index_entries_by_month"
49
+ add_index "appstats_entries", ["year"], :name => "index_entries_by_year"
50
+
34
51
  create_table "appstats_log_collectors", :force => true do |t|
35
52
  t.string "host"
36
53
  t.string "filename"
@@ -39,4 +56,6 @@ ActiveRecord::Schema.define(:version => 20110204183259) do
39
56
  t.datetime "updated_at"
40
57
  end
41
58
 
59
+ add_index "appstats_log_collectors", ["host"], :name => "index_appstats_log_collectors_on_host"
60
+
42
61
  end
@@ -7,6 +7,27 @@ module Appstats
7
7
  belongs_to :log_collector, :foreign_key => "appstats_log_collector_id"
8
8
 
9
9
  attr_accessible :action, :occurred_at, :raw_entry
10
+
11
+ before_destroy :remove_dependencies
12
+
13
+ def occurred_at=(value)
14
+ self[:occurred_at] = value
15
+ if value.nil?
16
+ self[:year] = nil
17
+ self[:month] = nil
18
+ self[:day] = nil
19
+ self[:hour] = nil
20
+ self[:minute] = nil
21
+ self[:second] = nil
22
+ else
23
+ self[:year] = value.year
24
+ self[:month] = value.month
25
+ self[:day] = value.day
26
+ self[:hour] = value.hour
27
+ self[:minute] = value.min
28
+ self[:second] = value.sec
29
+ end
30
+ end
10
31
 
11
32
  def to_s
12
33
  return "No Entry" if action.nil? || action == ''
@@ -38,5 +59,14 @@ module Appstats
38
59
  entry
39
60
  end
40
61
 
62
+
63
+ private
64
+
65
+ def remove_dependencies
66
+ contexts.each do |context|
67
+ context.destroy
68
+ end
69
+ end
70
+
41
71
  end
42
72
  end
@@ -1,3 +1,3 @@
1
1
  module Appstats
2
- VERSION = "0.0.16"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -4,9 +4,16 @@ module Appstats
4
4
  describe Entry do
5
5
 
6
6
  before(:each) do
7
+ @before_count = Entry.count
8
+ Appstats::Logger.reset
7
9
  @time = Time.parse('2010-01-02 10:20:30')
8
- @entry = Appstats::Entry.new
9
10
  Time.stub!(:now).and_return(@time)
11
+
12
+ @entry = Appstats::Entry.new
13
+ end
14
+
15
+ after(:each) do
16
+ File.delete(Appstats::Logger.filename) if File.exists?(Appstats::Logger.filename)
10
17
  end
11
18
 
12
19
  describe "#initialize" do
@@ -32,6 +39,60 @@ module Appstats
32
39
 
33
40
  end
34
41
 
42
+ describe "#destroy" do
43
+
44
+ it "should remove itself" do
45
+ e = Entry.create
46
+ id = e.id
47
+ e.destroy
48
+ Entry.exists?(id).should == false
49
+ end
50
+
51
+ it "should remove all contexts" do
52
+ e = Entry.create
53
+ c = Context.new and c.entry = e and c.save.should == true
54
+
55
+ id1 = e.id
56
+ id2 = c.id
57
+
58
+ e.destroy
59
+
60
+ Entry.exists?(id1).should == false
61
+ Context.exists?(id2).should == false
62
+ end
63
+ end
64
+
65
+ describe "#occurred_at" do
66
+
67
+ it "should update the individual parts" do
68
+ entry = Appstats::Entry.new(:action => 'a', :occurred_at => Time.parse("2010-01-15 10:11:12"), :raw_entry => 'b')
69
+ entry.year.should == 2010
70
+ entry.month.should == 01
71
+ entry.day.should == 15
72
+ entry.hour.should == 10
73
+ entry.minute.should == 11
74
+ entry.second.should == 12
75
+
76
+ entry.occurred_at = Time.parse("2011-02-16 17:18:19")
77
+ entry.year.should == 2011
78
+ entry.month.should == 02
79
+ entry.day.should == 16
80
+ entry.hour.should == 17
81
+ entry.minute.should == 18
82
+ entry.second.should == 19
83
+
84
+ entry.occurred_at = nil
85
+ entry.year.should == nil
86
+ entry.month.should == nil
87
+ entry.day.should == nil
88
+ entry.hour.should == nil
89
+ entry.minute.should == nil
90
+ entry.second.should == nil
91
+
92
+ end
93
+
94
+ end
95
+
35
96
  describe "#contexts" do
36
97
 
37
98
  it "should have none by default" do
@@ -41,16 +102,18 @@ module Appstats
41
102
  it "should be able add contexts" do
42
103
  context = Appstats::Context.new(:context_key => 'a', :context_value => 'one')
43
104
  context.save.should == true
105
+ @entry.save.should == true
44
106
  @entry.contexts<< context
45
107
  @entry.save.should == true
46
108
  @entry.reload
47
109
  @entry.contexts.size.should == 1
48
110
  @entry.contexts[0].should == context
49
111
  end
50
-
112
+
51
113
  it "should alphabetize them" do
52
114
  zzz = Appstats::Context.create(:context_key => 'zzz', :context_value => 'one')
53
115
  aaa = Appstats::Context.create(:context_key => 'aaa', :context_value => 'one')
116
+ @entry.save.should == true
54
117
  @entry.contexts<< zzz
55
118
  @entry.contexts<< aaa
56
119
  @entry.save.should == true
@@ -62,10 +125,6 @@ module Appstats
62
125
 
63
126
  describe "#to_s" do
64
127
 
65
- before(:each) do
66
- @entry = Appstats::Entry.new
67
- end
68
-
69
128
  it "should return no entry if no action" do
70
129
  @entry.to_s.should == 'No Entry'
71
130
  @entry.action = ''
@@ -87,16 +146,6 @@ module Appstats
87
146
 
88
147
  describe "#load_from_logger_file" do
89
148
 
90
- before(:each) do
91
- @before_count = Entry.count
92
- Appstats::Logger.reset
93
- Time.stub!(:now).and_return(Time.parse('2010-09-21 23:15:20'))
94
- end
95
-
96
- after(:each) do
97
- File.delete(Appstats::Logger.filename) if File.exists?(Appstats::Logger.filename)
98
- end
99
-
100
149
  it "should handle nil" do
101
150
  Entry.load_from_logger_file(nil).should == false
102
151
  Entry.count.should == @before_count
@@ -112,24 +161,20 @@ module Appstats
112
161
  it "should handle appstat files" do
113
162
  Appstats::Logger.entry("test_action")
114
163
  Appstats::Logger.entry("another_test_action")
164
+ @before_count = Entry.count
115
165
  Entry.load_from_logger_file(Appstats::Logger.filename).should == true
116
166
  Entry.count.should == @before_count + 2
117
167
  Entry.last.action.should == "another_test_action"
118
168
  end
119
-
169
+
120
170
  end
121
171
 
122
-
123
172
  describe "#load_from_logger_entry" do
124
173
 
125
- before(:each) do
126
- @before_count = Entry.count
127
- end
128
-
129
174
  it "should handle nil" do
130
175
  Entry.load_from_logger_entry(nil).should == false
131
176
  Entry.count.should == @before_count
132
-
177
+
133
178
  Entry.load_from_logger_entry("").should == false
134
179
  Entry.count.should == @before_count
135
180
  end
@@ -143,18 +188,18 @@ module Appstats
143
188
  end
144
189
 
145
190
  it "should understand an entry without contexts" do
146
- entry = Entry.load_from_logger_entry("0.0.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
191
+ entry = Entry.load_from_logger_entry("0.1.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
147
192
  Entry.count.should == @before_count + 1
148
193
  entry.action.should == "address_search"
149
- entry.raw_entry.should == "0.0.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
194
+ entry.raw_entry.should == "0.1.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
150
195
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
151
196
  end
152
197
 
153
198
  it "should understand contexts" do
154
- entry = Entry.load_from_logger_entry("0.0.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
199
+ entry = Entry.load_from_logger_entry("0.1.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
155
200
  Entry.count.should == @before_count + 1
156
201
  entry.action.should == "address_filter"
157
- entry.raw_entry.should == "0.0.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
202
+ entry.raw_entry.should == "0.1.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
158
203
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
159
204
  entry.contexts.size.should == 2
160
205
  entry.contexts[0].context_key = "app_name"
@@ -164,26 +209,26 @@ module Appstats
164
209
  end
165
210
 
166
211
  end
167
-
168
- describe "#log_collector" do
169
-
170
- before(:each) do
171
- @log_collector = Appstats::LogCollector.new(:host => "a")
172
- @log_collector.save.should == true
173
- end
174
-
175
- it "should have a log_collector" do
176
- @entry.log_collector.should == nil
177
- @entry.log_collector = @log_collector
178
- @entry.save.should == true
179
- @entry.reload
180
- @entry.log_collector.should == @log_collector
181
-
182
- @entry = Entry.last
183
- @entry.log_collector.should == @log_collector
184
- end
185
-
186
- end
212
+
213
+ # describe "#log_collector" do
214
+ #
215
+ # before(:each) do
216
+ # @log_collector = Appstats::LogCollector.new(:host => "a")
217
+ # @log_collector.save.should == true
218
+ # end
219
+ #
220
+ # it "should have a log_collector" do
221
+ # @entry.log_collector.should == nil
222
+ # @entry.log_collector = @log_collector
223
+ # @entry.save.should == true
224
+ # @entry.reload
225
+ # @entry.log_collector.should == @log_collector
226
+ #
227
+ # @entry = Entry.last
228
+ # @entry.log_collector.should == @log_collector
229
+ # end
230
+ #
231
+ # end
187
232
 
188
233
  end
189
234
  end
@@ -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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
130
+ actual = Appstats::Logger.entry_to_hash("0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
136
+ actual = Appstats::Logger.entry_to_hash("0.1.0 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.16 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
142
+ actual = Appstats::Logger.entry_to_hash("0.1.0 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.16 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
146
+ actual = Appstats::Logger.entry_to_hash("0.1.0 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.16 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
152
+ actual = Appstats::Logger.entry_to_hash("0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
161
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
167
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
174
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
180
+ expected = "0.1.0 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.16 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
186
+ expected = "0.1.0 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.16 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
190
+ expected = "0.1.0 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.16 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
196
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
202
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
208
+ expected = "0.1.0 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.16 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
214
+ expected = "0.1.0 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.16 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
220
+ expected = "0.1.0 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: 63
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 16
10
- version: 0.0.16
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Forward
@@ -145,6 +145,8 @@ files:
145
145
  - db/migrations/20110203151136_create_appstats_contexts.rb
146
146
  - db/migrations/20110203151635_rework_appstats_entries.rb
147
147
  - db/migrations/20110204183259_create_log_collectors.rb
148
+ - db/migrations/20110207200324_add_separated_entry_times.rb
149
+ - db/migrations/20110207200431_add_indexes.rb
148
150
  - db/schema.rb
149
151
  - lib/appstats.rb
150
152
  - lib/appstats/code_injections.rb
@@ -154,7 +156,6 @@ files:
154
156
  - lib/appstats/logger.rb
155
157
  - lib/appstats/tasks.rb
156
158
  - lib/appstats/version.rb
157
- - lib/daemons/appstats_log_collector
158
159
  - lib/daemons/appstats_log_collector.rb
159
160
  - lib/daemons/appstats_log_collector_ctl
160
161
  - lib/templates/appstats_config.rb
File without changes