【问题标题】:How to get raspberry's stats in python code如何在 python 代码中获取覆盆子的统计信息
【发布时间】:2022-02-07 22:03:08
【问题描述】:

我想在 python 代码中检索我的树莓派的统计信息(内存、存储...),但我找不到方法。一个想法?

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python statistics package


【解决方案1】:

考虑使用psutil 库来帮助您解决此问题。

看看下面我从page逐字复制的代码sn-p:

import psutil

# Get cpu statistics
cpu = str(psutil.cpu_percent()) + '%'

# Calculate memory information
memory = psutil.virtual_memory()
# Convert Bytes to MB (Bytes -> KB -> MB)
available = round(memory.available/1024.0/1024.0,1)
total = round(memory.total/1024.0/1024.0,1)
mem_info = str(available) + 'MB free / ' + str(total) + 'MB total ( ' + str(memory.percent) + '% )'

# Calculate disk information
disk = psutil.disk_usage('/')
# Convert Bytes to GB (Bytes -> KB -> MB -> GB)
free = round(disk.free/1024.0/1024.0/1024.0,1)
total = round(disk.total/1024.0/1024.0/1024.0,1)
disk_info = str(free) + 'GB free / ' + str(total) + 'GB total ( ' + str(disk.percent) + '% )'

print("CPU Info–> ", cpu)
print("Memory Info–>", mem_info)
print("Disk Info–>", disk_info)

【讨论】:

    猜你喜欢
    • 2011-12-18
    • 2023-02-15
    • 2021-09-26
    • 2016-12-24
    • 2023-01-17
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 2011-03-28
    相关资源
    最近更新 更多