[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: https://www.tarsnap.com/faq.html#out-of-money



Hi

"Amar via tarsnap-users" <tarsnap-users@tarsnap.com> wrote:
> Does that monthly report also has the information — how many days
> worth of balance is left?

From our "Works for me" dept., here's an awk script that will parse
the accounting file available from the tarsnap website and give you a
basic view of current daily costs per machine, current balance,
current daily cost, current projected annual cost and estimated days
left. (I emphasise basic and estimated.)

Download the accounting file for all machines from your account page.
You'll find the most recent date for which there are data with:

	$ tail accounting.csv

then run the script with something like:

	$ awk -f tarlog.awk -v date='2020-08-04' accounting.csv

(You can pass it any date in the file; useful for comparison.)

Output *should* look something like:

------------------------------------------------------------------------
bar                 Daily storage                 0.00350555763745946398
foo                 Daily storage                 0.00159967441795359593
bar                 Client->Server bandwidth      0.00080421500000000005
foo                 Client->Server bandwidth      0.00067914025000000004
baz                 Daily storage                 0.00011826084488202000
foo                 Server->Client bandwidth      0.00011541725000000000
baz                 Client->Server bandwidth      0.00000671400000000000
bar                 Server->Client bandwidth      0.00000584100000000000
baz                 Server->Client bandwidth      0.00000064350000000000
------------------------------------------------------------------------
Balance: $11.60 | Daily: $0.01 | Annual: $2.49 | Days left: 1697

There is no warranty. :)

---- paste begin ----

function nodate(n) {
	if(date == "") {
		exit(n)
	}
}

function rule(r) {
	while(r++ < 72) {
		printf("-")
	}
	printf("\n")
}

BEGIN {
	nodate(0)
	FS = ","
	rule(r)
}

{
	host = substr($3, 1, 19)
	if($0 ~ date && /Balance/) {
		balance = $NF
	}
	if($0 ~ date && !/Balance/) {
		printf("%-20s%-26s%26.20f\n",
			host, $4, $6) | "sort -nr -k4"
		daily += $6
	}
}

END {
	nodate(1)
	close("sort -nr -k4")
	rule(r)
	printf("Balance: $%.2f | ", balance)
	printf("Daily: $%.2f | ", daily)
	printf("Annual: $%.2f | ", daily * 365)
	printf("Days left: %.0f\n", balance / daily)
}

---- paste end ----