Skip to content

Commit

Permalink
v0.5.1 - disk-portability
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Wilhelm committed Jan 4, 2014
2 parents 2064db3 + 1345c47 commit dc288f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.1

* collectors/disk - solaris portability

# 0.5.0

* collector.rb - make panoptimon available in $RUBYLIB
Expand Down
38 changes: 29 additions & 9 deletions collectors/disk/disk
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
#!/usr/bin/env ruby
# Copyright (C) 2012-2014 Cisco, Inc.

require 'json'
require 'rubygems'
require 'ostruct'

require 'panoptimon/util'

config = ARGV[0] ? JSON::parse(ARGV[0]) : {'interval' => 60}

$stdout.sync = true

def GB b; (b.to_f / 1024**3).round(6); end # GB significant down to 4kB

def get_mounts
mount_hash = {}
mounts = File.open("/etc/mtab", "r").read.split("\n").map{|l| l.split(/\s+/)}
mounts.each{|m| mount_hash[m[1]] = m[0] unless %w[devpts udev sysfs tmpfs none proc].include?(m[0])}
mount_hash
end
class Array; def to_h; Hash[self]; end; end

get_mounts = ->() {
skip = %w[devpts udev sysfs tmpfs none proc cgroup swap lxproc objfs ctfs lofs
].map {|t| [t,true]}.to_h
Panoptimon::Util.os(
linux: ->() {
->() {
mounts = File.open("/etc/mtab", "r").read.split("\n").
map{|l| x = l.split(/\s+/); [x[1], x[0]]}.to_h.
keep_if {|k,v| not(skip[v])}
}
},
solaris: ->() {
->() {
mounts = File.open("/etc/mnttab", "r").read.split("\n").
map{|l| x = l.split(/\s+/); [x[1], x[0], x[2]]}.
keep_if {|p| not(skip[p[1]]) and not(skip[p[2]])}.
map {|p| [p[0], p[1]]}.to_h
}
},
)

}[]

def stat_fs (mounts)
s = %x[stat --printf="%n %s %b %f %a %c %d\n" -f #{mounts.keys.join(' ')}].split("\n")
s = %x[stat --printf="%n %S %b %f %a %c %d\n" -f #{mounts.keys.join(' ')}].split("\n")
s.map!{|l| l.split}
s.map{|l|
OpenStruct.new(
Expand All @@ -34,7 +54,7 @@ def stat_fs (mounts)
end

while(true) do
mounts = get_mounts
mounts = get_mounts[]
stats = stat_fs(mounts).select{|m| m.blocks > 0}
info = stats.map{ |s|
[s.name, {
Expand Down
4 changes: 2 additions & 2 deletions lib/panoptimon/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (C) 2012-2013 Sourcefire, Inc.
# Copyright (C) 2012-2014 Cisco, Inc.

module Panoptimon
VERSION = "0.5.0"
VERSION = "0.5.1"
end

0 comments on commit dc288f5

Please sign in to comment.