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.
spectrwm_status_ber.py python3
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment