logtrend 0.1.20101203211234 → 0.1.20101203213911

Sign up to get free protection for your applications and to get access to all the features.
data/lib/logtrend.rb CHANGED
@@ -23,8 +23,8 @@ class LogTrend
23
23
  counters
24
24
  end
25
25
 
26
- def update_rrd(name, value)
27
- file_name = "#{name}.rrd"
26
+ def update_rrd(rrd_dir,name, value)
27
+ file_name = File.join(rrd_dir,"#{name}.rrd")
28
28
  rrd = RRD::Base.new(file_name)
29
29
  if !File.exists?(file_name)
30
30
  rrd.create :start => Time.now - 10.seconds, :step => 1.minutes do
@@ -35,23 +35,25 @@ class LogTrend
35
35
  rrd.update Time.now, value
36
36
  end
37
37
 
38
- def build_graph(name, data)
39
- RRD.graph "#{name}.png", :title => name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
38
+ def build_graph(graphs_dir, rrd_dir, name, data)
39
+ RRD.graph File.join(graphs_dir,"#{name}.png"), :title => name, :width => 800, :height => 250, :color => ["FONT#000000", "BACK#FFFFFF"] do
40
40
  data.each do |name, color|
41
- area "#{name}.rrd", "#{name}_count" => :average, :color => color, :label => name.to_s
41
+ area File.join(rrd_dir,"#{name}.rrd"), "#{name}_count" => :average, :color => color, :label => name.to_s
42
42
  end
43
43
  end
44
44
  end
45
45
 
46
- def start(logfile)
47
- begin
46
+ def start(logfile,rrd_dir,graphs_dir)
47
+ begin
48
+ rrd_dir = rrd_dir
49
+ graphs_dir = graphs_dir
48
50
  counters = reset_counters
49
51
 
50
52
  EventMachine.run do
51
53
  EventMachine::add_periodic_timer(1.minute) do
52
54
  @logger.debug "#{Time.now} #{counters.inspect}"
53
- counters.each {|name, value| update_rrd(name, value)}
54
- graphs.each {|name, data| build_graph(name, data)}
55
+ counters.each {|name, value| update_rrd(rrd_dir,name, value)}
56
+ graphs.each {|name, data| build_graph(graphs_dir, rrd_dir, name, data)}
55
57
  counters = reset_counters
56
58
  end
57
59
 
@@ -66,9 +68,9 @@ class LogTrend
66
68
  end
67
69
  end
68
70
 
69
- def self.start(logfile, &block)
71
+ def self.start(logfile, rrd_dir, graphs_dir, &block)
70
72
  l = LogTrend.new
71
73
  yield l if block
72
- l.start(logfile)
74
+ l.start logfile, rrd_dir, graphs_dir
73
75
  end
74
76
  end
data/samples/example.rb CHANGED
@@ -5,8 +5,10 @@ require 'logtrend'
5
5
  require 'fileutils'
6
6
 
7
7
  FileUtils.touch('test.log')
8
+ Dir.mkdir('/tmp/rrd') if !File.exists?('/tmp/rrd')
9
+ Dir.mkdir('/tmp/graphs') if !File.exists?('/tmp/graphs')
8
10
 
9
- LogTrend.start('test.log') do |l|
11
+ LogTrend.start('test.log', "/tmp/rrd", "/tmp/graphs") do |l|
10
12
  l.trends = {
11
13
  :total => /.*/,
12
14
  :fbod => /fogbugz.com/,
data/samples/test.log ADDED
File without changes
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: 40202406422495
4
+ hash: 40202406427829
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 20101203211234
10
- version: 0.1.20101203211234
9
+ - 20101203213911
10
+ version: 0.1.20101203213911
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Gorsuch
@@ -57,6 +57,7 @@ extra_rdoc_files: []
57
57
  files:
58
58
  - lib/logtrend.rb
59
59
  - samples/example.rb
60
+ - samples/test.log
60
61
  has_rdoc: true
61
62
  homepage: https://github.com/gorsuch/logtrend
62
63
  licenses: []