Class: LogTrend::Base
- Inherits:
-
Object
- Object
- LogTrend::Base
- Defined in:
- lib/logtrend.rb
Instance Attribute Summary collapse
-
#graphs_dir ⇒ Object
This sets the directory where graphs should be stored.
-
#rrd_dir ⇒ Object
This sets the directory where your RRD files will rest.
Class Method Summary collapse
-
.run(logfile) {|l| ... } ⇒ Object
This is the preferred entry point.
Instance Method Summary collapse
- #add_graph(name) {|graph| ... } ⇒ Object
- #add_trend(name, &block) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #run(logfile) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/logtrend.rb', line 15 def initialize @graphs_dir = '.' @rrd_dir = '.' @trends = {} @graphs = [] @logger = Logger.new(STDERR) @logger.level = ($DEBUG and Logger::DEBUG or Logger::WARN) @template = ERB.new <<-EOF <html> <head> <title>logtrend</title> </head> <body> <% @graphs.each do |graph| %> <img src='<%=graph.name%>.png' /> <% end %> </body> </html> EOF end |
Instance Attribute Details
#graphs_dir ⇒ Object
This sets the directory where graphs should be stored.
11 12 13 |
# File 'lib/logtrend.rb', line 11 def graphs_dir @graphs_dir end |
#rrd_dir ⇒ Object
This sets the directory where your RRD files will rest.
13 14 15 |
# File 'lib/logtrend.rb', line 13 def rrd_dir @rrd_dir end |
Class Method Details
Instance Method Details
#add_graph(name) {|graph| ... } ⇒ Object
42 43 44 45 46 47 |
# File 'lib/logtrend.rb', line 42 def add_graph(name, &block) throw "D'oh! No block." unless block_given? graph = Graph.new(name) yield graph @graphs << graph end |
#add_trend(name, &block) ⇒ Object
37 38 39 40 |
# File 'lib/logtrend.rb', line 37 def add_trend(name, &block) throw "D'oh! No block." unless block_given? @trends[name] = block end |
#run(logfile) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/logtrend.rb', line 57 def run(logfile) counters = reset_counters EventMachine.run do EventMachine::add_periodic_timer(1.minute) do @logger.debug "#{Time.now} #{counters.inspect}" counters.each {|name, value| update_rrd(name, value)} @graphs.each {|graph| build_graph(graph)} build_page counters = reset_counters end EventMachine::file_tail(logfile) do |filetail, line| @trends.each do |name, block| counters[name] += 1 if block.call(line) end @logger.debug counters.inspect end end end |