Skip to content

Commit

Permalink
collectors/cpu/cpu - fix want hash, skip needless {} output
Browse files Browse the repository at this point in the history
CHANGELOG.md              - annotated
lib/panoptimon/version.rb - version bump
  • Loading branch information
Eric Wilhelm committed Nov 20, 2013
1 parent e39625e commit b2ce887
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.4.9

* collectors/cpu - portable vmstat, skip wait if missing

# 0.4.8

Expand Down
7 changes: 4 additions & 3 deletions collectors/cpu/cpu
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ $stdout.sync = true # persistent process
require 'json'
opt = ARGV[0] ? JSON::parse(ARGV[0]) : {'interval' => 1}

# TODO skip header line in parsing. (Whenever the header line is printed, pan
# will emit a {}.)
p = IO.popen([*%w{vmstat}, opt['interval'].to_s], 'r')
p.readline # scrap
optional = {stolen: 'st', wait: 'wa'}
want = {user: 'us', system: 'sy', idle: 'id'}.
merge(optional)

# index the header
head = p.readline.chomp.sub(/^\s+/, '').split(/\s+/)
Expand All @@ -34,6 +34,7 @@ while l = p.readline.sub(/^\s+/, '')
Hash[*outs.keys.map {|k| [k, l[outs[k]]]}.flatten]
)
else
puts '{}'
# TODO verify that this is a header line and not something strange
# puts '{}'
end
end
2 changes: 1 addition & 1 deletion lib/panoptimon/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (C) 2012 Sourcefire, Inc.

module Panoptimon
VERSION = "0.4.8"
VERSION = "0.4.9"
end

0 comments on commit b2ce887

Please sign in to comment.