logstash-input-remote_proc 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0983a9d2e35c35ad804f33c09edb2dcbb3700804
4
- data.tar.gz: 3e91fd6e62044ddb991862dfa78179d5f7eba9c8
3
+ metadata.gz: 18036cd47bafcebcaa5a6039407d6c8abf3d019a
4
+ data.tar.gz: 4a00dd8d6dec59b760010130ef65b785b3cf8fef
5
5
  SHA512:
6
- metadata.gz: 1fb45c39cea960ed7106cce6c65c6557df398b7119d6a626d6dbf0430cc0402553f7f45524a6660f594da71869927c5fd55bdea53de872ad775dba856f6f7675
7
- data.tar.gz: c5d77173d7ebbd0237656af361dcb128fe7134e4b8d3f716941a64781cc238990db7a1c08bcec558691d064303a3f3972c04174f2302a5737f5e508a30208a63
6
+ metadata.gz: c02c6b84a1cd161125e1f66798abc9dc0a84ab3a30ee6f405d39659f0b9d2041d71ee22867bb64dac2fcdcca0134e071ca1d4cba5175a8e82ac91b6ac693c870
7
+ data.tar.gz: b4a7d058b4c53aae5582b48521425c0dd254950e4a53e813780eb34278da78d0847ea22c38988e08ab85c4a4b0349818908cd3abd0823acedb8c21a4337944a9
@@ -86,8 +86,9 @@ module LogStash
86
86
  def register
87
87
  @host = Socket.gethostname
88
88
 
89
- require 'net/ssh/multi'
90
- @ssh_session = Net::SSH::Multi.start(on_error: :warn)
89
+ require 'net/ssh'
90
+ require 'net/ssh/gateway'
91
+ @ssh_sessions = []
91
92
 
92
93
  # Don't forget to close all gateways manually in `stop` method.
93
94
  @ssh_gateways = []
@@ -99,18 +100,47 @@ module LogStash
99
100
  def run(queue)
100
101
  # we can abort the loop if stop? becomes true
101
102
  until stop?
102
- COMMANDS.keys.each do |method|
103
- send("proc_#{method}", queue)
104
- end
103
+ @ssh_sessions.each do |ssh|
104
+ COMMANDS.each do |method, command|
105
+ result_data = String.new('')
106
+ channel = ssh.open_channel do |chan|
107
+ chan.exec(command) do |ch, success|
108
+ next unless success
109
+
110
+ # "on_data" called when the process writes to stdout
111
+ ch.on_data { |_c, data| result_data << data }
105
112
 
106
- @ssh_session.loop(@interval)
113
+ # "on_extended_data", called when the process writes to stderr
114
+ ch.on_extended_data {} # |_c, _type, _data|
107
115
 
116
+ ch.on_close(&:close)
117
+ end
118
+ end
119
+ channel.wait
120
+ next if result_data.empty?
121
+ result = send("proc_#{method}", result_data)
122
+ next if result.empty?
123
+ event = LogStash::Event.new(
124
+ method => result,
125
+ host: @host,
126
+ type: @type || "system-#{method}",
127
+ metric_name: "system-#{method}",
128
+ remote_host: channel.connection.transport.host,
129
+ remote_port: channel.connection.transport.port,
130
+ command: command,
131
+ message: result_data
132
+ )
133
+ decorate(event)
134
+ queue << event
135
+ end
136
+ ssh.loop
137
+ end # @ssh_sessions block
108
138
  Stud.stoppable_sleep(@interval) { stop? }
109
- end # loop
139
+ end # until loop
110
140
  end # def run
111
141
 
112
142
  def stop
113
- @ssh_session.close
143
+ @ssh_sessions.map(&:close)
114
144
  @ssh_gateways.map(&:shutdown!) unless @ssh_gateways.empty?
115
145
  end
116
146
 
@@ -128,6 +158,7 @@ module LogStash
128
158
  prepare_servers!(s)
129
159
 
130
160
  session_options = {}
161
+ session_options[:port] = s['port'] if s['port']
131
162
  session_options[:password] = s['password'] if s['password']
132
163
  if s['ssh_private_key']
133
164
  session_options[:auth_methods] = ['publickey']
