<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Cloudwatch on Evan Hoffman</title><link>https://evan.wtf/tags/cloudwatch/</link><description>Recent content in Cloudwatch on Evan Hoffman</description><generator>Hugo</generator><language>en-US</language><copyright>Evan Hoffman</copyright><lastBuildDate>Fri, 18 Jul 2014 10:29:57 +0000</lastBuildDate><atom:link href="https://evan.wtf/tags/cloudwatch/index.xml" rel="self" type="application/rss+xml"/><item><title>Create CloudWatch alerts for all Elastic Load Balancers</title><link>https://evan.wtf/2014/07/18/create-cloudwatch-alerts-for-all-elastic-load-balancers/</link><pubDate>Fri, 18 Jul 2014 10:29:57 +0000</pubDate><guid>https://evan.wtf/2014/07/18/create-cloudwatch-alerts-for-all-elastic-load-balancers/</guid><description>&lt;p&gt;I manage a bunch of ELBs but we were missing an alert on a pretty basic metric: how many errors the load balancer was returning. Rather than wade through the UI to add these alerts I figured it would be easier to do it via the CLI.&lt;/p&gt;&#10;&lt;p&gt;Assuming aws-cli is installed and the ARN for your SNS topic (in my case, just an email alert) is $arn:&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;for i in `aws elb describe-load-balancers | grep LoadBalancerName | &#10;perl -ne &amp;#39;chomp; my @a=split(/s+/); $a[2] =~ s/[&amp;#34;,]//g ; print &amp;#34;$a[2] &amp;#34;;&amp;#39; ` ; &#10;do aws cloudwatch put-metric-alarm --alarm-name &amp;#34;$i ELB 5XX Errors&amp;#34; --alarm-description &#10;&amp;#34;High $i ELB 5XX error count&amp;#34; --metric-name HTTPCode_ELB_5XX --namespace AWS/ELB &#10;--statistic Sum --period 300 --evaluation-periods 1 --threshold 50 &#10;--comparison-operator GreaterThanThreshold --dimensions Name=LoadBalancerName,Value=$i &#10;--alarm-actions $arn --ok-actions $arn ; done&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That huge one-liner creates a CloudWatch notification that sends an alarm when the number of 5XX errors returned by the ELB is greater than 50 over 5 minutes, and sends an &amp;ldquo;ok&amp;rdquo; message via the same SNS topic. The for loop creates/modifies the alarm for every ELB.&lt;/p&gt;</description></item></channel></rss>