Skip to content

Commit

Permalink
Sys flush
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemartinlogan committed Mar 29, 2024
1 parent 10125f6 commit 996dc76
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/pymonitor
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import json
import os

os.environ['PYTHONBUFFERED'] = '0'


if len(sys.argv) != 3:
print('USAGE: pymonitor [frequency] [directory]')
exit(1)
Expand Down Expand Up @@ -80,6 +82,7 @@ cur_time = 0
with open(path, 'w') as fp:
while True:
print(f'Monitoring on {host} at {cur_time}')
sys.stdout.flush()
cpu_usage = psutil.cpu_percent()
mem_usage = psutil.virtual_memory()
network_usage = psutil.net_io_counters()
Expand All @@ -99,6 +102,7 @@ with open(path, 'w') as fp:
fp.write(net_log_to_yaml(cur_time, network_usage))
fp.write(mem_log_to_yaml(cur_time, mem_usage))
fp.write(cpu_log_to_yaml(cur_time, cpu_usage))
fp.flush()
time.sleep(frequency)
cur_time += frequency

0 comments on commit 996dc76

Please sign in to comment.