Skip to content

Instantly share code, notes, and snippets.

@dadatuputi
Created May 8, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadatuputi/0a189dd05cf47b49e69cde0c27ccce40 to your computer and use it in GitHub Desktop.
Save dadatuputi/0a189dd05cf47b49e69cde0c27ccce40 to your computer and use it in GitHub Desktop.
95th Percentile Logger
#!/usr/bin/env python3
import time
iface = 'enp1s0f0'
log = '95.log'
poll_interval = 1
bytes_in = '/sys/class/net/{}/statistics/rx_bytes'.format(iface)
bytes_out = '/sys/class/net/{}/statistics/tx_bytes'.format(iface)
last_in = 0
last_out = 0
while True:
with open(bytes_in) as f:
bytes_in_new = int(f.readline())
with open(bytes_out) as f:
bytes_out_new = int(f.readline())
if not last_in:
last_in = bytes_in_new
last_out = bytes_out_new
continue
bytes_in_diff = bytes_in_new - last_in
bytes_out_diff = bytes_out_new - last_out
last_in = bytes_in_new
last_out = bytes_out_new
with open(log, 'a') as l:
l.writelines('{},{},{}\n'.format(int(time.time()),bytes_in_diff,bytes_out_diff))
time.sleep(poll_interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment