skinny_jeans 0.2.3 → 0.3.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.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ http://img696.imageshack.us/img696/75/skinnys3.jpg
10
10
  0.0.0.0 - - [01/Oct/2010:00:00:03 -0700] "GET /posts/my-first-post HTTP/1.1" 200 1337 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "-"
11
11
  0.0.0.0 - - [02/Oct/2010:00:00:03 -0700] "GET /posts/my-first-post HTTP/1.1" 200 1337 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "-"
12
12
 
13
- * then you get 2 SQL rows that looks like:
13
+ * then you get 2 SQL rows that look like:
14
14
  2010-10-01, my-first-post, 3
15
15
  2010-10-02, my-first-post, 1
16
16
  * note the date columns truncate timestamp, so the days are in whatever timezone your log file reports in
@@ -25,7 +25,7 @@ http://img696.imageshack.us/img696/75/skinnys3.jpg
25
25
  sj = SkinnyJeans::execute(logfile_path = "access.log", sqlite_skinny_jeans = "sqlite_skinny_jeans.db", path_regexp = /\s\/posts\/(.*)\sHTTP/, date_regexp = /\[(\d.*\d)\]/)
26
26
  sj.pageview.where("date = '2010-10-01' and path = 'my-first-post'")
27
27
  => #<SkinnyJeans::Pageview id: 1, date: "2010-10-01", path: "my-first-post", pageview_count: 3>
28
- 1. NOTE: for now *you have to monkey patch the SkinnyJeans#parse_string_as_date*
28
+ 1. NOTE: for now **you have to monkey patch the SkinnyJeans#parse_string_as_date**
29
29
  2. Parse oldest logs first, then run regularly against your main log, let logrotate handle the rest (skinny_jeans remembers where it left off)
30
30
  3. ASSUMES reading log files in ascending order, keeps track of last line read so you could put it on a scheduler or cron job
31
31
  4. access the 2 activerecord classes, sj.pageview (returns Pageview class), and sj.update
@@ -34,4 +34,9 @@ http://img696.imageshack.us/img696/75/skinnys3.jpg
34
34
 
35
35
  == PERFORMANCE
36
36
  * it parses 100,000 lines in < 2.5 seconds
37
- * persists 1,000 requests with 2 compound indexes in 15 seconds, or 10 seconds with home_run c extension
37
+ * persists 1,000 requests with 2 compound indexes in 15 seconds, or 10 seconds with home_run c extension
38
+ * 25,000 rows == 4 megabyte sqlite database
39
+
40
+ == NOTES
41
+ * supports gzipped files
42
+ * creates a temp copy of the log file before parsing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
data/lib/skinny_jeans.rb CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'sqlite3'
5
5
  require 'active_record'
6
6
  require 'zlib'
7
+ require 'fileutils'
7
8
  # require 'home_run'
8
9
 
9
10
  class SkinnyJeans
@@ -113,14 +114,21 @@ class SkinnyJeans
113
114
 
114
115
  end
115
116
 
117
+ # copies the log file, reads it, then removes it
116
118
  def file_reader
119
+
120
+ temp_file_path = "#{@logfile_path}.copy"
121
+ temp_file = FileUtils.cp(@logfile_path, temp_file_path)
122
+
117
123
  if @is_gzipped
118
124
  lineno = 0
119
- Zlib::GzipReader.new(File.new(@logfile_path, "r")).each_line{|line|yield([line,lineno]);lineno+=1}
125
+ Zlib::GzipReader.new(File.new(temp_file_path, "r")).each_line{|line|yield([line,lineno]);lineno+=1}
120
126
  # Zlib::GzipReader.open(@logfile_path).each_line{|line|yield([line,lineno]);lineno+=1}
121
127
  else
122
- File.new(@logfile_path, "r").each_with_index{|line, lineno| yield([line,lineno])}
128
+ File.new(temp_file_path, "r").each_with_index{|line, lineno| yield([line,lineno])}
123
129
  end
130
+
131
+ FileUtils.rm_f(temp_file_path)
124
132
  end
125
133
 
126
134
  def pageview;get_ar_class(Pageview);end
data/skinny_jeans.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{skinny_jeans}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jonathan Otto"]
12
- s.date = %q{2010-10-04}
12
+ s.date = %q{2010-10-05}
13
13
  s.email = %q{jonathan.otto@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skinny_jeans
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Otto
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-04 00:00:00 -05:00
18
+ date: 2010-10-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency