Skip to content

Instantly share code, notes, and snippets.

@KCCat
Last active July 31, 2020 17:26
Show Gist options
  • Select an option

  • Save KCCat/e55d05f60a6f7b5dcf0019f5301fd268 to your computer and use it in GitHub Desktop.

Select an option

Save KCCat/e55d05f60a6f7b5dcf0019f5301fd268 to your computer and use it in GitHub Desktop.

Revisions

  1. KCCat revised this gist Jul 31, 2020. 1 changed file with 97 additions and 40 deletions.
    137 changes: 97 additions & 40 deletions spectrwm_status_ber.py
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,104 @@
    #!/usr/bin/env python3

    from time import sleep
    from time import sleep, strftime, localtime
    from sys import stdout
    from os import statvfs

    #import time, sys

    def amdgpu():
    from pathlib import Path

    def hwmon():
    _hwmon = list(Path('/sys/class/hwmon/').iterdir())
    _hwmon.sort()
    return "|".join("|".join([reader(x) for x in _hwmon if x.is_dir()]).split('||'))

    def reader(hwmon_path):
    hwmon_name = hwmon_path / 'name'
    if hwmon_name.exists():
    with hwmon_name.open() as r:
    _name = r.read().split('\n')[0]
    if _name == 'amdgpu':
    return amdgpu(hwmon_path)
    if _name == 'zenpower':
    return zenpower(hwmon_path)
    if _name == 'nct6797':
    return nct6797(hwmon_path)
    if _name == 'nvme':
    return nvme(hwmon_path)
    return ''

    def amdgpu(hwmon_path):
    #/sys/class/drm/card0/device/hwmon/hwmon0/power1_average
    #/sys/class/drm/card0/device/hwmon/hwmon0/fan1_input
    #/sys/class/drm/card0/device/hwmon/hwmon0/temp1_input
    #/sys/class/drm/card0/device/hwmon/hwmon0/in0_input
    #/sys/class/drm/card0/device/hwmon/hwmon0/freq1_input
    #/sys/class/drm/card0/device/pp_dpm_sclk
    card = '/sys/class/drm/card0/device/'
    with open(card + 'pp_dpm_sclk') as r:
    sclk = r.read().split(' *')[0].split('\n')[-1]
    #/sys/class/drm/card0/device/gpu_busy_percent
    with open(hwmon_path / 'device' / 'gpu_busy_percent') as r:
    use = r.read().split('\n')[0]

    with open(card + 'hwmon/hwmon0/temp1_input') as r:
    with open(hwmon_path / 'freq1_input') as r:
    sclk = r.read()[:-7]

    with open(hwmon_path / 'freq2_input') as r:
    mclk = r.read()[:-7]

    with open(hwmon_path / 'temp1_input') as r:
    temp = r.read()[:-4]

    with open(card + 'hwmon/hwmon0/fan1_input') as r:
    with open(hwmon_path / 'temp2_input') as r:
    temp_j = r.read()[:-4]

    with open(hwmon_path / 'temp3_input') as r:
    temp_mem = r.read()[:-4]

    with open(hwmon_path / 'fan1_input') as r:
    fan = r.read()[:-1]

    with open(card + 'hwmon/hwmon0/power1_average') as r:
    with open(hwmon_path / 'power1_average') as r:
    power = r.read()[:-7]

    with open(card + 'hwmon/hwmon0/in0_input') as r:
    with open(hwmon_path / 'in0_input') as r:
    vu = r.read()[:-1]

    return 'AMDGPU %10s%3s°c %4sRPM %4smV %3sW' % (sclk, temp, fan, vu, power)
    return 'GPU%3s%%%4sMhz%4sMhz%3s°c%3s°c%3s°c %4sRPM%4smV%3sW' % (use, sclk, mclk, temp, temp_j, temp_mem, fan, vu, power)

    def zenpower(hwmon_path):
    with open(hwmon_path / 'temp1_input') as r: #Tdie
    die = r.read()[:-4]
    # with open(hwmon_path / 'temp2_input') as r: #Tctl
    # ctl = r.read()[:-4]
    with open(hwmon_path / 'temp3_input') as r: #Tccd1
    ccd1 = r.read()[:-4]
    with open(hwmon_path / 'temp4_input') as r: #Tccd2
    ccd2 = r.read()[:-4]
    with open(hwmon_path / 'power1_input') as r: #core_power
    core = r.read()[:-7]
    with open(hwmon_path / 'power2_input') as r: #soc_power
    soc = r.read()[:-7]
    return 'CPU DIE%3s°c CCD%3s°c%3s°c%3sW%3sW' % (die, ccd1, ccd2, core, soc)

    def nct6797(hwmon_path):
    with open(hwmon_path / 'temp3_input') as r:
    mosin = r.read()[:-4]
    with open(hwmon_path / 'temp5_input') as r:
    pchin = r.read()[:-4]
    with open(hwmon_path / 'fan2_input') as r:
    cpufan = r.read()[:-1]
    with open(hwmon_path / 'fan1_input') as r:
    fan1 = r.read()[:-1]
    return 'MOS%3s°c PCH%3s°c%4s/%4sRPM' % (mosin, pchin, cpufan, fan1,)

    def nvme(hwmon_path):
    with open(hwmon_path / 'temp1_input') as r:
    nvme_in = r.read()[:-4]
    return 'NVME%3s°c' % (nvme_in, )




    '''
    def net():
    #/sys/class/net/enp24s0/statistics/rx_bytes
    @@ -54,9 +124,9 @@ def net():
    '''
    def net():
    #/sys/class/net/enp24s0/statistics/rx_bytes
    #/sys/class/net/enp24s0/statistics/tx_bytes
    #/sys/class/net/enp24s0/statistics/rx_bytes
    b = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'NaN']
    card = '/sys/class/net/enp24s0/statistics/'
    card = '/sys/class/net/enp39s0/statistics/'
    o_rx = o_tx = 0
    while 1:
    with open(card + 'rx_bytes') as r:
    @@ -72,34 +142,21 @@ def net():
    yield '↓%5.2f%4s ↑%5.2f%4s' % (h[0], b[p[0]], h[1], b[p[1]])
    o_rx = rx; o_tx = tx

    def Ryzen():
    #/sys/class/hwmon/hwmon2/
    cpu = '/sys/class/hwmon/hwmon2/'
    with open(cpu + 'temp1_input') as r:
    sysin = r.read()[:-4]
    with open(cpu + 'temp2_input') as r:
    cpuin = r.read()[:-4]
    with open(cpu + 'fan2_input') as r:
    cpufan = r.read()[:-1]
    with open(cpu + 'fan3_input') as r:
    fan1 = r.read()[:-1]
    with open(cpu + 'fan4_input') as r:
    fan2 = r.read()[:-1]
    with open(cpu + 'fan5_input') as r:
    fan3 = r.read()[:-1]
    return 'Ryzen%3s°c SYS%3s°c %4s/%4s/%4s/%4sRPM' % (cpuin, sysin, cpufan, fan1, fan2, fan3)


    def disk(path):
    b = ['B', 'K', 'M', 'G', 'T']
    root = statvfs(path)
    root_f = root.f_bavail * root.f_bsize
    root_n = len(str(root_f))//3
    root_h = root_f/pow(1024, root_n)
    return '%s:%5.2f%s' % ('/'+path.split('/')[-1], root_h, b[root_n])
    #def disk(path):
    # b = ['B', 'K', 'M', 'G', 'T']
    # root = statvfs(path)
    # root_f = root.f_bavail * root.f_bsize
    # root_n = len(str(root_f))//3
    # root_h = root_f/pow(1024, root_n)
    # return '%s:%5.2f%s' % ('/'+path.split('/')[-1], root_h, b[root_n])

    r_net = net()
    while 1:
    stdout.write('| %s| %s| %s| %s|\n' % (next(r_net), Ryzen(), amdgpu(), disk('/')))
    stdout.flush()
    sleep(1)
    def loop():
    r_net = net()
    while True:
    stdout.write('|%s|%s|%s \n' % (next(r_net), hwmon(), strftime("%Y-%m-%d %H:%M", localtime()) ))
    stdout.flush()
    sleep(1)

    loop()
  2. KCCat created this gist Oct 25, 2018.
    105 changes: 105 additions & 0 deletions spectrwm_status_ber.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    #!/usr/bin/env python3

    from time import sleep
    from sys import stdout
    from os import statvfs

    #import time, sys

    def amdgpu():
    #/sys/class/drm/card0/device/hwmon/hwmon0/power1_average
    #/sys/class/drm/card0/device/hwmon/hwmon0/fan1_input
    #/sys/class/drm/card0/device/hwmon/hwmon0/temp1_input
    #/sys/class/drm/card0/device/hwmon/hwmon0/in0_input
    #/sys/class/drm/card0/device/pp_dpm_sclk
    card = '/sys/class/drm/card0/device/'
    with open(card + 'pp_dpm_sclk') as r:
    sclk = r.read().split(' *')[0].split('\n')[-1]

    with open(card + 'hwmon/hwmon0/temp1_input') as r:
    temp = r.read()[:-4]

    with open(card + 'hwmon/hwmon0/fan1_input') as r:
    fan = r.read()[:-1]

    with open(card + 'hwmon/hwmon0/power1_average') as r:
    power = r.read()[:-7]

    with open(card + 'hwmon/hwmon0/in0_input') as r:
    vu = r.read()[:-1]

    return 'AMDGPU %10s%3s°c %4sRPM %4smV %3sW' % (sclk, temp, fan, vu, power)
    '''
    def net():
    #/sys/class/net/enp24s0/statistics/rx_bytes
    #/sys/class/net/enp24s0/statistics/rx_bytes
    b = ['B/s', 'KB/s', 'MB/s', 'GB/s']
    card = '/sys/class/net/enp24s0/statistics/'
    o_rx = [0]*5
    o_tx = [0]*5
    while 1:
    with open(card + 'rx_bytes') as r:
    rx = int(r.read())
    with open(card + 'tx_bytes') as r:
    tx = int(r.read())
    l = [(rx - o_rx.pop())//5, (tx - o_tx.pop())//5]
    p = [len(str(x))//3 for x in l]
    n = zip(l, p)
    h = [x[0]/pow(1024, x[1]) for x in n]
    yield '[↓%5.2f%4s ↑%5.2f%4s]' % (h[0], b[p[0]], h[1], b[p[1]])
    o_rx.insert(0, rx)
    o_tx.insert(0, tx)
    '''
    def net():
    #/sys/class/net/enp24s0/statistics/rx_bytes
    #/sys/class/net/enp24s0/statistics/tx_bytes
    b = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'NaN']
    card = '/sys/class/net/enp24s0/statistics/'
    o_rx = o_tx = 0
    while 1:
    with open(card + 'rx_bytes') as r:
    rx = int(r.read())

    with open(card + 'tx_bytes') as r:
    tx = int(r.read())

    l = [rx - o_rx, tx - o_tx]
    p = [min(len(str(x))//3, 4) for x in l]
    n = zip(l, p)
    h = [x[0]/pow(1024, x[1]) for x in n]
    yield '↓%5.2f%4s ↑%5.2f%4s' % (h[0], b[p[0]], h[1], b[p[1]])
    o_rx = rx; o_tx = tx

    def Ryzen():
    #/sys/class/hwmon/hwmon2/
    cpu = '/sys/class/hwmon/hwmon2/'
    with open(cpu + 'temp1_input') as r:
    sysin = r.read()[:-4]
    with open(cpu + 'temp2_input') as r:
    cpuin = r.read()[:-4]
    with open(cpu + 'fan2_input') as r:
    cpufan = r.read()[:-1]
    with open(cpu + 'fan3_input') as r:
    fan1 = r.read()[:-1]
    with open(cpu + 'fan4_input') as r:
    fan2 = r.read()[:-1]
    with open(cpu + 'fan5_input') as r:
    fan3 = r.read()[:-1]
    return 'Ryzen%3s°c SYS%3s°c %4s/%4s/%4s/%4sRPM' % (cpuin, sysin, cpufan, fan1, fan2, fan3)

    def disk(path):
    b = ['B', 'K', 'M', 'G', 'T']
    root = statvfs(path)
    root_f = root.f_bavail * root.f_bsize
    root_n = len(str(root_f))//3
    root_h = root_f/pow(1024, root_n)
    return '%s:%5.2f%s' % ('/'+path.split('/')[-1], root_h, b[root_n])

    r_net = net()
    while 1:
    stdout.write('| %s| %s| %s| %s|\n' % (next(r_net), Ryzen(), amdgpu(), disk('/')))
    stdout.flush()
    sleep(1)