def get_cpu_times()

in ambari-metrics-host-monitoring/src/main/python/core/host_info.py [0:0]


  def get_cpu_times(self):
    """
    Return cpu stats at current time
    """
    cpu_times = psutil.cpu_times_percent()
    cpu_count = self.__host_static_info.get('cpu_num', 1)
    # Since only boot time which is a part of static info is not sent with
    # other payload sending it with cpu stats.
    boot_time = self.__host_static_info.get('boottime')

    result = {
      'cpu_num': int(cpu_count),
      'cpu_user': cpu_times.user if hasattr(cpu_times, 'user') else 0,
      'cpu_system': cpu_times.system if hasattr(cpu_times, 'system') else 0,
      'cpu_idle': cpu_times.idle if hasattr(cpu_times, 'idle') else 0,
      'cpu_nice': cpu_times.nice if hasattr(cpu_times, 'nice') else 0,
      'cpu_wio': cpu_times.iowait if hasattr(cpu_times, 'iowait') else 0,
      'cpu_intr': cpu_times.irq if hasattr(cpu_times, 'irq') else 0,
      'cpu_sintr': cpu_times.softirq if hasattr(cpu_times, 'softirq') else 0,
      'cpu_steal': cpu_times.steal if hasattr(cpu_times, 'steal') else 0,
      'boottime': int(boot_time) if boot_time else 0
    }
    if platform.system() != "Windows":
      load_avg = os.getloadavg()
      result.update({
        'load_one' : load_avg[0] if len(load_avg) > 0 else '',
        'load_five' : load_avg[1] if len(load_avg) > 1 else '',
        'load_fifteen' : load_avg[2] if len(load_avg) > 2 else ''
      })
    return result