city-watch 0.3.0 → 0.3.1

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.
@@ -9,17 +9,18 @@ class MPstat
9
9
  end
10
10
 
11
11
  def data
12
+ headers = false
12
13
  command_output.split("\n").map {|line| line.split("\s") }.inject([]) do |output,line|
13
14
  if line[1] == "CPU"
14
15
  headers = line.map {|hdr| hdr.gsub(/%/,'').to_sym}
15
- next
16
+ headers[0] = :run
17
+ elsif headers
18
+ pkt = {}
19
+ line.each_with_index do |itm,idx|
20
+ pkt[headers[idx]] = itm
21
+ end
22
+ output << pkt
16
23
  end
17
- next unless headers
18
- pkt = {}
19
- line.each_with_index do |itm,idx|
20
- pkt[headers[idx]] = itm
21
- end
22
- output << pkt
23
24
  output
24
25
  end
25
26
  end
@@ -10,22 +10,20 @@ class PS
10
10
 
11
11
  def data
12
12
  headers = false
13
- output = []
14
- command_output.split("\n").map {|line| line.split("\s") }.each do |line|
13
+ command_output.split("\n").map {|line| line.split("\s") }.inject([]) do |output,line|
15
14
  if !headers
16
15
  headers = line.map {|hdr| hdr.downcase.to_sym}
17
- next
16
+ else
17
+ pkt = {}
18
+ cmd = line.slice!(10,line.size-1)
19
+ line << cmd.join(" ")
20
+ line.each_with_index do |itm,idx|
21
+ pkt[headers[idx]] = itm
22
+ end
23
+ output << pkt
18
24
  end
19
- next unless headers
20
- pkt = {}
21
- cmd = line.slice!(10,line.size-1)
22
- line << cmd.join(" ")
23
- line.each_with_index do |itm,idx|
24
- pkt[headers[idx]] = itm
25
- end
26
- output << pkt
25
+ output
27
26
  end
28
- output
29
27
  end
30
28
 
31
29
  end
@@ -4,7 +4,7 @@ class CPUUsage
4
4
 
5
5
  def self.data
6
6
  out = MPstat.data.select do |line|
7
- line[:command][/^Average:/]
7
+ line[:run][/^Average:/]
8
8
  end
9
9
  out.length > 0 ? out.first.merge({:summary => [:usr, :idle, :sys]}) : {:nodata => true}
10
10
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CityWatch
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: city-watch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bragg