Skip to content

Commit

Permalink
Per-cpu monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jul 25, 2024
1 parent 6d60e34 commit 3f3b21c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
def monitor():
with open('cpu.txt', 'a') as f:
while True:
cpu = psutil.cpu_percent(interval=2)
tstamp = datetime.isoformat(datetime.now(), timespec='seconds')
print(f"{tstamp} {round(cpu) * '|'} ({cpu}%)", file=f)
cpus = psutil.cpu_percent(interval=2, percpu=True)
tstamp = datetime.now().strftime('%H:%M:%S')
bars = (
f"{round(cpu / 4) * '|'}{(25 - round(cpu / 4)) * ' '}%"
for cpu in cpus
)
print(f"{tstamp} {' '.join(bars)} {cpus}", file=f)
f.flush()


Expand Down

0 comments on commit 3f3b21c

Please sign in to comment.