vidibus-sysinfo 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,20 @@ module Vidibus
13
13
  extend Base
14
14
 
15
15
  class Result < Vidibus::Sysinfo::Result
16
- attrs :user, :nice, :system, :iowait, :irq, :soft, :steal, :guest, :idle, :used
16
+ KEYS = {
17
+ usr: :user,
18
+ user: :user,
19
+ nice: :nice,
20
+ sys: :system,
21
+ system: :system,
22
+ iowait: :iowait,
23
+ irq: :irq,
24
+ soft: :soft,
25
+ steal: :steal,
26
+ guest: :guest,
27
+ idle: :idle
28
+ }
29
+ attrs *KEYS.values.uniq + [:used]
17
30
 
18
31
  def to_i
19
32
  round(used, 0).to_i
@@ -26,24 +39,22 @@ module Vidibus
26
39
 
27
40
  class << self
28
41
  def command
29
- "mpstat 1 5 | grep Average:"
42
+ 'mpstat 1 5'
30
43
  end
31
44
 
45
+ # user system missing
32
46
  def parse(output)
33
- matches = output.scan(/([\d\.]+)/)
34
- if matches.any?
35
- matches.flatten!
36
- data = {
37
- user: matches[0].to_f,
38
- nice: matches[1].to_f,
39
- system: matches[2].to_f,
40
- iowait: matches[3].to_f,
41
- irq: matches[4].to_f,
42
- soft: matches[5].to_f,
43
- steal: matches[6].to_f,
44
- guest: matches[7].to_f,
45
- idle: matches[8].to_f
46
- }
47
+ lines = output.split(/\r?\n/)
48
+ values = lines[-1].scan(/([\d\.]+)/)
49
+ if values.any?
50
+ values.flatten!
51
+ data = {}
52
+ labels = lines[2].scan(/%([^\s]+)/).flatten
53
+ labels.each_with_index do |label, index|
54
+ key = Result::KEYS[label.to_sym]
55
+ next unless key
56
+ data[key] = values[index].to_f
57
+ end
47
58
  data[:used] = round(100.0 - data[:idle])
48
59
  Result.new(data)
49
60
  end
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Sysinfo
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-sysinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-10 00:00:00.000000000 Z
12
+ date: 2014-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 2293815735734862113
148
+ hash: 1223332183346536001
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements: