Class: Fluent::Plugin::WatchProcessInput::WindowsWatcher
- Inherits:
-
Object
- Object
- Fluent::Plugin::WatchProcessInput::WindowsWatcher
- Defined in:
- lib/fluent/plugin/in_watch_process.rb
Constant Summary collapse
- DEFAULT_KEYS =
Keys are from the “System.Diagnostics.Process” object properties that can be taken by the “Get-Process” command. You can check the all properties by the “(Get-Process) | Get-Member” command.
%w(StartTime UserName SessionId Id CPU WorkingSet VirtualMemorySize HandleCount ProcessName)
- DEFAULT_TYPES =
%w( SessionId:integer Id:integer CPU:float WorkingSet:integer VirtualMemorySize:integer HandleCount:integer ).join(",")
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #command_ps ⇒ Object
- #default_command ⇒ Object
- #default_types ⇒ Object
-
#initialize(keys, command, lookup_user, powershell_command) ⇒ WindowsWatcher
constructor
A new instance of WindowsWatcher.
- #match_look_up_user?(data) ⇒ Boolean
- #parse_line(line) ⇒ Object
Constructor Details
#initialize(keys, command, lookup_user, powershell_command) ⇒ WindowsWatcher
Returns a new instance of WindowsWatcher.
137 138 139 140 141 142 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 137 def initialize(keys, command, lookup_user, powershell_command) @keys = keys || DEFAULT_KEYS @powershell_command = powershell_command @command = command || default_command @lookup_user = lookup_user end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
135 136 137 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 135 def command @command end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
134 135 136 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 134 def keys @keys end |
Instance Method Details
#command_ps ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 178 def command_ps if @keys.include?("UserName") # The "IncludeUserName" option is needed to get the username, but this option requires Administrator privilege. "Get-Process -IncludeUserName" else "Get-Process" end end |
#default_command ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 167 def default_command command = [ command_ps, pipe_filtering_normal_ps, pipe_select_columns, pipe_fixing_locale, pipe_formatting_output, ].join "#{@powershell_command} -command \"#{command}\"" end |
#default_types ⇒ Object
144 145 146 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 144 def default_types DEFAULT_TYPES end |
#match_look_up_user?(data) ⇒ Boolean
161 162 163 164 165 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 161 def match_look_up_user?(data) return true if @lookup_user.nil? @lookup_user.include?(data["UserName"]) end |
#parse_line(line) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/fluent/plugin/in_watch_process.rb', line 148 def parse_line(line) values = line.chomp.strip.parse_csv.map { |e| e ? e : "" } data = Hash[@keys.zip(values)] unless data["StartTime"].nil? start_time = Time.parse(data['StartTime']) data['ElapsedTime'] = (Time.now - start_time).to_i data["StartTime"] = start_time.to_s end data end |