@@ -144,352 +175,246 @@ module LogStash
144
175
  s['gateway_username'],
145
176
  gw_opts)
146
177
  @ssh_gateways << gw
147
- session_options[:via] = gw
178
+ @ssh_sessions << gw.ssh(s['host'],
179
+ s['username'],
180
+ session_options)
181
+ else
182
+ @ssh_sessions << Net::SSH.start(s['host'],
183
+ s['username'],
184
+ session_options)
148
185
  end
149
-
150
- @ssh_session.use("#{s['username']}@#{s['host']}:#{s['port']}",
151
- session_options)
152
186
  end
153
187
  end
154
188
 
155
189
  # Process SYSVIPCSHM data
156
- def proc_sysvipcshm(queue)
157
- @ssh_session.exec(COMMANDS[:sysvipcshm]) do |ch, stream, data|
158
- next unless stream == :stdout # ignore :stderr
159
- lines = data.split(/$/)
160
- _ = lines.shift # Remove column name line
161
- sysvipcshm = {}
162
- lines.each do |l|
163
- t = l.strip.split(/\s+/)
164
- next if t.empty? || t.length < 16
165
- sysvipcshm[t[1]] = {} # shmid
166
- sysvipcshm[t[1]]['key'] = t[0]
167
- sysvipcshm[t[1]]['perms'] = t[2]
168
- sysvipcshm[t[1]]['size'] = t[3]
169
- sysvipcshm[t[1]]['cpid'] = t[4]
170
- sysvipcshm[t[1]]['lpid'] = t[5]
171
- sysvipcshm[t[1]]['nattch'] = t[6]
172
- sysvipcshm[t[1]]['uid'] = t[7]
173
- sysvipcshm[t[1]]['gid'] = t[8]
174
- sysvipcshm[t[1]]['cuid'] = t[9]
175
- sysvipcshm[t[1]]['cgid'] = t[10]
176
- sysvipcshm[t[1]]['atime'] = t[11]
177
- sysvipcshm[t[1]]['dtime'] = t[12]
178
- sysvipcshm[t[1]]['ctime'] = t[13]
179
- sysvipcshm[t[1]]['rss'] = t[14]
180
- sysvipcshm[t[1]]['swap'] = t[15]
181
- end
182
- next if sysvipcshm.empty?
183
- event = LogStash::Event.new(sysvipcshm: sysvipcshm,
184
- host: @host,
185
- type: @type || 'system-sysvipcshm',
186
- metric_name: 'system-sysvipcshm',
187
- remote_host: ch[:host],
188
- command: COMMANDS[:sysvipcshm],
189
- message: data)
190
- decorate(event)
191
- queue << event
190
+ def proc_sysvipcshm(data)
191
+ return {} unless data
192
+ lines = data.split(/$/)
193
+ _ = lines.shift # Remove column name line
194
+ sysvipcshm = {}
195
+ lines.each do |l|
196
+ t = l.strip.split(/\s+/)
197
+ next if t.empty? || t.length < 16
198
+ sysvipcshm[t[1]] = {} # shmid
199
+ sysvipcshm[t[1]]['key'] = t[0]
200
+ sysvipcshm[t[1]]['perms'] = t[2]
201
+ sysvipcshm[t[1]]['size'] = t[3]
202
+ sysvipcshm[t[1]]['cpid'] = t[4]
203
+ sysvipcshm[t[1]]['lpid'] = t[5]
204
+ sysvipcshm[t[1]]['nattch'] = t[6]
205
+ sysvipcshm[t[1]]['uid'] = t[7]
206
+ sysvipcshm[t[1]]['gid'] = t[8]
207
+ sysvipcshm[t[1]]['cuid'] = t[9]
208
+ sysvipcshm[t[1]]['cgid'] = t[10]
209
+ sysvipcshm[t[1]]['atime'] = t[11]
210
+ sysvipcshm[t[1]]['dtime'] = t[12]
211
+ sysvipcshm[t[1]]['ctime'] = t[13]
212
+ sysvipcshm[t[1]]['rss'] = t[14]
213
+ sysvipcshm[t[1]]['swap'] = t[15]
192
214
  end
