Class: Dasht::LogThread
- Inherits:
-
Object
- Object
- Dasht::LogThread
- Defined in:
- lib/dasht/log_thread.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #append(metric, regex, &block) ⇒ Object
- #count(metric, regex, &block) ⇒ Object
- #event(metric, regex, op, value = nil, &block) ⇒ Object
- #gauge(metric, regex, &block) ⇒ Object
-
#initialize(parent, command) ⇒ LogThread
constructor
A new instance of LogThread.
- #max(metric, regex, &block) ⇒ Object
- #min(metric, regex, &block) ⇒ Object
- #run ⇒ Object
- #terminate ⇒ Object
- #unique(metric, regex, &block) ⇒ Object
Constructor Details
#initialize(parent, command) ⇒ LogThread
Returns a new instance of LogThread.
13 14 15 16 17 |
# File 'lib/dasht/log_thread.rb', line 13 def initialize(parent, command) @parent = parent @command = command @event_definitions = [] end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/dasht/log_thread.rb', line 3 def parent @parent end |
Class Method Details
.update_global_stats(line) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/dasht/log_thread.rb', line 5 def self.update_global_stats(line) @total_lines ||= 0 @total_bytes ||= 0 @total_lines += 1 @total_bytes += line.length print "\rConsumed #{@total_lines} lines (#{@total_bytes} bytes)..." end |
Instance Method Details
#append(metric, regex, &block) ⇒ Object
62 63 64 |
# File 'lib/dasht/log_thread.rb', line 62 def append(metric, regex, &block) event(metric, regex, :to_a, nil, &block) end |
#count(metric, regex, &block) ⇒ Object
46 47 48 |
# File 'lib/dasht/log_thread.rb', line 46 def count(metric, regex, &block) event(metric, regex, :dasht_sum, 1, &block) end |
#event(metric, regex, op, value = nil, &block) ⇒ Object
42 43 44 |
# File 'lib/dasht/log_thread.rb', line 42 def event(metric, regex, op, value = nil, &block) @event_definitions << [metric, regex, op, value, block] end |
#gauge(metric, regex, &block) ⇒ Object
50 51 52 |
# File 'lib/dasht/log_thread.rb', line 50 def gauge(metric, regex, &block) event(metric, regex, :last, nil, &block) end |
#max(metric, regex, &block) ⇒ Object
58 59 60 |
# File 'lib/dasht/log_thread.rb', line 58 def max(metric, regex, &block) event(metric, regex, :max, nil, &block) end |
#min(metric, regex, &block) ⇒ Object
54 55 56 |
# File 'lib/dasht/log_thread.rb', line 54 def min(metric, regex, &block) event(metric, regex, :min, nil, &block) end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dasht/log_thread.rb', line 19 def run parent.log "Starting `#{@command}`..." @thread = Thread.new do begin while true begin IO.popen(@command) do |process| process.each do |line| _consume_line(line) end end rescue => e parent.log e end sleep 2 end rescue => e parent.log e raise e end end end |
#terminate ⇒ Object
70 71 72 |
# File 'lib/dasht/log_thread.rb', line 70 def terminate @thread.terminate end |
#unique(metric, regex, &block) ⇒ Object
66 67 68 |
# File 'lib/dasht/log_thread.rb', line 66 def unique(metric, regex, &block) event(metric, regex, :uniq, nil, &block) end |