Answers: <p>I decided to approach the calculations this way.</p>
  <p>Success = HealthyHostCount &gt; 0</p>
  <p>Fail = HealthyHostCount &lt;= 0</p>
  <p>Time = HealthyHostCount + UnhealthyHostCount</p>
  <p>Uptime = 100*(Success/(Success+Fail))</p>
  <p>That ended up with a dashboard widget in CloudWatch with a source like this.</p>
  <pre><code>{
      &quot;metrics&quot;: [
          [ { &quot;expression&quot;: &quot;100*(succeed/(succeed+fail))&quot;, 
              &quot;label&quot;: &quot;Dev %Up&quot;, &quot;id&quot;: &quot;e2&quot;, 
              &quot;region&quot;: &quot;us-west-1&quot;, &quot;period&quot;: 10 } ],
          [ { &quot;expression&quot;: &quot;IF(hhc &gt; 0, 1, 0)&quot;, 
              &quot;label&quot;: &quot;Success Count&quot;, &quot;id&quot;: &quot;succeed&quot;,
              &quot;visible&quot;: false, &quot;region&quot;: &quot;us-west-1&quot; } ],
          [ { &quot;expression&quot;: &quot;IF(uhc &gt; 0, 1, 0)&quot;, 
              &quot;label&quot;: &quot;Fail Count&quot;, &quot;id&quot;: &quot;fail&quot;, 
              &quot;visible&quot;: false, &quot;region&quot;: &quot;us-west-1&quot; } ],
          [ &quot;AWS/ELB&quot;,
            &quot;UnHealthyHostCount&quot;,
            &quot;LoadBalancerName&quot;,  
            &quot;internal-dev-XXX&quot;, 
            { &quot;id&quot;: &quot;uhc&quot;, &quot;visible&quot;: false, 
              &quot;region&quot;: &quot;us-west-1&quot; } ],
          [ &quot;.&quot;, &quot;HealthyHostCount&quot;, &quot;.&quot;, &quot;.&quot;,
            { &quot;id&quot;: &quot;hhc&quot;, &quot;visible&quot;: false,
              &quot;region&quot;: &quot;us-west-1&quot; } ]
      ],
      &quot;view&quot;: &quot;gauge&quot;,
      &quot;stacked&quot;: false,
      &quot;region&quot;: &quot;us-west-1&quot;,
      &quot;stat&quot;: &quot;Sum&quot;,
      &quot;period&quot;: 10,
      &quot;title&quot;: &quot;Dev Uptime&quot;,
      &quot;yAxis&quot;: {
          &quot;left&quot;: {
              &quot;min&quot;: 0,
              &quot;max&quot;: 100
          }
      },
      &quot;setPeriodToTimeRange&quot;: true,
      &quot;sparkline&quot;: false,
      &quot;trend&quot;: false,
      &quot;singleValueFullPrecision&quot;: false
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-11-20T20:57:43.763Z
Answers: 2023-11-20T20:57:43.763Z
Answers: Josiah
Body: <p>Is there a clear way to calculate starting uptime metrics from AWS ELB?</p>
  <p>I need to start running uptime calculations. I'd like to start by just using AWS services for monitoring the uptime and then grow from there as I determine what I'd like that to mean.</p>
  <p>I have the service behind an ELB as a target group. I trust the instance health check to indicate service uptime. I'd like to use the metrics on the AWS ELB as received by AWS CloudWatch to calculate the uptime over 30 days. If the <code>HealthyHostCount</code> metric is 0 for 10 seconds, that's 10 seconds of downtime. Otherwise, we have uptime. Then I'd like to have a percentage of time up over a period (30 days) to the hundredth of a percent.</p>
  <p>I've been playing with CloudWatch metrics to try to figure this out and finding that I can do math and have been getting results that seem in the right neighborhood, but I'm not confident that I'm properly thinking about the statistic period and the graph period. I'm also wondering if I should be using the PR statistic instead of doing my own math.</p>
  <p>Here's what I have right now.
  I'm grabbing the ELB's <code>HealthyHostCount as m1</code> and <code>UnhealthyHostCount</code> as m2. Both are summed up for 30 days. Then I have an expression <code>100*(m1/m1+m2)</code> to calculate percent up counts over the total counts taken for that 30 days. I have the chart set to a relative 30 days period.</p>
  <p>The problem is that this calculation, as soon as I have some value greater than 0 in m2, seems to result in numbers in the thousands or millions instead of reducing the percent down from 100.</p>
  <p>How would you calculate service percent uptime from AWS ELB metrics?</p>
  
Tags: <amazon-ec2><amazon-cloudwatch>
Title: Beginner Uptime Calculations Based on ELB?
UserDisplayName: Josiah
ThreadText: # Beginner Uptime Calculations Based on ELB?
  
  (Asked by: username_0 on 2023-11-20)
  
  Is there a clear way to calculate starting uptime metrics from AWS ELB?
  
  I need to start running uptime calculations. I'd like to start by just using AWS services for monitoring the uptime and then grow from there as I determine what I'd like that to mean.
  
  I have the service behind an ELB as a target group. I trust the instance health check to indicate service uptime. I'd like to use the metrics on the AWS ELB as received by AWS CloudWatch to calculate the uptime over 30 days. If the `HealthyHostCount` metric is 0 for 10 seconds, that's 10 seconds of downtime. Otherwise, we have uptime. Then I'd like to have a percentage of time up over a period (30 days) to the hundredth of a percent.
  
  I've been playing with CloudWatch metrics to try to figure this out and finding that I can do math and have been getting results that seem in the right neighborhood, but I'm not confident that I'm properly thinking about the statistic period and the graph period. I'm also wondering if I should be using the PR statistic instead of doing my own math.
  
  Here's what I have right now.
  I'm grabbing the ELB's `HealthyHostCount as m1` and `UnhealthyHostCount` as m2. Both are summed up for 30 days. Then I have an expression `100*(m1/m1+m2)` to calculate percent up counts over the total counts taken for that 30 days. I have the chart set to a relative 30 days period.
  
  The problem is that this calculation, as soon as I have some value greater than 0 in m2, seems to result in numbers in the thousands or millions instead of reducing the percent down from 100.
  
  How would you calculate service percent uptime from AWS ELB metrics?
  
  **Tags:** amazon-ec2, amazon-cloudwatch
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-11-20. Score: 0
  
  I decided to approach the calculations this way.
  
  Success = HealthyHostCount > 0
  
  Fail = HealthyHostCount <= 0
  
  Time = HealthyHostCount + UnhealthyHostCount
  
  Uptime = 100\*(Success/(Success+Fail))
  
  That ended up with a dashboard widget in CloudWatch with a source like this.
  
  ```
  {
      "metrics": [
          [ { "expression": "100*(succeed/(succeed+fail))", 
              "label": "Dev %Up", "id": "e2", 
              "region": "us-west-1", "period": 10 } ],
          [ { "expression": "IF(hhc > 0, 1, 0)", 
              "label": "Success Count", "id": "succeed",
              "visible": false, "region": "us-west-1" } ],
          [ { "expression": "IF(uhc > 0, 1, 0)", 
              "label": "Fail Count", "id": "fail", 
              "visible": false, "region": "us-west-1" } ],
          [ "AWS/ELB",
            "UnHealthyHostCount",
            "LoadBalancerName",  
            "internal-dev-XXX", 
            { "id": "uhc", "visible": false, 
              "region": "us-west-1" } ],
          [ ".", "HealthyHostCount", ".", ".",
            { "id": "hhc", "visible": false,
              "region": "us-west-1" } ]
      ],
      "view": "gauge",
      "stacked": false,
      "region": "us-west-1",
      "stat": "Sum",
      "period": 10,
      "title": "Dev Uptime",
      "yAxis": {
          "left": {
              "min": 0,
              "max": 100
          }
      },
      "setPeriodToTimeRange": true,
      "sparkline": false,
      "trend": false,
      "singleValueFullPrecision": false
  }
  
  ```
  
  
  ---
  
  