215
+ sysvipcshm
193
216
  end
194
217
 
195
218
  # Process CRYPTO data
196
- def proc_crypto(queue)
197
- @ssh_session.exec(COMMANDS[:crypto]) do |ch, stream, data|
198
- next unless stream == :stdout # ignore :stderr
199
- crypto = {}
200
- current_crypto = ''
201
- data.split(/$/).each do |line|
202
- l = line.strip
203
- next if l.empty?
204
- t = l.split(/\s+:\s+/)
205
- next if t.empty? || t.length != 2
206
- if 'name'.eql?(t[0])
207
- current_crypto = t[1]
208
- crypto[current_crypto] = {}
209
- next
210
- end
211
- crypto[current_crypto][t[0]] = t[1] unless current_crypto.empty?
219
+ def proc_crypto(data)
220
+ return {} unless data
221
+ crypto = {}
222
+ current_crypto = ''
223
+ data.split(/$/).each do |line|
224
+ l = line.strip
225
+ next if l.empty?
226
+ t = l.split(/\s+:\s+/)
227
+ next if t.empty? || t.length != 2
228
+ if 'name'.eql?(t[0])
229
+ current_crypto = t[1]
230
+ crypto[current_crypto] = {}
231
+ next
212
232
  end
213
- next if crypto.empty?
214
- event = LogStash::Event.new(crypto: crypto,
215
- host: @host,
216
- type: @type || 'system-crypto',
217
- metric_name: 'system-crypto',
218
- remote_host: ch[:host],
219
- command: COMMANDS[:crypto],
220
- message: data)
221
- decorate(event)
222
- queue << event
233
+ crypto[current_crypto][t[0]] = t[1] unless current_crypto.empty?
223
234
  end
235
+ crypto
224
236
  end
225
237
 
226
238
  # Process MOUNTS data
227
- def proc_mounts(queue)
228
- @ssh_session.exec(COMMANDS[:mounts]) do |ch, stream, data|
229
- next unless stream == :stdout # ignore :stderr
230
- mounts = {}
231
- data.split(/$/).each do |line|
232
- t = line.strip.split(/\s+/)
233
- next if t.empty? || t.length < 6
234
- # mounted device name
235
- device = {}
236
- device['mountPoint'] = t[1]
237
- device['fsType'] = t[2]
238
- device['fsOptions'] = t[3].split(/,/)
239
- device['dump'] = t[4]
240
- device['pass'] = t[5]
241
- mounts[t[0]] = [] unless mounts.include?(t[0])
242
- mounts[t[0]] << device
243
- end
244
- next if mounts.empty?
245
- event = LogStash::Event.new(mounts: mounts,
246
- host: @host,
247
- type: @type || 'system-mounts',
248
- metric_name: 'system-mounts',
249
- remote_host: ch[:host],
250
- command: COMMANDS[:mounts],
251
- message: data)
252
- decorate(event)
253
- queue << event
239
+ def proc_mounts(data)
240
+ return {} unless data
241
+ mounts = {}
242
+ data.split(/$/).each do |line|
243
+ t = line.strip.split(/\s+/)
244
+ next if t.empty? || t.length < 6
245
+ # mounted device name
246
+ device = {}
247
+ device['mountPoint'] = t[1]
248
+ device['fsType'] = t[2]
249
+ device['fsOptions'] = t[3].split(/,/)
250
+ device['dump'] = t[4]
251
+ device['pass'] = t[5]
252
+ mounts[t[0]] = [] unless mounts.include?(t[0])
253
+ mounts[t[0]] << device
254
254
  end
255
+ mounts
255
256
  end
256
257
 
257
258
  # Process NETWIRELESS data.
258
- def proc_netwireless(queue)
259
- @ssh_session.exec(COMMANDS[:netwireless]) do |ch, stream, data|
260
- next unless stream == :stdout # ignore :stderr
261
- lines = data.split(/$/)
262
- _ = lines.shift # Remove first line
263
- _ = lines.shift # Remove second line
264
- netwireless = {}
265
- lines.each do |l|
266
- t = l.strip.split(/[:\s]+/)
267
- next if t.empty? || t.length < 11 # Last column WE22 is often empty
268
- netwireless[t[0]] = {}
269
- netwireless[t[0]]['status'] = t[1].to_i
270
- netwireless[t[0]]['linkQuality'] = t[2].to_i
271
- netwireless[t[0]]['levelQuality'] = t[3].to_i
272
- netwireless[t[0]]['noiseQuality'] = t[4].to_i
273
- netwireless[t[0]]['nwidDiscarded'] = t[5].to_i
274
- netwireless[t[0]]['cryptDiscarded'] = t[6].to_i
275
- netwireless[t[0]]['fragDiscarded'] = t[7].to_i
276
- netwireless[t[0]]['retryDiscarded'] = t[8].to_i
277
- netwireless[t[0]]['miscDiscarded'] = t[9].to_i
278
- netwireless[t[0]]['beaconMissed'] = t[10].to_i
279
- netwireless[t[0]]['we22'] = t[11].to_i
280
- end
281
- next if netwireless.empty?
282
- event = LogStash::Event.new(netwireless: netwireless,
283
- host: @host,
284
- type: @type || 'system-netwireless',
285
- metric_name: 'system-netwireless',
286
- remote_host: ch[:host],
287
- command: COMMANDS[:netwireless],
288
- message: data)
289
- decorate(event)
290
- queue << event
259
+ def proc_netwireless(data)
260
+ return {} unless data
261
+ lines = data.split(/$/)
262
+ _ = lines.shift # Remove first line
263
+ _ = lines.shift # Remove second line
264
+ netwireless = {}
265
+ lines.each do |l|
266
+ t = l.strip.split(/[:\s]+/)
267
+ next if t.empty? || t.length < 11 # Last column WE22 is often empty
268
+ netwireless[t[0]] = {}
269
+ netwireless[t[0]]['status'] = t[1].to_i
270
+ netwireless[t[0]]['linkQuality'] = t[2].to_i
271
+ netwireless[t[0]]['levelQuality'] = t[3].to_i
272
+ netwireless[t[0]]['noiseQuality'] = t[4].to_i
273
+ netwireless[t[0]]['nwidDiscarded'] = t[5].to_i
274
+ netwireless[t[0]]['cryptDiscarded'] = t[6].to_i
275
+ netwireless[t[0]]['fragDiscarded'] = t[7].to_i
276
+ netwireless[t[0]]['retryDiscarded'] = t[8].to_i
277
+ netwireless[t[0]]['miscDiscarded'] = t[9].to_i
278
+ netwireless[t[0]]['beaconMissed'] = t[10].to_i
279
+ netwireless[t[0]]['we22'] = t[11].to_i
291
280
  end
281
+ netwireless
292
282
  end
293
283
 
294
284
  # Process NETDEV data.
