class TypeperfWrapper
Wraps the typeperf command-line tool, used to get Windows performance metrics
Attributes
counters[R]
Public Class Methods
new(perfmon_proc_getter, interval = 10)
click to toggle source
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
# File lib/logstash/inputs/typeperf_wrapper.rb, line 11 def initialize(perfmon_proc_getter, interval = 10) @interval = interval @perfmon_proc_getter = perfmon_proc_getter @counters = [] @msg_queue = Queue.new end
Public Instance Methods
add_counter(counter_name)
click to toggle source
Adds a counter to the list of counters watched
- counter_name
-
The path to the counter, such as “\processor(_total)\% processor time”
# File lib/logstash/inputs/typeperf_wrapper.rb, line 20 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?()
click to toggle source
Gets a value indicating whether the typeperf process is running
# File lib/logstash/inputs/typeperf_wrapper.rb, line 38 def alive? @perfmon_proc_getter.proc_is_running? end
get_next()
click to toggle source
Waits until a new message is put onto the queue, then returns it
# File lib/logstash/inputs/typeperf_wrapper.rb, line 43 def get_next while alive? && @msg_queue.empty? sleep 0.5 end @msg_queue.pop end
start_monitor()
click to toggle source
Begins monitoring, using the counters in the @counters array
- interval
-
The time between samples, defaults to ten seconds
# File lib/logstash/inputs/typeperf_wrapper.rb, line 27 def start_monitor raise "No perfmon counters defined" if @counters.compact.empty? open_thread_and_do_work() end
stop_monitor()
click to toggle source
Stops monitoring
# File lib/logstash/inputs/typeperf_wrapper.rb, line 33 def stop_monitor @perfmon_proc_getter.stop_process end
Private Instance Methods
open_thread_and_do_work()
click to toggle source
# File lib/logstash/inputs/typeperf_wrapper.rb, line 54 def open_thread_and_do_work Thread.new do @perfmon_proc_getter.start_process(@counters, @interval, @msg_queue) end @perfmon_proc_getter.wait_for_process_to_start end