Class: TypeperfWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/inputs/typeperf_wrapper.rb

Overview

Wraps the typeperf command-line tool, used to get Windows performance metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(perfmon_proc_getter, interval = 10) ⇒ TypeperfWrapper

Initializes the TypeperfWrapper class

perfmon_proc_getter

Gets the proc for opening the perfmon process and getting messages

interval

The time between samples, defaults to ten seconds



12
13
14
15
16
17
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 12

def initialize(perfmon_proc_getter, interval = 10)
  @interval = interval
  @perfmon_proc_getter = perfmon_proc_getter
  @counters = []
  @msg_queue = Queue.new
end

Instance Attribute Details

#countersObject (readonly)

Returns the value of attribute counters.



7
8
9
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 7

def counters
  @counters
end

Instance Method Details

#add_counter(counter_name) ⇒ Object

Adds a counter to the list of counters watched

counter_name

The path to the counter, such as “\processor(_total)\% processor time”



21
22
23
24
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 21

def add_counter(counter_name)
  raise "Perfmon counter '#{counter_name}' could not be found." unless @perfmon_proc_getter.counter_exists?(counter_name)
  @counters << counter_name.downcase
end

#alive?Boolean

Gets a value indicating whether the typeperf process is running

Returns:

  • (Boolean)


39
40
41
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 39

def alive?
  @perfmon_proc_getter.proc_is_running?
end

#get_nextObject

Waits until a new message is put onto the queue, then returns it



44
45
46
47
48
49
50
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 44

def get_next
  while @msg_queue.empty?
    sleep 0.5 
  end
  
  @msg_queue.pop
end

#start_monitorObject

Begins monitoring, using the counters in the @counters array

interval

The time between samples, defaults to ten seconds



28
29
30
31
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 28

def start_monitor
  raise "No perfmon counters defined" if @counters.compact.empty?
  open_thread_and_do_work()
end

#stop_monitorObject

Stops monitoring



34
35
36
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 34

def stop_monitor
  @perfmon_proc_getter.stop_process
end