Created
April 11, 2014 11:34
-
-
Save flyser/10460624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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