295
- def proc_netdev(queue)
296
- @ssh_session.exec(COMMANDS[:netdev]) do |ch, stream, data|
297
- next unless stream == :stdout # ignore :stderr
298
- lines = data.split(/$/)
299
- _ = lines.shift # Remove first line
300
- _ = lines.shift # Remove second line
301
- netdev = {}
302
- lines.each do |l|
303
- t = l.strip.split(/[:\s]+/)
304
- next if t.empty? || t.length < 17
305
- netdev[t[0]] = {}
306
- netdev[t[0]]['rxbytes'] = t[1].to_i
307
- netdev[t[0]]['rxpackets'] = t[2].to_i
308
- netdev[t[0]]['rxerrs'] = t[3].to_i
309
- netdev[t[0]]['rxdrop'] = t[4].to_i
310
- netdev[t[0]]['rxfifo'] = t[5].to_i
311
- netdev[t[0]]['rxframe'] = t[6].to_i
312
- netdev[t[0]]['rxcompressed'] = t[7].to_i
313
- netdev[t[0]]['rxmulticast'] = t[8].to_i
314
- netdev[t[0]]['txbytes'] = t[9].to_i
315
- netdev[t[0]]['txpackets'] = t[10].to_i
316
- netdev[t[0]]['txerrs'] = t[11].to_i
317
- netdev[t[0]]['txdrop'] = t[12].to_i
318
- netdev[t[0]]['txfifo'] = t[13].to_i
319
- netdev[t[0]]['txcolls'] = t[14].to_i
320
- netdev[t[0]]['txcarrier'] = t[15].to_i
321
- netdev[t[0]]['txcompressed'] = t[16].to_i
322
- end
323
- next if netdev.empty?
324
- event = LogStash::Event.new(netdev: netdev,
325
- host: @host,
326
- type: @type || 'system-netdev',
327
- metric_name: 'system-netdev',
328
- remote_host: ch[:host],
329
- command: COMMANDS[:netdev],
330
- message: data)
331
- decorate(event)
332
- queue << event
285
+ def proc_netdev(data)
286
+ return {} unless data
287
+ lines = data.split(/$/)
288
+ _ = lines.shift # Remove first line
289
+ _ = lines.shift # Remove second line
290
+ netdev = {}
291
+ lines.each do |l|
292
+ t = l.strip.split(/[:\s]+/)
293
+ next if t.empty? || t.length < 17
294
+ netdev[t[0]] = {}
295
+ netdev[t[0]]['rxbytes'] = t[1].to_i
296
+ netdev[t[0]]['rxpackets'] = t[2].to_i
297
+ netdev[t[0]]['rxerrs'] = t[3].to_i
298
+ netdev[t[0]]['rxdrop'] = t[4].to_i
299
+ netdev[t[0]]['rxfifo'] = t[5].to_i
300
+ netdev[t[0]]['rxframe'] = t[6].to_i
301
+ netdev[t[0]]['rxcompressed'] = t[7].to_i
302
+ netdev[t[0]]['rxmulticast'] = t[8].to_i
303
+ netdev[t[0]]['txbytes'] = t[9].to_i
304
+ netdev[t[0]]['txpackets'] = t[10].to_i
305
+ netdev[t[0]]['txerrs'] = t[11].to_i
306
+ netdev[t[0]]['txdrop'] = t[12].to_i
307
+ netdev[t[0]]['txfifo'] = t[13].to_i
308
+ netdev[t[0]]['txcolls'] = t[14].to_i
309
+ netdev[t[0]]['txcarrier'] = t[15].to_i
310
+ netdev[t[0]]['txcompressed'] = t[16].to_i
333
311
  end
312
+ netdev
334
313
  end
335
314
 
336
315
  # Process DISKSTATS data.
337
316
  # https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
338
317
  # https://www.kernel.org/doc/Documentation/iostats.txt
339
- def proc_diskstats(queue)
340
- @ssh_session.exec(COMMANDS[:diskstats]) do |ch, stream, data|
341
- next unless stream == :stdout # ignore :stderr
342
- diskstats = {}
343
- data.split(/$/).each do |line|
344
- t = line.strip.split(/\s+/)
345
- next if t.empty? || t.length < 14
346
- diskstats[t[2]] = {} # device name
347
- diskstats[t[2]]['major number'] = t[0].to_i
348
- diskstats[t[2]]['minor number'] = t[1].to_i
349
- diskstats[t[2]]['reads completed'] = t[3].to_i
350
- diskstats[t[2]]['reads merged'] = t[4].to_i
351
- diskstats[t[2]]['sectors read'] = t[5].to_i
352
- diskstats[t[2]]['time spent reading ms'] = t[6].to_i
353
- diskstats[t[2]]['writes completed'] = t[7].to_i
354
- diskstats[t[2]]['writes merged'] = t[8].to_i
355
- diskstats[t[2]]['sectors written'] = t[9].to_i
356
- diskstats[t[2]]['time spent writing ms'] = t[10].to_i
357
- diskstats[t[2]]['io in progress'] = t[11].to_i
358
- diskstats[t[2]]['io time spent ms'] = t[12].to_i
359
- diskstats[t[2]]['io weighted time spent ms'] = t[13].to_i
360
- end
361
- next if diskstats.empty?
362
- event = LogStash::Event.new(diskstats: diskstats,
363
- host: @host,
364
- type: @type || 'system-diskstats',
365
- metric_name: 'system-diskstats',
366
- remote_host: ch[:host],
367
- command: COMMANDS[:diskstats],
368
- message: data)
369
- decorate(event)
370
- queue << event
318
+ def proc_diskstats(data)
319
+ return {} unless data
320
+ diskstats = {}
321
+ data.split(/$/).each do |line|
322
+ t = line.strip.split(/\s+/)
323
+ next if t.empty? || t.length < 14
324
+ diskstats[t[2]] = {} # device name
325
+ diskstats[t[2]]['major number'] = t[0].to_i
326
+ diskstats[t[2]]['minor number'] = t[1].to_i
327
+ diskstats[t[2]]['reads completed'] = t[3].to_i
328
+ diskstats[t[2]]['reads merged'] = t[4].to_i
329
+ diskstats[t[2]]['sectors read'] = t[5].to_i
330
+ diskstats[t[2]]['time spent reading ms'] = t[6].to_i
331
+ diskstats[t[2]]['writes completed'] = t[7].to_i
332
+ diskstats[t[2]]['writes merged'] = t[8].to_i
333
+ diskstats[t[2]]['sectors written'] = t[9].to_i
334
+ diskstats[t[2]]['time spent writing ms'] = t[10].to_i
335
+ diskstats[t[2]]['io in progress'] = t[11].to_i
336
+ diskstats[t[2]]['io time spent ms'] = t[12].to_i
337
+ diskstats[t[2]]['io weighted time spent ms'] = t[13].to_i
371
338
  end
339
+ diskstats
372
340
  end
373
341
 
374
342
  # Process VMSTAT data.
375
- def proc_vmstat(queue)
376
- @ssh_session.exec(COMMANDS[:vmstat]) do |ch, stream, data|
377
- next unless stream == :stdout # ignore :stderr
378
- vmstat = {}
379
- data.split(/$/).each do |line|
380
- m = /([^\s]+)\s+(\d+)/.match(line)
381
- vmstat[m[1]] = m[2].to_i if m && m.length >= 3
382
- end
383
- next if vmstat.empty?
384
- event = LogStash::Event.new(vmstat: vmstat,
385
- host: @host,
386
- type: @type || 'system-vmstat',
387
- metric_name: 'system-vmstat',
388
- remote_host: ch[:host],
389
- command: COMMANDS[:vmstat],
390
- message: data)
391
- decorate(event)
392
- queue << event
343
+ def proc_vmstat(data)
344
+ return {} unless data
345
+ vmstat = {}
346
+ data.split(/$/).each do |line|
347
+ m = /([^\s]+)\s+(\d+)/.match(line)
348
+ vmstat[m[1]] = m[2].to_i if m && m.length >= 3
393
349
  end
350
+ vmstat
394
351
  end
395
352
 
396
353
  # Process LOADAVG data.
