Windows Azure Storage Analytics with PowerShell

Windows Azure Storage Analytics allows you to log very detailed information about how a storage account is being used. Each service (Blob/Table/Queues) has independant settings allowing you to have granular control over what data is collected. To enable/disable each setting just add or omit the argument (-LoggingDelete as an example). One of the great things about this service is the ability to set a retention policy so the data can be automatically deleted after a set number of days.

Enabling Storage Analytics per Service

Set-StorageServicePropertiesForAnalytics -ServiceName "Table" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey `
		-LoggingDelete -LoggingRead -LoggingWrite -MetricsEnabled -MetricsIncludeApis `
		-MetricsRetentionPolicyDays 5 -LoggingRetentionPolicyEnabled -LoggingRetentionPolicyDays 5 `
		-MetricsRetentionPolicyEnabled 
									
Set-StorageServicePropertiesForAnalytics -ServiceName "Queue" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey `
		-LoggingDelete -LoggingRead -LoggingWrite -MetricsEnabled -MetricsIncludeApis `
		-MetricsRetentionPolicyDays 5 -LoggingRetentionPolicyEnabled -LoggingRetentionPolicyDays 5 `
		-MetricsRetentionPolicyEnabled 
									
Set-StorageServicePropertiesForAnalytics -ServiceName "Blob" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey `
		-LoggingDelete -LoggingRead -LoggingWrite -MetricsEnabled -MetricsIncludeApis `
		-MetricsRetentionPolicyDays 5 -LoggingRetentionPolicyEnabled -LoggingRetentionPolicyDays 5 `
		-MetricsRetentionPolicyEnabled 		

Retrieving the Current Storage Analytics Settings

	Get-StorageServicePropertiesForAnalytics -ServiceName "Table" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey | Format-List
	
	Get-StorageServicePropertiesForAnalytics -ServiceName "Blob" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey | Format-List
		
	Get-StorageServicePropertiesForAnalytics -ServiceName "Queue" `
		-StorageAccountName $storageAccount -StorageAccountKey $storagekey | Format-List

Downloading the storage analytics data requires a bit more explanation. Each service has two fundamental types of data (except blob storage which has 3). The two are log data which contains all of the requests for that service (depending on which settings you have enabled) and transactions. Transactions contains numerous metrics that give you a deep understanding of how the storage service is performing. Metrics such as % Success or Avg E2E Latency are extremely useful for understanding your application. Blob storage also has a “Capacity” set of data that will tell you how much storage space blob storage is using broken down by analytics and application data.

Downloading Storage Analytics Data

Get-StorageAnalyticsLogs -ServiceName "Blob" `
	-LocalPath "c:\DiagData\SALogsBlob.log"  `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey  

Get-StorageAnalyticsMetrics -DataType "Capacity" -ServiceName "Blob" `
    -LocalPath "c:\DiagData\SAMetricsBlob-Capacity.log" `
    -StorageAccountName $storageAccount -StorageAccountKey $storagekey 
						 
Get-StorageAnalyticsMetrics -DataType "Transactions" -ServiceName "Blob" `
	-LocalPath "c:\DiagData\SAMetricsBlob-Transactions.log" `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey 

Get-StorageAnalyticsLogs -ServiceName "Table" `
	-LocalPath "c:\DiagData\SALogsTable.log"  `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey  
						 
Get-StorageAnalyticsMetrics -DataType "Transactions" -ServiceName "Table" `
	-LocalPath "c:\DiagData\SAMetricsTable-Transactions.log" `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey 

Get-StorageAnalyticsLogs -ServiceName "Queue" `
	-LocalPath "c:\DiagData\SALogsQueue.log" `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey  
						 
Get-StorageAnalyticsMetrics -DataType "Transactions" -ServiceName "Queue" `
	-LocalPath "c:\DiagData\SAMetricsQueue-Transactions.log" `
	-StorageAccountName $storageAccount -StorageAccountKey $storagekey 

For more information on storage analytics and details on understanding the metrics you can use see the following:
http://msdn.microsoft.com/en-us/library/windowsazure/hh343268.aspx