Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Last active December 25, 2015 07:19
Show Gist options
  • Save bahamas10/6938284 to your computer and use it in GitHub Desktop.
Save bahamas10/6938284 to your computer and use it in GitHub Desktop.
Billable amount in Joyent Manta
# Total the billable amount in Manta
mbillable() {
mget -q ~~/reports/usage/storage/latest |\
json storage.public.bytes storage.stor.bytes |\
awk '
{
s += $1;
}
END {
billable = (s / 1024 / 1024 / 1024) + 1;
human = s;
units = "B";
if (s > 1024 * 1024 * 1024 * 1024) {
human = s / 1024 / 1024 / 1024 / 1024;
units = "TB";
} else if (s > 1024 * 1024 * 1024) {
human = s / 1024 / 1024 / 1024;
units = "GB";
} else if (s > 1024 * 1024) {
human = s / 1024 / 1024;
units = "MB";
} else if (s > 1024) {
human = s / 1024;
units = "KB";
}
printf("%s => using %d %s (%d GB billable)\n",
ENVIRON["MANTA_USER"], human, units, billable);
}
'
}
$ mbillable 
bahamas10 => using 133 MB (1 GB billable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment