本文整理汇总了Python中psutil.getloadavg方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.getloadavg方法的具体用法?Python psutil.getloadavg怎么用?Python psutil.getloadavg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.getloadavg方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mon_performance
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def mon_performance():
# get system/CPU load
load1m, _, _ = os.getloadavg()
# get CPU utilization as a percentage
cpuload = p.cpu_percent(interval=1)
print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n")
if cur_turbo == "0":
print("Currently turbo boost is: on")
print("Suggesting to set turbo boost: on")
else:
print("Currently turbo boost is: off")
print("Suggesting to set turbo boost: on")
footer(79)
# set cpufreq based if device is charging
示例2: query_psutil
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def query_psutil() -> Dict:
vm = psutil.virtual_memory()
results = {}
percents = psutil.cpu_percent(interval=None, percpu=True)
if len(percents) > 0:
results["cpu_percent_avg"] = sum(percents) / len(percents)
for (i, percent) in enumerate(percents):
results["cpu_percent_%02d" % (i + 1)] = percent
try:
# psutil <= 5.6.2 did not have getloadavg:
if hasattr(psutil, "getloadavg"):
results["load_avg"] = psutil.getloadavg()[0]
else:
# Do not log an empty metric
pass
except OSError:
pass
results["memory_used"] = vm.used / vm.total
return results
示例3: test_getloadavg
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def test_getloadavg(self):
loadavg = psutil.getloadavg()
self.assertEqual(len(loadavg), 3)
for load in loadavg:
self.assertIsInstance(load, float)
self.assertGreaterEqual(load, 0.0)
示例4: test_getloadavg
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def test_getloadavg(self):
psutil.getloadavg()
self.execute(psutil.getloadavg)
# --- mem
示例5: test_getloadavg
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def test_getloadavg(self):
psutil_value = psutil.getloadavg()
with open("/proc/loadavg", "r") as f:
proc_value = f.read().split()
self.assertAlmostEqual(float(proc_value[0]), psutil_value[0], delta=1)
self.assertAlmostEqual(float(proc_value[1]), psutil_value[1], delta=1)
self.assertAlmostEqual(float(proc_value[2]), psutil_value[2], delta=1)
# =====================================================================
# --- system network
# =====================================================================
示例6: load_avg
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def load_avg(self) -> List[float]:
"""
Get the average load as a vector that represents the load within the last 1, 5 and 15 minutes.
"""
import psutil
return psutil.getloadavg()
示例7: set_powersave
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def set_powersave():
print("Setting to use: \"powersave\" governor")
s.run("cpufreqctl --governor --set=powersave", shell=True)
if (os.path.exists("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference")):
s.run("cpufreqctl --epp --set=balance_power", shell=True)
print("Setting to use: \"balance_power\" EPP")
# get system/CPU load
load1m, _, _ = os.getloadavg()
# get CPU utilization as a percentage
cpuload = p.cpu_percent(interval=1)
print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n")
# conditions for setting turbo in powersave
if load1m > cpus / 7:
print("High load, setting turbo boost: on")
s.run("echo 0 > " + turbo_loc, shell=True)
footer(79)
elif cpuload > 25:
print("High CPU load, setting turbo boost: on")
s.run("echo 0 > " + turbo_loc, shell=True)
footer(79)
else:
print("Load optimal, setting turbo boost: off")
s.run("echo 1 > " + turbo_loc, shell=True)
footer(79)
# make turbo suggestions in powersave
示例8: mon_powersave
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def mon_powersave():
# get system/CPU load
load1m, _, _ = os.getloadavg()
# get CPU utilization as a percentage
cpuload = p.cpu_percent(interval=1)
print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n")
if load1m > cpus / 7:
print("High load, suggesting to set turbo boost: on")
if cur_turbo == "0":
print("Currently turbo boost is: on")
else:
print("Currently turbo boost is: off")
footer(79)
elif cpuload > 25:
print("High CPU load, suggesting to set turbo boost: on")
if cur_turbo == "0":
print("Currently turbo boost is: on")
else:
print("Currently turbo boost is: off")
footer(79)
else:
print("Load optimal, suggesting to set turbo boost: off")
if cur_turbo == "0":
print("Currently turbo boost is: on")
else:
print("Currently turbo boost is: off")
footer(79)
# set performance and enable turbo
示例9: set_performance
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def set_performance():
print("Setting to use \"performance\" governor")
s.run("cpufreqctl --governor --set=performance", shell=True)
if (os.path.exists("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference")):
s.run("cpufreqctl --epp --set=balance_performance", shell=True)
print("Setting to use: \"balance_performance\" EPP")
# get system/CPU load
load1m, _, _ = os.getloadavg()
# get CPU utilization as a percentage
cpuload = p.cpu_percent(interval=1)
print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n")
# conditions for setting turbo in performance
if load1m >= cpus / 5:
print("High load, setting turbo boost: on")
s.run("echo 0 > " + turbo_loc, shell=True)
footer(79)
elif cpuload > 20:
print("High CPU load, setting turbo boost: on")
s.run("echo 0 > " + turbo_loc, shell=True)
footer(79)
else:
print("Load optimal, setting turbo boost: off")
s.run("echo 1 > " + turbo_loc, shell=True)
footer(79)
# make turbo suggestions in performance
示例10: get_cpu_count_adjusted_load_avg
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def get_cpu_count_adjusted_load_avg(*args, **kwargs):
return [x / psutil.cpu_count() for x in psutil.getloadavg()]
示例11: print_header
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def print_header(procs_status, num_procs):
"""Print system-related info, above the process list."""
def get_dashes(perc):
dashes = "|" * int((float(perc) / 10 * 4))
empty_dashes = " " * (40 - len(dashes))
return dashes, empty_dashes
# cpu usage
percs = psutil.cpu_percent(interval=0, percpu=True)
for cpu_num, perc in enumerate(percs):
dashes, empty_dashes = get_dashes(perc)
print_line(" CPU%-2s [%s%s] %5s%%" % (cpu_num, dashes, empty_dashes,
perc))
mem = psutil.virtual_memory()
dashes, empty_dashes = get_dashes(mem.percent)
line = " Mem [%s%s] %5s%% %6s / %s" % (
dashes, empty_dashes,
mem.percent,
str(int(mem.used / 1024 / 1024)) + "M",
str(int(mem.total / 1024 / 1024)) + "M"
)
print_line(line)
# swap usage
swap = psutil.swap_memory()
dashes, empty_dashes = get_dashes(swap.percent)
line = " Swap [%s%s] %5s%% %6s / %s" % (
dashes, empty_dashes,
swap.percent,
str(int(swap.used / 1024 / 1024)) + "M",
str(int(swap.total / 1024 / 1024)) + "M"
)
print_line(line)
# processes number and status
st = []
for x, y in procs_status.items():
if y:
st.append("%s=%s" % (x, y))
st.sort(key=lambda x: x[:3] in ('run', 'sle'), reverse=1)
print_line(" Processes: %s (%s)" % (num_procs, ', '.join(st)))
# load average, uptime
uptime = datetime.datetime.now() - \
datetime.datetime.fromtimestamp(psutil.boot_time())
av1, av2, av3 = psutil.getloadavg()
line = " Load average: %.2f %.2f %.2f Uptime: %s" \
% (av1, av2, av3, str(uptime).split('.')[0])
print_line(line)
示例12: psutil_info
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import getloadavg [as 别名]
def psutil_info():
ps_util_info = {}
for x in psutil.sensors_temperatures(fahrenheit=False):
ps_util_info['cpu_temp_' + x] = psutil.sensors_temperatures(fahrenheit=False)[x][0][1]
#ps_util_info['cpu_temp'] = psutil.sensors_temperatures(fahrenheit=False)['bcm2835_thermal'][0][1]
ps_util_info['cpu_ctx_switches'] = psutil.cpu_stats()[0]
ps_util_info['cpu_interrupts'] = psutil.cpu_stats()[1]
ps_util_info['cpu_soft_interrupts'] = psutil.cpu_stats()[2]
ps_util_info['cpu_frequency'] = psutil.cpu_freq(percpu=False)[0]
ps_util_info['cpu_min_frequency'] = psutil.cpu_freq(percpu=False)[1]
ps_util_info['cpu_max_frequency'] = psutil.cpu_freq(percpu=False)[2]
ps_util_info['load_ave1'] = psutil.getloadavg()[0]
ps_util_info['load_ave5'] = psutil.getloadavg()[1]
ps_util_info['load_ave15'] = psutil.getloadavg()[2]
ps_util_info['vmem_total'] = psutil.virtual_memory()[0]
ps_util_info['vmem_available'] = psutil.virtual_memory()[1]
ps_util_info['vmem_pcent'] = psutil.virtual_memory()[2]
ps_util_info['vmem_used'] = psutil.virtual_memory()[3]
ps_util_info['vmem_free'] = psutil.virtual_memory()[4]
ps_util_info['vmem_active'] = psutil.virtual_memory()[5]
ps_util_info['swap_pcent'] = psutil.swap_memory()[3]
ps_util_info['swap_in'] = psutil.swap_memory()[4]
ps_util_info['swap_out'] = psutil.swap_memory()[5]
ps_util_info['disk_used'] = psutil.disk_usage("/home/")[1]
ps_util_info['disk_free'] = psutil.disk_usage("/home/")[2]
ps_util_info['disk_usage_pcent'] = psutil.disk_usage("/home/")[3]
# Disk In-Out
ps_util_info['disk_read_count'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[0]
ps_util_info['disk_write_count'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[1]
ps_util_info['disk_read_bytes'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[2]
ps_util_info['disk_write_bytes'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[3]
ps_util_info['disk_read_time'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[4]
ps_util_info['disk_write_time'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[5]
ps_util_info['disk_read_merged_count'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[6]
ps_util_info['disk_write_merged_count'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[7]
ps_util_info['disk_busy_time'] = psutil.disk_io_counters(perdisk=False, nowrap=True)[8]
# Net In-Out
ps_util_info['net_bytes_sent'] = psutil.net_io_counters(pernic=False, nowrap=True)[0]
ps_util_info['net_bytes_recv'] = psutil.net_io_counters(pernic=False, nowrap=True)[1]
ps_util_info['net_packets_sent'] = psutil.net_io_counters(pernic=False, nowrap=True)[2]
ps_util_info['net_packets_recv'] = psutil.net_io_counters(pernic=False, nowrap=True)[3]
ps_util_info['net_errin'] = psutil.net_io_counters(pernic=False, nowrap=True)[4]
ps_util_info['net_errout'] = psutil.net_io_counters(pernic=False, nowrap=True)[5]
ps_util_info['net_dropin'] = psutil.net_io_counters(pernic=False, nowrap=True)[6]
ps_util_info['net_dropout'] = psutil.net_io_counters(pernic=False, nowrap=True)[7]
return ps_util_info