bin/instrument_server in instrumental_tools-0.4.1 vs bin/instrument_server in instrumental_tools-0.4.2
- old
+ new
@@ -206,14 +206,14 @@
'swap.free_percent' => (free.to_f / total.to_f) * 100,
}
end
def self.load_disks
- { :gauges => disks.merge(diskstats) }
+ { :gauges => disk_storage.merge(disk_io) }
end
- def self.disks
+ def self.disk_storage
output = {}
`df -Pk`.split("\n").grep(%r{^/dev/}).each do |line|
device, total, used, available, capacity, mount = line.split(/\s+/)
names = [File.basename(device)]
names << 'root' if mount == '/'
@@ -225,29 +225,27 @@
end
end
output
end
- def self.diskstats
- entries = `cat /proc/diskstats`.chomp.split("\n").map do |line|
+ def self.disk_io
+ mounted_devices = `mount`.split("\n").grep(/^\/dev\/(\w+)/) { $1 }
+ diskstats_lines = `cat /proc/diskstats`.split("\n").grep(/#{mounted_devices.join('|')}/)
+ entries = diskstats_lines.map do |line|
values = line.split
entry = {}
- entry[:time] = Time.now
+ entry[:time] = Time.now
entry[:device] = values[2]
- entry[:read] = values[6].to_f
- entry[:write] = values[10].to_f
- entry[:io] = entry[:read] + entry[:write]
+ entry[:utilization] = values[12].to_f
SystemInspector.memory.store("disk_stats_#{entry[:device]}".to_sym, entry)
end
output = {}
entries.each do |entry|
if previous_entry = SystemInspector.memory.retrieve("disk_stats_#{entry[:device]}".to_sym)
time_delta = (entry[:time] - previous_entry[:time]) * 1000
- [:read, :write, :io].each do |type|
- utilization_delta = entry[type] - previous_entry[type]
- output["disk.#{entry[:device]}.#{type}_utilization"] = utilization_delta / time_delta * 100
- end
+ utilization_delta = entry[:utilization] - previous_entry[:utilization]
+ output["disk.#{entry[:device]}.percent_utilization"] = utilization_delta / time_delta * 100
end
end
output
end