logtrend 0.2.20101204144415 → 0.3.20101204155928
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/logtrend.rb +28 -6
- data/samples/example.rb +5 -6
- data/samples/test.log +3 -0
- metadata +4 -4
data/lib/logtrend.rb
CHANGED
@@ -9,7 +9,7 @@ class LogTrend
|
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@trends = {}
|
12
|
-
@graphs =
|
12
|
+
@graphs = []
|
13
13
|
@logger = Logger.new(STDERR)
|
14
14
|
@logger.level = ($DEBUG and Logger::DEBUG or Logger::WARN)
|
15
15
|
end
|
@@ -34,10 +34,10 @@ class LogTrend
|
|
34
34
|
rrd.update Time.now, value
|
35
35
|
end
|
36
36
|
|
37
|
-
def build_graph(graphs_dir, rrd_dir,
|
38
|
-
RRD.graph File.join(graphs_dir,"#{name}.png"), :title => name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
|
39
|
-
|
40
|
-
line File.join(rrd_dir,"#{name}.rrd"), "#{name}_count" => :average, :color => color, :label => name.to_s
|
37
|
+
def build_graph(graphs_dir, rrd_dir, graph)
|
38
|
+
RRD.graph File.join(graphs_dir,"#{graph.name}.png"), :title => graph.name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
|
39
|
+
graph.points.each do |point|
|
40
|
+
line File.join(rrd_dir,"#{point[:name]}.rrd"), "#{point[:name]}_count" => :average, :color => point[:color], :label => point[:name].to_s
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -52,7 +52,7 @@ class LogTrend
|
|
52
52
|
EventMachine::add_periodic_timer(1.minute) do
|
53
53
|
@logger.debug "#{Time.now} #{counters.inspect}"
|
54
54
|
counters.each {|name, value| update_rrd(rrd_dir,name, value)}
|
55
|
-
graphs.each {|
|
55
|
+
@graphs.each {|graph| build_graph(graphs_dir, rrd_dir, graph)}
|
56
56
|
counters = reset_counters
|
57
57
|
end
|
58
58
|
|
@@ -73,9 +73,31 @@ class LogTrend
|
|
73
73
|
@trends[name] = block
|
74
74
|
end
|
75
75
|
|
76
|
+
def add_graph(name, &block)
|
77
|
+
throw "D'oh! No block." unless block_given?
|
78
|
+
graph = Graph.new(name)
|
79
|
+
yield graph
|
80
|
+
@graphs << graph
|
81
|
+
end
|
82
|
+
|
76
83
|
def self.start(logfile, rrd_dir, graphs_dir, &block)
|
77
84
|
l = LogTrend.new
|
78
85
|
yield l if block
|
79
86
|
l.start logfile, rrd_dir, graphs_dir
|
80
87
|
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Graph
|
91
|
+
|
92
|
+
attr_reader :points
|
93
|
+
attr_reader :name
|
94
|
+
|
95
|
+
def initialize(name)
|
96
|
+
@name = name
|
97
|
+
@points = []
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_line(name,color)
|
101
|
+
@points << {:name => name, :color => color}
|
102
|
+
end
|
81
103
|
end
|
data/samples/example.rb
CHANGED
@@ -14,10 +14,9 @@ LogTrend.start('test.log', "/tmp/rrd", "/tmp/graphs") do |l|
|
|
14
14
|
l.add_trend(:fbod) {|line| line.match /fogbugz.com/}
|
15
15
|
l.add_trend(:kod) {|line| line.match /kilnhg.com/}
|
16
16
|
|
17
|
-
l.
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
17
|
+
l.add_graph(:requests_per_minute) do |g|
|
18
|
+
g.add_line :fbod, "#0066cc"
|
19
|
+
g.add_line :kod, "#993333"
|
20
|
+
end
|
21
|
+
|
23
22
|
end
|
data/samples/test.log
CHANGED
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: 40202408311843
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 20101204155928
|
10
|
+
version: 0.3.20101204155928
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Gorsuch
|