dir = Path[ENV.fetch("PROCIO_DIR", "/proc")] result = {} of String => Array(UInt64) time = Time.utc.to_s("%s%9N") Dir.children(dir).each do |entry| next unless (entry =~ /^\d+$/) && File.directory?(dir/entry) begin comm = File.read("#{dir}/#{entry}/comm").chomp result[comm] ||= [0.to_u64, 0.to_u64] File.read_lines("#{dir}/#{entry}/io").each do |line| if line.starts_with?("read_bytes: ") result[comm][0] += line.split(" ").last.to_u64 elsif line.starts_with?("write_bytes: ") result[comm][1] += line.split(" ").last.to_u64 end end rescue File::NotFoundError # process might already have exited end end result.each do |comm, (r, w)| if r > 0 && w > 0 puts %(procio,comm="#{comm}" read_bytes=#{r},write_bytes=#{w} #{time}) end end