logtrend 0.5.20101204163902 → 0.6.20101204165035

Sign up to get free protection for your applications and to get access to all the features.
data/lib/logtrend.rb CHANGED
@@ -6,8 +6,11 @@ require 'logger'
6
6
 
7
7
  class LogTrend
8
8
  attr_accessor :graphs
9
+ attr_accessor :graphs_dir, :rrd_dir
9
10
 
10
11
  def initialize
12
+ @graphs_dir = '.'
13
+ @rrd_dir = '.'
11
14
  @trends = {}
12
15
  @graphs = []
13
16
  @logger = Logger.new(STDERR)
@@ -22,8 +25,8 @@ class LogTrend
22
25
  counters
23
26
  end
24
27
 
25
- def update_rrd(rrd_dir,name, value)
26
- file_name = File.join(rrd_dir,"#{name}.rrd")
28
+ def update_rrd(name, value)
29
+ file_name = File.join(@rrd_dir,"#{name}.rrd")
27
30
  rrd = RRD::Base.new(file_name)
28
31
  if !File.exists?(file_name)
29
32
  rrd.create :start => Time.now - 10.seconds, :step => 1.minutes do
@@ -34,8 +37,9 @@ class LogTrend
34
37
  rrd.update Time.now, value
35
38
  end
36
39
 
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
40
+ def build_graph(graph)
41
+ rrd_dir = @rrd_dir
42
+ RRD.graph File.join(@graphs_dir,"#{graph.name}.png"), :title => graph.name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
39
43
  graph.points.each do |point|
40
44
  if point.style == :line
41
45
  line File.join(rrd_dir,"#{point.name}.rrd"), "#{point.name}_count" => :average, :color => point.color, :label => point.name.to_s
@@ -46,17 +50,15 @@ class LogTrend
46
50
  end
47
51
  end
48
52
 
49
- def start(logfile,rrd_dir,graphs_dir)
53
+ def start(logfile)
50
54
  begin
51
- rrd_dir = rrd_dir
52
- graphs_dir = graphs_dir
53
55
  counters = reset_counters
54
56
 
55
57
  EventMachine.run do
56
58
  EventMachine::add_periodic_timer(1.minute) do
57
59
  @logger.debug "#{Time.now} #{counters.inspect}"
58
- counters.each {|name, value| update_rrd(rrd_dir,name, value)}
59
- @graphs.each {|graph| build_graph(graphs_dir, rrd_dir, graph)}
60
+ counters.each {|name, value| update_rrd(name, value)}
61
+ @graphs.each {|graph| build_graph(graph)}
60
62
  counters = reset_counters
61
63
  end
62
64
 
@@ -84,10 +86,10 @@ class LogTrend
84
86
  @graphs << graph
85
87
  end
86
88
 
87
- def self.start(logfile, rrd_dir, graphs_dir, &block)
89
+ def self.start(logfile, &block)
88
90
  l = LogTrend.new
89
91
  yield l if block
90
- l.start logfile, rrd_dir, graphs_dir
92
+ l.start logfile
91
93
  end
92
94
  end
93
95
 
data/samples/example.rb CHANGED
@@ -8,7 +8,10 @@ FileUtils.touch('test.log')
8
8
  Dir.mkdir('/tmp/rrd') if !File.exists?('/tmp/rrd')
9
9
  Dir.mkdir('/tmp/graphs') if !File.exists?('/tmp/graphs')
10
10
 
11
- LogTrend.start('test.log', "/tmp/rrd", "/tmp/graphs") do |l|
11
+ LogTrend.start("test.log") do |l|
12
+
13
+ l.rrd_dir = '/tmp/rrd'
14
+ l.graphs_dir = '/tmp/graphs'
12
15
 
13
16
  l.add_trend(:total) {|line| line.match /.*/}
14
17
  l.add_trend(:fbod) {|line| line.match /fogbugz.com/}
data/samples/test.log CHANGED
@@ -31,3 +31,9 @@ test
31
31
  test
32
32
  test
33
33
  test
34
+ test
35
+ test
36
+ test
37
+ test
38
+ test
39
+ 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: 40202408327799
4
+ hash: 40202408330065
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 20101204163902
10
- version: 0.5.20101204163902
8
+ - 6
9
+ - 20101204165035
10
+ version: 0.6.20101204165035
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Gorsuch