Class: TypeperfWrapper
- Inherits:
-
Object
- Object
- TypeperfWrapper
- 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
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
Instance Method Summary collapse
-
#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”.
-
#alive? ⇒ Boolean
Gets a value indicating whether the typeperf process is running.
-
#get_next ⇒ Object
Waits until a new message is put onto the queue, then returns it.
-
#initialize(perfmon_proc_getter, interval = 10) ⇒ TypeperfWrapper
constructor
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.
-
#start_monitor ⇒ Object
Begins monitoring, using the counters in the @counters array [interval] The time between samples, defaults to ten seconds.
-
#stop_monitor ⇒ Object
Stops monitoring.
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
11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
6 7 8 |
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 6 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”
20 21 22 23 |
# 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? ⇒ Boolean
Gets a value indicating whether the typeperf process is running
38 39 40 |
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 38 def alive? @perfmon_proc_getter.proc_is_running? end |
#get_next ⇒ Object
Waits until a new message is put onto the queue, then returns it
43 44 45 46 47 48 49 |
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 43 def get_next while @msg_queue.empty? sleep 0.5 end @msg_queue.pop end |
#start_monitor ⇒ Object
Begins monitoring, using the counters in the @counters array
- interval
-
The time between samples, defaults to ten seconds
27 28 29 30 |
# 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 ⇒ Object
Stops monitoring
33 34 35 |
# File 'lib/logstash/inputs/typeperf_wrapper.rb', line 33 def stop_monitor @perfmon_proc_getter.stop_process end |