Skip to content

Instantly share code, notes, and snippets.

@kmf
Created June 20, 2018 19:23
Show Gist options
  • Save kmf/f4dfc4a50e73d640a56553b4b04419e3 to your computer and use it in GitHub Desktop.
Save kmf/f4dfc4a50e73d640a56553b4b04419e3 to your computer and use it in GitHub Desktop.
How I would like to see processes in OHAI
# Encoding: utf-8
Ohai.plugin(:Processes) do
provides 'processes'
collect_data(:linux) do
processes Mash.new
so = shell_out('ps -axco command,pid,euser')
so.stdout.lines do |line|
case line
when / CMD PID EUSER /
next
else
line = line.split("\s")
info = line.shift(3)
command = info[0]
euser = line.join(' ')
processes[command] = Mash.new
processes[command][:pid] = info[1]
processes[command][:user] = info[2]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment