logfile_interval 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a422a1c2dd8f8e7f23f0383d0e136b092a759bb7
4
- data.tar.gz: a00233a4c5d418409adebb04192f2ece523afd17
3
+ metadata.gz: 417b2ac31812737e3157b7f96c59d60e9923aaf7
4
+ data.tar.gz: 4cd82aa72b77e206073e2bbac761017efa6f849b
5
5
  SHA512:
6
- metadata.gz: 10ae89ce0a1634f7cb7f3dd12c9b729cf9b3423a69d6493ec61a185681adbcc5257422c2d9ca02ed353f34d67ec76e244042f1d984dcba0a826c74370f94c9c6
7
- data.tar.gz: 3795d4971b016b9b5101f387d8fd7ee4dcb9e6551631f100cc7cbb22e49444622826ee8e594102f12fd588f3136f10281379a6f382452bad38f4b6d5b608b3ba
6
+ metadata.gz: 69445364975c36a7b0f96b78303f7fab0b95ad4bc8cda51b9501c91e5985c4bf5c8b7beecff87b4481e4b6e7e7a4024964afdf77ed58dabcfcf51b9b2f8602db
7
+ data.tar.gz: f16e7acf7e9b95471775763977eb775d75d9c32482599b0d519836e9fc1f5c162ee97bb18529db28bc695a514b8a15c036172dc8900bf4745b8d19bdff4f38d8
data/README.md CHANGED
@@ -22,7 +22,7 @@ require 'pp'
22
22
  require 'date'
23
23
  require 'logfile_interval'
24
24
 
25
- class AccessLog < LogfileInterval::LineParser::Base
25
+ class AccessLog < LogfileInterval::ParsedLine::Base
26
26
  # Example line:
27
27
  # 74.75.19.145 - - [31/Mar/2013:06:54:12 -0700] "GET /ppa/google_chrome HTTP/1.1" 200 7855 "https://www.google.com/" "Mozilla/5.0 Chrome/25.0.1364.160"
28
28
 
@@ -84,25 +84,21 @@ for each ip, number of requests grouped by http code:
84
84
  ### Write a LineParser class
85
85
  The first step is to define a LineParser class as in the example above. The parser lists the fields that must be parsed, how a timestamp can be extracted from each line and how to aggregate values into intervals.
86
86
  ```ruby
87
- module LogfileInterval
88
- module LineParser
89
- class AccessLog < Base
90
- # Example line:
91
- # 74.75.19.145 - - [31/Mar/2013:06:54:12 -0700] "GET /ppa/google_chrome HTTP/1.1" 200 7855 "https://www.google.com/" "Mozilla/5.0 Chrome/25.0.1364.160"
92
-
93
- set_regex /^([\d\.]+)\s+\S+\s+\S+\s+\[(\d\d.*\d\d)\]\s+"(?:GET|POST|PUT|HEAD|DELETE)\s+(\S+)\s+HTTP\S+"\s+(\d+)\s+(\d+)\s+"([^"]*)"\s+"([^"]+)"$/
94
-
95
- add_column :name => 'ip', :pos => 1, :aggregator => :count
96
- add_column :name => 'timestamp', :pos => 2, :aggregator => :timestamp
97
- add_column :name => 'code', :pos => 4, :aggregator => :count
98
- add_column :name => 'code_by_ip', :pos => 4, :aggregator => :count, :group_by => 'ip'
99
- add_column :name => 'length', :pos => 5, :aggregator => :average, :conversion => :integer
100
- add_column :name => 'length_by_ip', :pos => 5, :aggregator => :average, :group_by => 'ip', :conversion => :integer
101
-
102
- def time
103
- Time.strptime(self.timestamp, '%d/%b/%Y:%H:%M:%S %z')
104
- end
105
- end
87
+ class AccessLog < LogfileInterval::ParsedLine::Base
88
+ # Example line:
89
+ # 74.75.19.145 - - [31/Mar/2013:06:54:12 -0700] "GET /ppa/google_chrome HTTP/1.1" 200 7855 "https://www.google.com/" "Mozilla/5.0 Chrome/25.0.1364.160"
90
+
91
+ set_regex /^([\d\.]+)\s+\S+\s+\S+\s+\[(\d\d.*\d\d)\]\s+"(?:GET|POST|PUT|HEAD|DELETE)\s+(\S+)\s+HTTP\S+"\s+(\d+)\s+(\d+)\s+"([^"]*)"\s+"([^"]+)"$/
92
+
93
+ add_column :name => 'ip', :pos => 1, :aggregator => :count
94
+ add_column :name => 'timestamp', :pos => 2, :aggregator => :timestamp
95
+ add_column :name => 'code', :pos => 4, :aggregator => :count
96
+ add_column :name => 'code_by_ip', :pos => 4, :aggregator => :count, :group_by => 'ip'
97
+ add_column :name => 'length', :pos => 5, :aggregator => :average, :conversion => :integer
98
+ add_column :name => 'length_by_ip', :pos => 5, :aggregator => :average, :group_by => 'ip', :conversion => :integer
99
+
100
+ def time
101
+ Time.strptime(self.timestamp, '%d/%b/%Y:%H:%M:%S %z')
106
102
  end
107
103
  end
108
104
  ```
@@ -134,7 +130,7 @@ end
134
130
  And get a parsed record for each line.
135
131
  ```ruby
136
132
  logfile = 'access.log'
137
- parser = LineParser::AccessLog
133
+ parser = AccessLog
138
134
 
139
135
  log = LogfileInterval::Logfile.new(logfile, parser)
140
136
  log.each_line do |line|
@@ -142,7 +138,6 @@ log.each_line do |line|
142
138
  puts line
143
139
  end
144
140
 
145
- parser = LineParser::AccessLog
146
141
  log.each_parsed_line do |record|
147
142
  puts record.class # LineParser::AccessLog
148
143
  puts record.ip
@@ -0,0 +1,17 @@
1
+ module LogfileInterval
2
+ module Aggregator
3
+ class Appender < Base
4
+ def initialize(options = {})
5
+ super(options)
6
+ @val = {}
7
+ end
8
+
9
+ def add(value, group_by = nil)
10
+ @val[key(group_by)] ||= Set.new
11
+ @val[key(group_by)].add(value)
12
+ @size.increment(key(group_by))
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,3 +1,3 @@
1
1
  module LogfileInterval
2
- VERSION = "2.1.3"
2
+ VERSION = "2.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logfile_interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Le Rohellec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,6 +99,7 @@ files:
99
99
  - bin/readme.rb
100
100
  - docs/design.rb
101
101
  - lib/logfile_interval.rb
102
+ - lib/logfile_interval/aggregator/appender.rb
102
103
  - lib/logfile_interval/aggregator/average.rb
103
104
  - lib/logfile_interval/aggregator/base.rb
104
105
  - lib/logfile_interval/aggregator/count.rb
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  version: '0'
162
163
  requirements: []
163
164
  rubyforge_project:
164
- rubygems_version: 2.2.2
165
+ rubygems_version: 2.4.5
165
166
  signing_key:
166
167
  specification_version: 4
167
168
  summary: Aggregate logfile data into intervals