Skip to content

Instantly share code, notes, and snippets.

@ross-nordstrom
Last active August 29, 2015 14:07
Show Gist options
  • Save ross-nordstrom/65e7d61bc8e34fc0081d to your computer and use it in GitHub Desktop.
Save ross-nordstrom/65e7d61bc8e34fc0081d to your computer and use it in GitHub Desktop.
Get process usage
#!/usr/bin/env ruby
require 'json'
p_main = `ps`
p_all = `ps -a`
users = `who`
data = {
:local => `ps`.split("\n").size - 1,
:tty => `ps a`.split("\n").size - 1,
:non_tty => `ps x`.split("\n").size - 1,
:total => `ps -A`.split("\n").size - 1
}
data[:other] = data[:total] - (data[:local] + data[:tty] + data[:non_tty])
puts data.to_json.gsub(/"/, "'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment