26 lines
740 B
Crystal
26 lines
740 B
Crystal
dir = ENV.fetch("PROCIO_DIR", "/proc")
|
|
hostname = ENV.fetch("PROCIO_HOSTNAME", "/proc")
|
|
result = {} of String => Hash(Symbol, UInt64)
|
|
|
|
Dir.entries(dir).each do |entry|
|
|
entry =~ /^\d+$/ || next
|
|
|
|
comm = File.read("#{dir}/#{entry}/comm").chomp
|
|
result[comm] ||= {r: 0.to_u64, w: 0.to_u64}.to_h
|
|
|
|
File.read_lines("#{dir}/#{entry}/io").each do |line|
|
|
if line.starts_with?("read_bytes: ")
|
|
result[comm][:r] += line.split(" ").last.to_u64
|
|
elsif line.starts_with?("write_bytes: ")
|
|
result[comm][:w] += line.split(" ").last.to_u64
|
|
end
|
|
end
|
|
end
|
|
|
|
time = Time.local.to_s("%s%9N")
|
|
|
|
result.each do |comm, v|
|
|
if v[:r] + v[:w] > 0
|
|
puts %(procio comm="#{comm}" read_bytes=#{v[:r]},write_bytes=#{v[:w]} #{time})
|
|
end
|
|
end
|