397
- def proc_loadavg(queue)
398
- @ssh_session.exec(COMMANDS[:loadavg]) do |ch, stream, data|
399
- next unless stream == :stdout # ignore :stderr
400
- m = %r{([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\/([^\s]+)\s+([^\s$]+)}.match(data)
401
- next unless m
402
- if m && m.length >= 6
403
- loadavg = { '1minute' => m[1].to_f,
404
- '5minutes' => m[2].to_f,
405
- '15minutes' => m[3].to_f,
406
- 'running_processes' => m[4].to_i,
407
- 'total_processes' => m[5].to_i,
408
- 'last_running_pid' => m[6].to_i }
409
- event = LogStash::Event.new(loadavg: loadavg,
410
- host: @host,
411
- type: @type || 'system-loadavg',
412
- metric_name: 'system-loadavg',
413
- remote_host: ch[:host],
414
- command: COMMANDS[:loadavg],
415
- message: data)
416
- decorate(event)
417
- queue << event
418
- end
354
+ def proc_loadavg(data)
355
+ return {} unless data
356
+ m = %r{([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\/([^\s]+)\s+([^\s$]+)}.match(data)
357
+ next unless m
358
+ loadavg = {}
359
+ if m && m.length >= 6
360
+ loadavg.merge!('1minute' => m[1].to_f,
361
+ '5minutes' => m[2].to_f,
362
+ '15minutes' => m[3].to_f,
363
+ 'running_processes' => m[4].to_i,
364
+ 'total_processes' => m[5].to_i,
365
+ 'last_running_pid' => m[6].to_i)
419
366
  end
367
+ loadavg
420
368
  end
421
369
 
422
370
  # Process MEMINFO data.
423
- def proc_meminfo(queue)
424
- @ssh_session.exec(COMMANDS[:meminfo]) do |ch, stream, data|
425
- next unless stream == :stdout # ignore :stderr
426
- meminfo = {}
427
- data.split(/$/).each do |line|
428
- m = /([^\n\t:]+)\s*:\s+(\d+)(\skb)?$/i.match(line)
429
- next unless m
430
- meminfo[m[1]] = m[2].to_i
431
- meminfo[m[1]] *= 1000 if m[3] # m[3] is not nil if `/KB/i` is found
432
- end
433
- next if meminfo.empty?
371
+ def proc_meminfo(data)
372
+ return {} unless data
373
+ meminfo = {}
374
+ data.split(/$/).each do |line|
375
+ m = /([^\n\t:]+)\s*:\s+(\d+)(\skb)?$/i.match(line)
376
+ next unless m
377
+ meminfo[m[1]] = m[2].to_i
378
+ meminfo[m[1]] *= 1000 if m[3] # m[3] is not nil if `/KB/i` is found
379
+ end
380
+ unless meminfo.empty?
434
381
  meminfo['CalcMemUsed'] = meminfo['MemTotal'] - meminfo['MemFree']
435
- event = LogStash::Event.new(meminfo: meminfo,
436
- host: @host,
437
- type: @type || 'system-meminfo',
438
- metric_name: 'system-meminfo',
439
- remote_host: ch[:host],
440
- command: COMMANDS[:meminfo],
441
- message: data)
442
- decorate(event)
443
- queue << event
444
382
  end
383
+ meminfo
445
384
  end
446
385
 
447
386
  # Process CPUINFO data.
448
- def proc_cpuinfo(queue)
449
- @ssh_session.exec(COMMANDS[:cpuinfo]) do |ch, stream, data|
450
- next unless stream == :stdout # ignore :stderr
451
- cpuinfo = {} # TODO(fenicks): change to array
452
- num_cpu = 0
453
- data.split(/$/).each do |line|
454
- next if line.strip.empty?
455
- m = /([^\n\t:]+)\s*:\s+(.+)$/.match(line)
456
- next unless m
457
- # Apply filters
458
- value = m[2] # needed to permit assignation and computation
459
- num_cpu += 1 if m[1].eql?('processor')
460
- value = m[2].split(/\s+/) if m[1] == 'flags'
461
- value = m[2].to_i if ['processor',
462
- 'physical id',
463
- 'siblings',
464
- 'core id',
465
- 'cpu cores',
466
- 'apicid',
467
- 'initial apicid',
468
- 'cpuid level',
469
- 'clflush size',
470
- 'cache size',
471
- 'cache_alignment'].include?(m[1])
472
- value = m[2].to_f if ['bogomips',
473
- 'cpu MHz'].include?(m[1])
474
- value = m[2].to_i * 1000 if m[2] =~ /\skb$/i
475
- index = num_cpu - 1
476
- cpuinfo[index] = {} unless cpuinfo.include?(index)
477
- cpuinfo[index][m[1]] = value
478
- end
479
- next if cpuinfo.empty?
480
- # Other computed fields
481
- cpuinfo[0]['cpu cores'] = 1 unless cpuinfo[0].include?('cpu cores')
482
- cpuinfo['threads per core'] = num_cpu / cpuinfo[0]['cpu cores']
483
- event = LogStash::Event.new(cpuinfo: cpuinfo,
484
- host: @host,
485
- type: @type || 'system-cpuinfo',
486
- metric_name: 'system-cpuinfo',
487
- remote_host: ch[:host],
488
- command: COMMANDS[:cpuinfo],
489
- message: data)
490
- decorate(event)
491
- queue << event
387
+ def proc_cpuinfo(data)
388
+ return {} unless data
389
+ cpuinfo = {} # TODO(fenicks): change to array
390
+ num_cpu = 0
391
+ data.split(/$/).each do |line|
392
+ next if line.strip.empty?
393
+ m = /([^\n\t:]+)\s*:\s+(.+)$/.match(line)
394
+ next unless m
395
+ # Apply filters
396
+ value = m[2] # needed to permit assignation and computation
397
+ num_cpu += 1 if m[1].eql?('processor')
398
+ value = m[2].split(/\s+/) if m[1] == 'flags'
399
+ value = m[2].to_i if ['processor',
400
+ 'physical id',
401
+ 'siblings',
402
+ 'core id',
403
+ 'cpu cores',
404
+ 'apicid',
405
+ 'initial apicid',
406
+ 'cpuid level',
407
+ 'clflush size',
408
+ 'cache size',
409
+ 'cache_alignment'].include?(m[1])
410
+ value = m[2].to_f if ['bogomips',
411
+ 'cpu MHz'].include?(m[1])
412
+ value = m[2].to_i * 1000 if m[2] =~ /\skb$/i
413
+ index = num_cpu - 1
414
+ cpuinfo[index] = {} unless cpuinfo.include?(index)
415
+ cpuinfo[index][m[1]] = value
492
416
  end
417
+ cpuinfo
493
418
  end
494
419
  end # class LogStash::Inputs::RemoteProc
495
420
  end # module LogStash::Inputs
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-remote_proc'
3
- s.version = '0.0.22'
4
- s.licenses = ['Apache License (2.0)']
3
+ s.version = '0.0.23'
4
+ s.licenses = ['Apache-2.0']
5
5
  s.summary = 'This Logstash plugin collects PROCFS metrics through remote SSH servers.'
6
6
  s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
7
7
  s.authors = ['Christian Kakesa']
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency 'logstash-core', '>= 2.0.0'
30
30
  s.add_runtime_dependency 'logstash-codec-plain', '>= 3.0.2'
31
31
  s.add_runtime_dependency 'net-ssh', '~> 2.9', '>= 2.9.2'
32
- s.add_runtime_dependency 'net-ssh-multi', '~>1.2', '>= 1.2.1'
32
+ s.add_runtime_dependency 'net-ssh-gateway', '~> 1.2', '>= 1.2.0'
33
33
  s.add_runtime_dependency 'stud', '~> 0.0', '>= 0.0.22'
34
34
  s.add_development_dependency 'logstash-devutils', '>= 1.1.0'
35
35
  end
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
2
  require 'logstash/devutils/rspec/spec_helper'
3
3
  require 'logstash/inputs/remote_proc'
4
- require 'net/ssh/multi'
4
+ require 'net/ssh'
5
+ require 'net/ssh/gateway'
5
6
 
6
7
  describe LogStash::Inputs::RemoteProc do
7
8
  let(:config) do
@@ -14,9 +15,8 @@ describe LogStash::Inputs::RemoteProc do
14
15
  let(:queue) { [] }
15
16
 
16
17
  before do
17
- ssh_session = spy('Net::SSH::Multi')
18
- expect(Net::SSH::Multi).to receive(:start).with(any_args)
19
- .and_return(ssh_session)
18
+ ssh_session = spy('Net::SSH')
19
+ allow(Net::SSH).to receive(:start).with(any_args).and_return(ssh_session)
20
20
  end
21
21
 
22
22
  it_behaves_like 'an interruptible input plugin' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-remote_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -66,8 +66,8 @@ dependencies:
66
66
  version: '1.2'
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 1.2.1
70
- name: net-ssh-multi
69
+ version: 1.2.0
70
+ name: net-ssh-gateway
71
71
  prerelease: false
72
72
  type: :runtime
73
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '1.2'
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: 1.2.1
80
+ version: 1.2.0
81
81
  - !ruby/object:Gem::Dependency
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
@@ -490,7 +490,7 @@ files:
490
490
  - vendor/bundle/jruby/1.9/specifications/rake-11.3.0.gemspec
491
491
  homepage: https://github.com/fenicks/logstash-input-remote_proc
492
492
  licenses:
493
- - Apache License (2.0)
493
+ - Apache-2.0
494
494
  metadata:
495
495
  logstash_plugin: 'true'
496
496
  logstash_group: input