{"id":5371,"date":"2015-11-07T18:41:19","date_gmt":"2015-11-07T17:41:19","guid":{"rendered":"https:\/\/blog.redbaronofazure.com\/?p=5371"},"modified":"2015-11-08T16:05:31","modified_gmt":"2015-11-08T15:05:31","slug":"azure-storage-monitoring-and-logging","status":"publish","type":"post","link":"https:\/\/blog.redbaronofazure.com\/?p=5371","title":{"rendered":"Azure Storage monitoring and logging"},"content":{"rendered":"<p>Azure Storage is one of the key core infrastructure components that basically all other Azure features rely upon. It is very easy to use since you just create a Storage Account and off you go, but to know how it actually performs, you must switch on what is called monitoring and logging. However, like all monitoring data, you must know what to look for in order to get some value out of it.<\/p>\n<p><strong>Storage Monitoring and Logging basics<\/strong><\/p>\n<p>Storage Monitoring and Logging are built in features in Azure Storage and has been since day 1. You only need to turn them on.<\/p>\n<p><strong>Monitoring <\/strong>is about recording data about capacity and metrics. <strong>Capacity<\/strong> is info about the used space in the account, the number containers (root folders) and objects (files). It is only recorded with a frequence of once a day. This is the data you need to track storage growth.<\/p>\n<p><strong>Metrics<\/strong> is a whole lot of information about how your Storage Account is performing such as availability, average response time, total ingress, total egress, network and throttling errors. The metrics data is recorded in two major different buckets where one is per hour and the other per minute. If you are doing deep perf monitoring you would use the per minute. I will only use the per hour data which means that a value such as average response time is the average per hour. One bad response time during that hour raises the average significantly if we have a low amount of requests.<\/p>\n<p>Both Capacity and the different Metrics buckets are recorded to Azure Table Storage, where capacity is recorded to a table named $MetricsCapacityBlob and the hourly metrics for blob transactions are stored in a table named $MetricsHourPrimaryTransactionsBlob. Replace Hour for Minute and Blob for Table\/Queue and you&#8217;ll have the complete palette of what&#8217;s being recorded. There are some very good, but quite heavy, articles in the Azure documentation explaining this (see refs below).<\/p>\n<p><strong>Logging<\/strong> is a different thing and is capturing the storage requests being sent to your account. It is compareable to the IIS-log of a webserver logging requests from clients. This data is perfect for analyzing what&#8217;s going on on an application level. It is stored in a special container named $logs with the storage account itself. Under the $logs container and in there you will find blobs named <em>blob\/2015\/11\/06\/2000\/000001.log<\/em> or\u00a0<em>table\/2015\/11\/07\/1200\/000000.log<\/em> which holds requests for\u00a0a specific date and hour. The file has sequence numbers to avoid having too large logfiles for a single hour.<\/p>\n<p><strong>Rule of thumb<\/strong> &#8211; If you just want to know how your Storage Account is performing, then you should enable Monitoring. If you also need to know about the requests applications are sending, then you should also enable Logging.<\/p>\n<p>Turning on Monitoring and Logging is easy, getting the data being recorded and understanding it is the harder part and that is what I will try to show you.<\/p>\n<p><strong>Retrieving Capacity data<\/strong><\/p>\n<p>Given that we have enabled monitoring, how do we retrieve the data from the Azure Table $MetricsCapacityBlob\u00a0in a powershell script?<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-1.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5451\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-1.png\" alt=\"ListBlobCapacity-1\" width=\"888\" height=\"367\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-1.png 888w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-1-300x124.png 300w\" sizes=\"(max-width: 888px) 100vw, 888px\" \/><\/a><\/p>\n<p>The function above gets the storage key and then calls Get-AzureStorageServiceMetricsProperty to get the Monitoring config for Blobs and the Hour bucket. If RetentionDays isn&#8217;t specified we are using 0 which means that we only store it for the current date. Then it gets a reference to the $MetricsCapacityBlob and loop over the number of retention days and reads the data for each day. The PartitionKey for the $MetricsCapacityBlob is in format YYYYMMDDT0000. If the HTTP response is OK, then we grab the data and add it to an array of data.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-2.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5461\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-2.png\" alt=\"ListBlobCapacity-2\" width=\"907\" height=\"118\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-2.png 907w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-2-300x39.png 300w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/><\/a><\/p>\n<p>There is no native support for reading an Azure\u00a0Table in powershell but it is possible by creating the objects via New-Object and using the CreateCloudTableClient and GetTableReference methods.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-3.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5471\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-3.png\" alt=\"ListBlobCapacity-3\" width=\"787\" height=\"228\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-3.png 787w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-3-300x87.png 300w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/a><\/p>\n<p>The data retrived from the Retrieve operation on the Azure Table is a TableEntity and we can enumerate all properties\u00a0 in a key\/value pair fashion to create an internalpowershell object (which we need later to save it as a CSV file). The DecimalPoint clutter is due to the fact that although the Locale in my country and on my computers has the comma (&#8220;,&#8221;) as the decimal point, PowerBI doesn&#8217;t understand that (yet). If I am to use the output in Excel, I must have a comma as separator in the CSV file (since that is my Windows setting). But if I want to import the CSV file to PowerBI (which is all nicely localized in my local country in the UI), it will assume that decimal point is period (&#8220;.&#8221;) and comma is a thousend separator. If the CSV file has a value of 27,983 as AverageServerLatency then that is interpreted by PowerBI as 27983 seconds instead of a little less than 28 seconds. When PowerBI understands different Locale, this can be removed.<\/p>\n<p><strong>Downloading Capacity data to a CSV file<\/strong><\/p>\n<p>The whole point of automation is reducing and eliminating tedious manual steps, and what you probably want is a way to retrieve Capacity data for all your Storage Accounts in one go. The powershell script enumerates all Storage Accounts and invokes the ListBlobCapacity function, described above, and all the capcity data is stored in the array and written out as a CSV file together.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-result.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5501\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-result.png\" alt=\"ListBlobCapacity-result\" width=\"978\" height=\"403\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-result.png 978w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-result-300x124.png 300w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><\/a><\/p>\n<p>Importing the CSV file with Capacity data, you can chart it like below in Excel and get an overview of your storage usage. To the left I used a bar chart showing how much storage each account is using and to the right it&#8217;s a line chart for a single account that have reduced its stored data during the measured period.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-excel-bar.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5541\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-excel-bar.png\" alt=\"ListBlobCapacity-excel-bar\" width=\"963\" height=\"321\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-excel-bar.png 963w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobCapacity-excel-bar-300x100.png 300w\" sizes=\"(max-width: 963px) 100vw, 963px\" \/><\/a><\/p>\n<p><strong>Retrieving Metrics data<\/strong><\/p>\n<p>Getting the Metrics data follows the exact same pattern as getting the Capacity data from a powershell script perspective. The only difference is that it&#8217;s another Azure Table we are retrieving the data from and that the data i sampled per hour. Therefor, there is an outer for-loop for days and inner for-loop for the hours, but the rest is exactly the same.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-1.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5581\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-1.png\" alt=\"ListBlobMetrics-1\" width=\"803\" height=\"425\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-1.png 803w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-1-300x159.png 300w\" sizes=\"(max-width: 803px) 100vw, 803px\" \/><\/a><\/p>\n<p>Running the script and creating a CSV file with metrics for all Storage Accounts and then uploading it to PowerBI, gives you the ability to create some interesting diagrams. Below the top diagram shows the TotalEgress for storage accounts and the bottom show AverageServerLatency over time. As you can see there are several spikes in TotalEgress, which means data is being read from storage, and each spike is accompanied by the AverageServerLatency increasing in a similar fashion.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-PowerBI.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5621\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-PowerBI.png\" alt=\"ListBlobMetrics-PowerBI\" width=\"786\" height=\"545\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-PowerBI.png 786w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-PowerBI-300x208.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/p>\n<p>Loading the metrics CSV file into Excel and using PowerPivot to analyse it, you can create a chart like below easily showing the performance of a storage account. In this chart\u00a0DateTime is used as\u00a0Axis, StorageAccountName as Filter and AverageE2ELatency, AverageServerLatency, PercentSuccess and PercentNetworkError as Values.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-Excel.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5751\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-Excel.png\" alt=\"ListBlobMetrics-Excel\" width=\"934\" height=\"632\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-Excel.png 934w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/11\/ListBlobMetrics-Excel-300x203.png 300w\" sizes=\"(max-width: 934px) 100vw, 934px\" \/><\/a><\/p>\n<p><strong>8 functions of my Powershell script<\/strong><\/p>\n<p>The powershell script being used in this post have 8 functions, which are<\/p>\n<ul>\n<li>List Storage Account(s) Capacity<\/li>\n<li>List Storage Account(s) Metrics<\/li>\n<li>Show current Monitoring config<\/li>\n<li>Set Monitoring config<\/li>\n<li>Show current Logging config<\/li>\n<li>Set Logging config<\/li>\n<li>List available log files<\/li>\n<li>Download available log files<\/li>\n<\/ul>\n<p>The first two are what I&#8217;ve used in the post. The Show\/Set functions will help you manage the settings across accounts so that you can see and change them with one command. The Download function would be the next step in analyzing futher what actually caused those spikes in the PowerBI diagrams above.<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>Storage Monitoring and Logging has been available in Azure for a long time and I am certainly not the first one to write about it. But this post tries to get you from theory to practice with as little as a single powershell script. There are of course other and more competent tools to handle this, but the point is that you should start getting familiar with how to use this data in order to avoid running out of storage or having performance issues coming as a surprise to you. It is really as easy as enabling monitoring and logging and then start downloading and analysing the data.<\/p>\n<p><strong>References<\/strong><\/p>\n<p>Documentation &#8211; Enabeling monitoring and logging via\u00a0Powershell<br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/dn782840.aspx\" target=\"_blank\">https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/dn782840.aspx<\/a><\/p>\n<p>How to monitor a storage account in the portal<br \/>\n<a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/storage-monitor-storage-account\/\" target=\"_blank\">https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/storage-monitor-storage-account\/<\/a><\/p>\n<p>Storage Analytics documentation<br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/hh343270.aspx\" target=\"_blank\">https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/hh343270.aspx<\/a><\/p>\n<p>Monitor, diagnose, and troubleshoot Microsoft Azure Storage<br \/>\n<a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/storage-monitoring-diagnosing-troubleshooting\/\" target=\"_blank\">https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/storage-monitoring-diagnosing-troubleshooting\/<\/a><\/p>\n<p>Metrics data documentation<br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/dn782843.aspx\" target=\"_blank\">https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/dn782843.aspx<\/a><\/p>\n<p><strong>Sources<br \/>\n<\/strong>Please read the readme.txt for how to use all the 8 different functions.<br \/>\n<a href=\"http:\/\/data.redbaronofazure.com\/public\/StorageMonitoring.zip\" target=\"_blank\">http:\/\/data.redbaronofazure.com\/public\/StorageMonitoring.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure Storage is one of the key core infrastructure components that basically all other Azure features rely upon. It is very easy to use since you just create a Storage Account and off you go, but to know how it actually performs, you must switch on what is called monitoring and logging. However, like all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[141,321],"tags":[331,31],"_links":{"self":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/5371"}],"collection":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5371"}],"version-history":[{"count":0,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/5371\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}