コード例 #1
0
ファイル: system_info.py プロジェクト: rudolph9/dotfiles-1
def _get_memory():
    memory = psutil.virtual_memory()
    return (
        humanize_bytes(memory.used),
        humanize_bytes(memory.total),
        colorize_percent(memory.percent, warning=60, critical=80),
    )
コード例 #2
0
ファイル: system_info.py プロジェクト: keanuplayz/dotfiles
def _get_cpu_usage() -> Optional[str]:
    try:
        percent = cast(float, psutil.cpu_percent())
    except Exception as e:
        print("Error in _get_cpu_usage:", e)
        return None

    return colorize_percent(percent, warning=60, critical=80)
コード例 #3
0
ファイル: system_info.py プロジェクト: rudolph9/dotfiles-1
def _get_battery():
    if not hasattr(psutil, "sensors_battery"):
        return None

    try:
        battery = psutil.sensors_battery()
    except Exception as e:
        print(e)
        return None

    if battery is None:
        return None

    percent = battery.percent
    if battery.power_plugged:
        status = "charging" if percent < 100 else "fully charged"
    else:
        status = "%s left" % humanize_timedelta(timedelta(seconds=battery.secsleft))
    return colorize_percent(percent, critical=10, warning=20, inverse=True), status
コード例 #4
0
ファイル: system_info.py プロジェクト: rudolph9/dotfiles-1
def _get_disks():
    result = []
    for disk in psutil.disk_partitions(all=False):
        if psutil.WINDOWS and ("cdrom" in disk.opts or disk.fstype == ""):
            # skip cd-rom drives with no disk in it on Windows; they may raise
            # ENOENT, pop-up a Windows GUI error for a non-ready partition or
            # just hang
            continue

        usage = psutil.disk_usage(disk.mountpoint)
        result.append(
            (
                disk.mountpoint,
                humanize_bytes(usage.used),
                humanize_bytes(usage.total),
                colorize_percent(usage.percent, warning=70, critical=85),
            )
        )
    return result
コード例 #5
0
ファイル: system_info.py プロジェクト: rudolph9/dotfiles-1
def _get_cpu_usage():
    percent = psutil.cpu_percent()

    return colorize_percent(percent, warning=60, critical=80)