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.
-
#heartbeat ⇒ Object
Defines the amount of time between updates that will mark a value unknown.
-
#logger ⇒ Object
This sets the logger to use.
-
#rrd_dir ⇒ Object
This sets the directory where your RRD files will rest.
-
#step ⇒ Object
Defines the amount of time between each updates, given in seconds.
-
#template ⇒ Object
This sets the HTML file template for the generated index.html file.
Class Method Summary collapse
-
.run(logfile, options = {}) {|l| ... } ⇒ Object
This is the preferred entry point.
Instance Method Summary collapse
- #add_graph(name) {|graph| ... } ⇒ Object
- #add_trend(name, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #run(logfile) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
47 48 49 50 51 52 53 |
# File 'lib/logtrend.rb', line 47 def initialize(={}) set_defaults .each do |key, val| send("#{key}=", val) end end |
Instance Attribute Details
#graphs_dir ⇒ Object
This sets the directory where graphs should be stored.
14 15 16 |
# File 'lib/logtrend.rb', line 14 def graphs_dir @graphs_dir end |
#heartbeat ⇒ Object
Defines the amount of time between updates that will mark a value unknown.
From the rrdcreate(2) manual page:
heartbeat defines the maximum number of seconds that may pass between two updates of this data source before the value of the data source is assumed to be *UNKNOWN*.
45 46 47 |
# File 'lib/logtrend.rb', line 45 def heartbeat @heartbeat end |
#logger ⇒ Object
This sets the logger to use. Must be something that behaves like a Logger object.
20 21 22 |
# File 'lib/logtrend.rb', line 20 def logger @logger end |
#rrd_dir ⇒ Object
This sets the directory where your RRD files will rest.
17 18 19 |
# File 'lib/logtrend.rb', line 17 def rrd_dir @rrd_dir end |
#step ⇒ Object
Defines the amount of time between each updates, given in seconds. Default value is 60 seconds.
From the rrdcreate(2) manual page:
Specifies the base interval in seconds with which data will be fed into the RRD.
36 37 38 |
# File 'lib/logtrend.rb', line 36 def step @step end |
#template ⇒ Object
This sets the HTML file template for the generated index.html file. The String here will pass through ERB, with self being set as the binding.
The default generates a simple HTML file that loads one IMG tag per graph.
26 27 28 |
# File 'lib/logtrend.rb', line 26 def template @template end |
Class Method Details
Instance Method Details
#add_graph(name) {|graph| ... } ⇒ Object
60 61 62 63 64 65 |
# File 'lib/logtrend.rb', line 60 def add_graph(name, &block) raise ArgumentError, "D'oh! No block." unless block_given? graph = Graph.new(name) yield graph @graphs << graph end |
#add_trend(name, &block) ⇒ Object
55 56 57 58 |
# File 'lib/logtrend.rb', line 55 def add_trend(name, &block) raise ArgumentError, "D'oh! No block." unless block_given? @trends[name] = block end |
#run(logfile) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/logtrend.rb', line 75 def run(logfile) counters = reset_counters EventMachine.run do EventMachine::add_periodic_timer(step) 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 |