{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Observability Solution from CloudWatch: EC2 Health (Linux/macOS). Version: 1.0.0.",
  "Transform": "AWS::LanguageExtensions",
  "Parameters": {
    "DashboardNameParameter": {
      "Type": "String",
      "Description": "Enter name of the dashboard, the maximum length is 255, and valid characters are A-Z, a-z, 0-9, \"-\", and \"_\". The dashboard will display metrics from the region where the stack is being created. To easily differentiate this dashboard from similar ones in other regions, we recommend including the region name in the dashboard name.",
      "MinLength": "1",
      "MaxLength": "255",
      "AllowedPattern": "^[a-zA-Z0-9-_]*$",
      "Default": "EC2HealthDashboard"
    }
  },
  "Resources": {
    "CloudWatchDashboard": {
      "Type": "AWS::CloudWatch::Dashboard",
      "Properties": {
        "DashboardName": {
          "Ref": "DashboardNameParameter"
        },
        "DashboardBody": {
          "Fn::ToJsonString": {
            "widgets": [
              {
                "height": 1,
                "width": 24,
                "y": 0,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "## CloudWatch Agent Metrics",
                  "background": "transparent"
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 1,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### CPU",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 2,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,cpu} MetricName=cpu_usage_idle', 'Average')), MIN, ASC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Idle [avg: ${AVG}, min: ${MIN}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.name')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,cpu} MetricName=cpu_usage_idle', 'Average')), MIN, ASC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "Idle [avg: ${AVG}, min: ${MIN}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.name')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "CPU Usage Idle (Ascending)",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 2,
                "x": 12,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,cpu} MetricName=cpu_usage_iowait', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "IOWait [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,cpu} MetricName=cpu_usage_iowait', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "IOWait [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "CPU Usage IOWait",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 8,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,cpu} MetricName=cpu_usage_user', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "User [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,cpu} MetricName=cpu_usage_user', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "User [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "CPU Usage User",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 8,
                "x": 12,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,cpu} MetricName=cpu_usage_system', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "System [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,cpu} MetricName=cpu_usage_system', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "System [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "CPU Usage System",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 14,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### Disk",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 15,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,device, fstype, path} MetricName=disk_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.path')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,device, fstype, path} MetricName=disk_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.path')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "Disk Used",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 15,
                "x": 12,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,device, fstype, path} MetricName=disk_inodes_free', 'Average')), MIN, ASC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Inodes Free [avg: ${AVG}, min: ${MIN}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.path')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,device, fstype, path} MetricName=disk_inodes_free', 'Average')), MIN, ASC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "Inodes Free [avg: ${AVG}, min: ${MIN}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.path')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "Disk Inodes Free (Ascending)",
                  "yAxis": {
                    "left": {
                      "label": "Count",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 21,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### DiskIO",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 24,
                "y": 22,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,name} MetricName=diskio_io_time', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "IO Time [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.name')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName,name} MetricName=diskio_io_time', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "IO Time [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} ${PROP('Dim.name')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "Disk IO",
                  "yAxis": {
                    "left": {
                      "label": "Milliseconds",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 28,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### Memory",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 24,
                "y": 29,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId} MetricName=mem_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName} MetricName=mem_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "Memory Used",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 35,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### Swap",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 24,
                "y": 36,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId} MetricName=swap_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ],
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{CWAgent,InstanceId,InstanceType,ImageId,AutoScalingGroupName} MetricName=swap_used_percent', 'Average')), MAX, DESC, 10)",
                        "id": "e2",
                        "period": 60,
                        "label": "Used % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')} (${PROP('Dim.AutoScalingGroupName')})"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 60,
                  "title": "Swap Used",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 42,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "## AWS/EC2 Vended Metrics",
                  "background": "transparent"
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 43,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### CPU",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 24,
                "y": 44,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=CPUUtilization', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "CPU % [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 300,
                  "title": "EC2 CPU Utilization",
                  "yAxis": {
                    "left": {
                      "label": "Percent",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 1,
                "width": 24,
                "y": 50,
                "x": 0,
                "type": "text",
                "properties": {
                  "markdown": "### Network",
                  "background": "transparent"
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 51,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=NetworkPacketsIn', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Packets In [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 300,
                  "title": "Network Packets In",
                  "yAxis": {
                    "left": {
                      "label": "Count",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 51,
                "x": 12,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=NetworkPacketsOut', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Packets Out [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 300,
                  "title": "Network Packets Out",
                  "yAxis": {
                    "left": {
                      "label": "Count",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 57,
                "x": 0,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=NetworkIn', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Network In [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 300,
                  "title": "Network In",
                  "yAxis": {
                    "left": {
                      "label": "Bytes",
                      "showUnits": false
                    }
                  }
                }
              },
              {
                "height": 6,
                "width": 12,
                "y": 57,
                "x": 12,
                "type": "metric",
                "properties": {
                  "metrics": [
                    [
                      {
                        "expression": "SORT(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=NetworkOut', 'Average')), MAX, DESC, 10)",
                        "id": "e1",
                        "period": 60,
                        "label": "Network Out [avg: ${AVG}, max: ${MAX}] - ${PROP('Dim.InstanceId')}"
                      }
                    ]
                  ],
                  "view": "timeSeries",
                  "stacked": false,
                  "region": {
                    "Ref": "AWS::Region"
                  },
                  "stat": "Average",
                  "period": 300,
                  "title": "Network Out",
                  "yAxis": {
                    "left": {
                      "label": "Bytes",
                      "showUnits": false
                    }
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}