logtrend 0.1.20101204135642 → 0.2.20101204144415
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/lib/logtrend.rb +11 -6
- data/samples/example.rb +4 -5
- data/samples/test.log +19 -0
- metadata +5 -4
data/lib/logtrend.rb
CHANGED
@@ -5,19 +5,18 @@ require 'rrd'
|
|
5
5
|
require 'logger'
|
6
6
|
|
7
7
|
class LogTrend
|
8
|
-
attr_accessor :trends
|
9
8
|
attr_accessor :graphs
|
10
9
|
|
11
10
|
def initialize
|
12
|
-
trends = {}
|
13
|
-
graphs = {}
|
11
|
+
@trends = {}
|
12
|
+
@graphs = {}
|
14
13
|
@logger = Logger.new(STDERR)
|
15
14
|
@logger.level = ($DEBUG and Logger::DEBUG or Logger::WARN)
|
16
15
|
end
|
17
16
|
|
18
17
|
def reset_counters
|
19
18
|
counters = {}
|
20
|
-
trends.keys.each do |k|
|
19
|
+
@trends.keys.each do |k|
|
21
20
|
counters[k] = 0
|
22
21
|
end
|
23
22
|
counters
|
@@ -58,9 +57,10 @@ class LogTrend
|
|
58
57
|
end
|
59
58
|
|
60
59
|
EventMachine::file_tail(logfile) do |filetail, line|
|
61
|
-
trends.each do |name,
|
62
|
-
counters[name] += 1 if
|
60
|
+
@trends.each do |name, block|
|
61
|
+
counters[name] += 1 if block.call(line)
|
63
62
|
end
|
63
|
+
@logger.debug counters.inspect
|
64
64
|
end
|
65
65
|
end
|
66
66
|
rescue Interrupt
|
@@ -68,6 +68,11 @@ class LogTrend
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
def add_trend(name, &block)
|
72
|
+
throw "D'oh! No block." unless block_given?
|
73
|
+
@trends[name] = block
|
74
|
+
end
|
75
|
+
|
71
76
|
def self.start(logfile, rrd_dir, graphs_dir, &block)
|
72
77
|
l = LogTrend.new
|
73
78
|
yield l if block
|
data/samples/example.rb
CHANGED
@@ -9,11 +9,10 @@ Dir.mkdir('/tmp/rrd') if !File.exists?('/tmp/rrd')
|
|
9
9
|
Dir.mkdir('/tmp/graphs') if !File.exists?('/tmp/graphs')
|
10
10
|
|
11
11
|
LogTrend.start('test.log', "/tmp/rrd", "/tmp/graphs") do |l|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
12
|
+
|
13
|
+
l.add_trend(:total) {|line| line.match /.*/}
|
14
|
+
l.add_trend(:fbod) {|line| line.match /fogbugz.com/}
|
15
|
+
l.add_trend(:kod) {|line| line.match /kilnhg.com/}
|
17
16
|
|
18
17
|
l.graphs = {
|
19
18
|
"requests_per_minute" => {
|
data/samples/test.log
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logtrend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 40202408288809
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 20101204144415
|
10
|
+
version: 0.2.20101204144415
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Gorsuch
|
@@ -71,6 +71,7 @@ extra_rdoc_files: []
|
|
71
71
|
files:
|
72
72
|
- lib/logtrend.rb
|
73
73
|
- samples/example.rb
|
74
|
+
- samples/test.log
|
74
75
|
has_rdoc: true
|
75
76
|
homepage: https://github.com/gorsuch/logtrend
|
76
77
|
licenses: []
|