{"id":756,"date":"2020-02-10T10:45:31","date_gmt":"2020-02-10T18:45:31","guid":{"rendered":"http:\/\/blog.nillsf.com\/?p=756"},"modified":"2020-02-10T17:23:07","modified_gmt":"2020-02-11T01:23:07","slug":"adding-alerts-to-azure-storage-metrics","status":"publish","type":"post","link":"https:\/\/blog.nillsf.com\/index.php\/2020\/02\/10\/adding-alerts-to-azure-storage-metrics\/","title":{"rendered":"Adding alerts to Azure Storage metrics"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">For every system you use, monitoring and alerting is critical. This holds true for Azure storage as well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this quick post I&#8217;ll explain how you can setup alert rules for hitting TPS limits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up the alert<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To set up the alerts, navigate to your storage account, look for Alerts, and hit the &#8220;New alert rule&#8221; button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"233\" src=\"\/wp-content\/uploads\/2020\/02\/image-17-1024x233.png\" alt=\"\" class=\"wp-image-757\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-17-1024x233.png 1024w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-17-300x68.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-17-768x175.png 768w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-17.png 1063w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, you need to define the rules you want to follow for this alert. The first question you get asked if which resource you want to monitor. This could be a single storage account, multiple accounts in a resource group, or all accounts in a subscription. In my case, I&#8217;ll create an alert for this specific storage account.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"117\" src=\"\/wp-content\/uploads\/2020\/02\/image-19.png\" alt=\"\" class=\"wp-image-759\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-19.png 1014w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-19-300x35.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-19-768x89.png 768w\" sizes=\"auto, (max-width: 1014px) 100vw, 1014px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, you&#8217;ll need to select a condition to match. You can select diffent Signal types, which in our case will be Metrics. Then you can select transactions.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"462\" src=\"\/wp-content\/uploads\/2020\/02\/image-20.png\" alt=\"\" class=\"wp-image-760\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-20.png 496w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-20-300x279.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, you will see an overview of the current transactions, and you&#8217;ll get the opportunity to specify specific dimensions to split the metric. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"645\" src=\"\/wp-content\/uploads\/2020\/02\/image-21.png\" alt=\"\" class=\"wp-image-761\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-21.png 815w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-21-300x237.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-21-768x608.png 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then, you&#8217;ll have to define which threshold to hit. Azure supports two thresholds here, either they are static (i.e. a metric you provide, e.g. close to the max of the storage account) or dynamic (showing you anomalies in your usage). In my case, I&#8217;ll configure a static alert at 1000 transactions. Note as well that you can define the aggregation granularity (over how much transactions will be counted) and how frequent this will be checked.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"333\" src=\"\/wp-content\/uploads\/2020\/02\/image-22.png\" alt=\"\" class=\"wp-image-762\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-22.png 820w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-22-300x122.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-22-768x312.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"147\" src=\"\/wp-content\/uploads\/2020\/02\/image-25-1024x147.png\" alt=\"\" class=\"wp-image-765\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-25-1024x147.png 1024w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-25-300x43.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-25-768x110.png 768w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-25.png 1031w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After that, you need to create an action group. Actions can be multiple things, ranging from sending an e-mail, to calling a webhook to triggering an automation runbook to run. In my case, I&#8217;ll send an e-mail to myself. If you don&#8217;t have action groups precreated, you can create them for here by hitting the Create button in stead of the Add button. You can even configure multiple actions as part of a single action group.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1017\" height=\"148\" src=\"\/wp-content\/uploads\/2020\/02\/image-26.png\" alt=\"\" class=\"wp-image-766\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-26.png 1017w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-26-300x44.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-26-768x112.png 768w\" sizes=\"auto, (max-width: 1017px) 100vw, 1017px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"845\" height=\"393\" src=\"\/wp-content\/uploads\/2020\/02\/image-28.png\" alt=\"\" class=\"wp-image-769\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-28.png 845w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-28-300x140.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-28-768x357.png 768w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"148\" src=\"\/wp-content\/uploads\/2020\/02\/image-29.png\" alt=\"\" class=\"wp-image-770\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-29.png 644w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-29-300x69.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we&#8217;ll give our rule a name and enable it. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"311\" src=\"\/wp-content\/uploads\/2020\/02\/image-30.png\" alt=\"\" class=\"wp-image-771\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-30.png 744w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-30-300x125.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It can take up to 10 minutes for the alert to become active, and then it&#8217;ll take about 5 minutes for the aggregation window to catch up. Let&#8217;s wait a little and then trigger our alert.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Triggering the alert<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To trigger my alert based on total amount of transactions, I&#8217;ll start a <code>azcopy bench<\/code> job. <code>Azcopy bench<\/code> is a benchmarking tool to verify bandwidth to azure storage. To do this, I&#8217;ll start up a Linux VM, and download <code>azcopy <\/code>on there with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/aka.ms\/downloadazcopy-v10-linux\ntar -xvzf downloadazcopy-v10-linux\ncd azcopy_linux_amd64_10.3.4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">While in that folder, we can setup our benchmark tool. First, we&#8217;ll need a SAS token to connect to our storage account. Head over to the storage blade and look for SAS. Create a new SAS token that at least can write to blob. In my case, I gave full permissions to blob.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"958\" height=\"786\" src=\"\/wp-content\/uploads\/2020\/02\/image-31.png\" alt=\"\" class=\"wp-image-772\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-31.png 958w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-31-300x246.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-31-768x630.png 768w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the token is generated, copy it somewhere safe. Next, we&#8217;ll create a new container for our benchmark.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"482\" height=\"283\" src=\"\/wp-content\/uploads\/2020\/02\/image-32.png\" alt=\"\" class=\"wp-image-773\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-32.png 482w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-32-300x176.png 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once that is done, we can format our bench command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>azcopy bench \"https:\/\/&lt;account>.blob.core.windows.net\/&lt;container>?&lt;SAS>\" --file-count 100 --size-per-file 2G<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With that done, let&#8217;s run the benchmark and see if the alert rule is triggered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And for sure &#8211; after waiting a couple minutes &#8211; I got an alert in my inbox, explaining we hit the 1000 transactions limit:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"175\" src=\"\/wp-content\/uploads\/2020\/02\/image-33.png\" alt=\"\" class=\"wp-image-774\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-33.png 590w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-33-300x89.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><figcaption><br><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Automating this setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Doing this setup using the portal is easy for a single storage account, but requires some automation to set this up across all your storage accounts. The following Powershell snipper will create a rule that does the same we just created in the portal. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$action = Get-AzActionGroup -Name \"email_nills\" -ResourceGroupName \"Default-ActivityLogAlerts\"\n$act = New-AzActionGroup -ActionGroupId $action.Id\n$crit = New-AzMetricAlertRuleV2Criteria -MetricName transactions -TimeAggregation Total -Operator GreaterThan -Threshold 1000\n\n$staccs = Get-AzStorageAccount\nforeach ($stacc in $staccs){\n    $alertrulename = $stacc.StorageAccountName + \" exceeded transactions\" \n    Add-AzMetricAlertRuleV2 -ResourceGroupName $stacc.ResourceGroupName -Name $alertrulename -WindowSize 00:05:00 -ActionGroup $act `\n    -TargetResourceId $stacc.Id -Frequency 00:05:00 -Condition $crit -severity 2\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this post we quickly evaluated how we can setup alerts based on the amount of transactions in a storage account. This will trigger automatically and do the required actions. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>For every system you use, monitoring and alerting is critical. This holds true for Azure storage as well. In this quick post I&#8217;ll explain how you can setup alert rules for hitting TPS limits. Setting up the alert To set up the alerts, navigate to your storage account, look for Alerts, and hit the &#8220;New [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":761,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,4,1],"tags":[81,68,76,67],"class_list":["post-756","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-management","category-uncategorized","tag-alert","tag-blob","tag-monitoring","tag-storage"],"jetpack_featured_media_url":"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-21.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/comments?post=756"}],"version-history":[{"count":3,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/756\/revisions"}],"predecessor-version":[{"id":777,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/756\/revisions\/777"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/media\/761"}],"wp:attachment":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/media?parent=756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/categories?post=756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/tags?post=756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}