Created
November 30, 2012 02:41
-
-
Save analogrelay/4173450 to your computer and use it in GitHub Desktop.
Blob Scanner
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Blob; | |
namespace BlobScanner | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<SNIP>;AccountKey=<SNIP>"); | |
CloudBlobClient client = account.CreateCloudBlobClient(); | |
CloudBlobContainer container = client.GetContainerReference("wad-iis"); | |
// Recursively search each directory and count the size | |
long size = 0; | |
long count = 0; | |
DateTimeOffset now = DateTimeOffset.UtcNow; | |
DateTimeOffset oldest = DateTimeOffset.UtcNow; | |
foreach (ICloudBlob blob in container.ListBlobs(useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Metadata)) | |
{ | |
count++; | |
size += blob.Properties.Length; | |
if (blob.Properties.LastModified.HasValue && blob.Properties.LastModified.Value < oldest) | |
{ | |
oldest = blob.Properties.LastModified.Value; | |
} | |
} | |
var sizePerDay = (size / (now - oldest).TotalDays); | |
Console.WriteLine("Found {0} blobs", count); | |
Console.WriteLine("Size: {0}MB", size / (1024*1024)); | |
Console.WriteLine("Oldest Blob: {0}", oldest.ToLocalTime()); | |
Console.WriteLine("Span in days: {0}", (now - oldest).TotalDays); | |
Console.WriteLine("Size per day: ~{0}MB/day", sizePerDay / (1024 * 1024)); | |
Console.WriteLine("Per month: ~{0}MB/mth", (sizePerDay * 31) / (1024 * 1024)); | |
Console.WriteLine("Per quarter: ~{0}GB/quarter", (sizePerDay * (31 * 3)) / (1024 * 1024 * 1024)); | |
Console.WriteLine("Per half-year: ~{0}GB/halfyear", (sizePerDay * (31 * 6)) / (1024 * 1024 * 1024)); | |
Console.WriteLine("Per year: ~{0}GB/year", (sizePerDay * 365) / (1024 * 1024 * 1024)); | |
Console.WriteLine("Per 5 years: ~{0}GB/5years", (sizePerDay * (365 * 5)) / (1024 * 1024 * 1024)); | |
Console.WriteLine("Cost for 5 years of data storage, geo-redundant: ${0}/mth", ((sizePerDay * (365 * 5)) / (1024 * 1024 * 1024)) * 0.125); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment