Skip to content

Instantly share code, notes, and snippets.

@flyser
Created April 11, 2014 11:34
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 flyser/10460624 to your computer and use it in GitHub Desktop.
Save flyser/10460624 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
filename = "/var/tmp/test"
interval = 10
targetsize = 2*1000*1000*1000*1000 # 2 TB
import os, time, datetime
file = os.open(filename, os.O_RDONLY)
startsize = os.lseek(file, 0, os.SEEK_END)
lastsize = startsize
starttime = time.perf_counter()
lasttime = starttime
time.sleep(interval/10)
while True:
currentsize = os.lseek(file, 0, os.SEEK_END)
currenttime = time.perf_counter()
print("{:.1f} kByte/s,\t".format((currentsize-lastsize)/1024/(currenttime-lasttime)), end="")
# print("written {} Byte,\t".format(currentsize), end="")
# print("remaining {} Byte,\t".format(targetsize-currentsize), end="")
print("avg {:.1f} kByte/s,\t".format((currentsize-startsize)/1024/(currenttime-starttime)), end="")
try:
seconds = (targetsize-currentsize)/((currentsize-startsize)/(currenttime-starttime))
if seconds < 0:
raise Exception()
eta = datetime.timedelta(seconds=int(seconds))
print("ETA {}".format(eta))
except:
print("ETA inf")
lastsize = currentsize
lasttime = currenttime
time.sleep(interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment