title: Reliably monitor current CPU usage
body: <p>I'd like to monitor the current system-wide CPU usage on a Mac with Python.</p>
  
  <p>I've written some code that starts 'ps', and adds up all the values from the '%cpu' column.</p>
  
  <pre><code>def psColumn(colName):
      """Get a column of ps output as a list"""
      ps = subprocess.Popen(["ps", "-A", "-o", colName], stdout=subprocess.PIPE)
      (stdout, stderr) = ps.communicate()
      column = stdout.split("\n")[1:]
      column = [token.strip() for token in column if token != '']
      return column
  
  def read(self):
      values = map(float, psColumn("%cpu"))
      return sum(values)
  </code></pre>
  
  <p>However, I always get high readings from 50% - 80%, probably caused by the measuring program itself. This CPU usage peak does not register on my MenuMeters or other system monitoring programs. How can I get readings which are more like what MenuMeters would display? (I want to detect critical situations in which some program is hogging the CPU.)</p>
  
  <p>p.s. I have tried <a href="http://code.google.com/p/psutil/wiki/Documentation" rel="nofollow noreferrer">psutil</a>, but</p>
  
  <pre><code>psutil.cpu_percent()
  </code></pre>
  
  <p>always returns 100%, so either it's useless for me or I am using it wrongly.</p>