logtrend 0.2.20101204144415 → 0.3.20101204155928

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.
@@ -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, name, data)
38
- RRD.graph File.join(graphs_dir,"#{name}.png"), :title => name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
39
- data.each do |name, color|
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 {|name, data| build_graph(graphs_dir, rrd_dir, name, data)}
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
@@ -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.graphs = {
18
- "requests_per_minute" => {
19
- :fbod => '#0066cc',
20
- :kod => '#993333'
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
@@ -17,3 +17,6 @@ fogbugz.com
17
17
  fogbugz.com
18
18
  fogbugz.com
19
19
  kilnhg.com
20
+ test
21
+ test
22
+ test
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: 40202408288809
4
+ hash: 40202408311843
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 20101204144415
10
- version: 0.2.20101204144415
8
+ - 3
9
+ - 20101204155928
10
+ version: 0.3.20101204155928
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Gorsuch