commit d96fb7afa4fa2c667aeb117e8f869e5fec0ec6b5 Author: mwiegand Date: Fri Nov 5 18:47:34 2021 +0100 initial commit diff --git a/procio.cr b/procio.cr new file mode 100644 index 0000000..0a90def --- /dev/null +++ b/procio.cr @@ -0,0 +1,26 @@ +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 diff --git a/test/12/comm b/test/12/comm new file mode 100644 index 0000000..08262c6 --- /dev/null +++ b/test/12/comm @@ -0,0 +1 @@ +multi diff --git a/test/12/io b/test/12/io new file mode 100644 index 0000000..259822e --- /dev/null +++ b/test/12/io @@ -0,0 +1,7 @@ +rchar: 0 +wchar: 0 +syscr: 0 +syscw: 0 +read_bytes: 100000 +write_bytes: 0 +cancelled_write_bytes: 0 diff --git a/test/13/comm b/test/13/comm new file mode 100644 index 0000000..08262c6 --- /dev/null +++ b/test/13/comm @@ -0,0 +1 @@ +multi diff --git a/test/13/io b/test/13/io new file mode 100644 index 0000000..d7eae47 --- /dev/null +++ b/test/13/io @@ -0,0 +1,7 @@ +rchar: 0 +wchar: 0 +syscr: 0 +syscw: 0 +read_bytes: 100000 +write_bytes: 100000 +cancelled_write_bytes: 0 diff --git a/test/3/comm b/test/3/comm new file mode 100644 index 0000000..0002afd --- /dev/null +++ b/test/3/comm @@ -0,0 +1 @@ +nothinghere diff --git a/test/3/io b/test/3/io new file mode 100644 index 0000000..13c30d4 --- /dev/null +++ b/test/3/io @@ -0,0 +1,7 @@ +rchar: 0 +wchar: 0 +syscr: 0 +syscw: 0 +read_bytes: 0 +write_bytes: 0 +cancelled_write_bytes: 0 diff --git a/test/452/comm b/test/452/comm new file mode 100644 index 0000000..b07899f --- /dev/null +++ b/test/452/comm @@ -0,0 +1 @@ +alotgoingon diff --git a/test/452/io b/test/452/io new file mode 100644 index 0000000..7619268 --- /dev/null +++ b/test/452/io @@ -0,0 +1,7 @@ +rchar: 0 +wchar: 0 +syscr: 0 +syscw: 0 +read_bytes: 82546474 +write_bytes: 34637376 +cancelled_write_bytes: 0