Use new psutil API in ps module

This commit is contained in:
Weilu Jia 2015-04-30 18:11:23 -07:00
parent e48982ff9c
commit f8edf72f98

View file

@ -126,10 +126,10 @@ def top(num_processes=5, interval=3):
'''
result = []
start_usage = {}
for pid in psutil.get_pid_list():
for pid in psutil.pid_list():
try:
process = psutil.Process(pid)
user, system = process.get_cpu_times()
user, system = process.cpu_times()
except psutil.NoSuchProcess:
continue
start_usage[process] = user + system
@ -137,7 +137,7 @@ def top(num_processes=5, interval=3):
usage = set()
for process, start in start_usage.items():
try:
user, system = process.get_cpu_times()
user, system = process.cpu_times()
except psutil.NoSuchProcess:
continue
now = user + system
@ -159,9 +159,9 @@ def top(num_processes=5, interval=3):
'cpu': {},
'mem': {},
}
for key, value in process.get_cpu_times()._asdict().items():
for key, value in process.cpu_times()._asdict().items():
info['cpu'][key] = value
for key, value in process.get_memory_info()._asdict().items():
for key, value in process.memory_info()._asdict().items():
info['mem'][key] = value
result.append(info)
@ -178,7 +178,7 @@ def get_pid_list():
salt '*' ps.get_pid_list
'''
return psutil.get_pid_list()
return psutil.pid_list()
def proc_info(pid, attrs=None):
@ -538,7 +538,7 @@ def boot_time(time_format=None):
except AttributeError:
# get_boot_time() has been removed in newer psutil versions, and has
# been replaced by boot_time() which provides the same information.
b_time = int(psutil.get_boot_time())
b_time = int(psutil.boot_time())
if time_format:
# Load epoch timestamp as a datetime.datetime object
b_time = datetime.datetime.fromtimestamp(b_time)
@ -604,7 +604,7 @@ def get_users():
salt '*' ps.get_users
'''
try:
recs = psutil.get_users()
recs = psutil.users()
return [dict(x._asdict()) for x in recs]
except AttributeError:
# get_users is only present in psutil > v0.5.0