Skip to content

Instantly share code, notes, and snippets.

@thimslugga
Last active November 25, 2025 14:53
Show Gist options
  • Select an option

  • Save thimslugga/707b074b88f6f2ed35a0683b9b007d5d to your computer and use it in GitHub Desktop.

Select an option

Save thimslugga/707b074b88f6f2ed35a0683b9b007d5d to your computer and use it in GitHub Desktop.
CloudWatch Dashboards
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudWatch Dashboard for Transit Gateway and Direct Connect resources monitoring'
Parameters:
DashboardName:
Type: String
Description: 'Name of CloudWatch Dashboard'
Default: 'NetworkDashboard'
# CloudFormation AllowedPattern only works with String types
TransitGatewayId:
Type: String
Description: |
Transit Gateway ID (e.g. tgw-1234567890abcdef0)
AllowedPattern: '^tgw-[a-z0-9]{17}$'
DirectConnectConnectionIds:
Type: CommaDelimitedList
Description: |
Comma-separated list of Direct Connect Connection IDs (e.g. dxcon-abc123,dxcon-def456)
Default: ''
VirtualInterfaceIds:
Type: CommaDelimitedList
Description: |
Comma-separated list of Virtual Interface IDs (e.g. dxvif-abc123,dxvif-def456)
Default: ''
Conditions:
HasDirectConnect: !Not [!Equals [!Join ['', !Ref DirectConnectConnectionIds], '']]
HasVirtualInterfaces: !Not [!Equals [!Join ['', !Ref VirtualInterfaceIds], '']]
Resources:
NetworkDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: !Ref DashboardName
DashboardBody: !Sub |
{
"widgets": [
{
"type": "text",
"x": 0,
"y": 0,
"width": 24,
"height": 1,
"properties": {
"markdown": "# Transit Gateway Metrics - ${TransitGatewayId}"
}
},
{
"type": "metric",
"x": 0,
"y": 1,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/TransitGateway", "BytesIn", {"stat": "Sum", "label": "Bytes In"}],
[".", "BytesOut", {"stat": "Sum", "label": "Bytes Out"}]
],
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"title": "Transit Gateway - Data Transfer",
"period": 300,
"yAxis": {
"left": {
"label": "Bytes",
"showUnits": false
}
}
}
},
{
"type": "metric",
"x": 12,
"y": 1,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/TransitGateway", "PacketsIn", {"stat": "Sum", "label": "Packets In"}],
[".", "PacketsOut", {"stat": "Sum", "label": "Packets Out"}]
],
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"title": "Transit Gateway - Packet Count",
"period": 300,
"yAxis": {
"left": {
"label": "Packets",
"showUnits": false
}
}
}
},
{
"type": "metric",
"x": 0,
"y": 7,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/TransitGateway", "PacketDropCountBlackhole", {"stat": "Sum", "label": "Blackhole Drops"}],
[".", "PacketDropCountNoRoute", {"stat": "Sum", "label": "No Route Drops"}]
],
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"title": "Transit Gateway - Packet Drops",
"period": 300,
"yAxis": {
"left": {
"label": "Packets",
"showUnits": false
}
}
}
},
{
"type": "metric",
"x": 12,
"y": 7,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/TransitGateway", "BytesDropCountBlackhole", {"stat": "Sum", "label": "Blackhole Bytes"}],
[".", "BytesDropCountNoRoute", {"stat": "Sum", "label": "No Route Bytes"}]
],
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"title": "Transit Gateway - Byte Drops",
"period": 300,
"yAxis": {
"left": {
"label": "Bytes",
"showUnits": false
}
}
}
}
]
}
Outputs:
DashboardName:
Description: 'CloudWatch Dashboard'
Value: !Ref DashboardName
DashboardURL:
Description: 'CloudWatch Dashboard URL'
Value: !Sub 'https://console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#dashboards:name=${DashboardName}'
{
"variables": [
{
"widget": {
"title": "Filter by Attachment ID",
"id": "tgw_filter",
"type": "input",
"properties": {
"query": "SEARCH('{AWS/TransitGateway, TransitGatewayAttachmentId} MetricName=\"BytesIn\"', 'TransitGatewayAttachmentId', 300)",
"populateFrom": "TransitGatewayAttachmentId",
"variableId": "var_id",
"inputType": "select"
}
}
}
],
"widgets": [
{
"height": 6,
"width": 12,
"y": 0,
"x": 0,
"type": "metric",
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ { "expression": "SEARCH(' {AWS/TransitGateway, TransitGatewayAttachmentId} MetricName=\"BytesIn\" TransitGatewayAttachmentId=$var_id ', 'Sum', 300)", "id": "e1", "label": "Bytes In" } ]
],
"title": "TGW: Incoming Traffic (Filtered)",
"period": 300,
"stat": "Sum"
}
},
{
"height": 6,
"width": 12,
"y": 0,
"x": 12,
"type": "alarm",
"properties": {
"title": "⚠️ Active Network Alarms",
"alarms": [
"arn:aws:cloudwatch:us-east-1:123456789012:alarm:TGW-PacketLoss-High",
"arn:aws:cloudwatch:us-east-1:123456789012:alarm:DX-Connection-Down"
]
}
}
]
}
{
"widgets": [
{
"type": "text",
"x": 0,
"y": 0,
"width": 24,
"height": 6,
"properties": {
"markdown": "# ☁️ AWS Network Resource Overview Dashboard\n\n\nThis dashboard automatically discovers and graphs all **Transit Gateway (TGW) Attachments** and **Direct Connect (DX)** circuits in the deployed region using the `SEARCH` expressions.\n\n\n## Overview"
}
},
{
"type": "metric",
"x": 0,
"y": 6,
"width": 12,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"metrics": [
[ { "expression": "SEARCH(' {AWS/TransitGateway, TransitGatewayAttachmentId} MetricName=\"BytesIn\" ', 'Sum', 300)", "id": "e1", "label": "Bytes In" } ]
],
"title": "TGW: Incoming Traffic (Per Attachment)",
"period": 300,
"stat": "Sum",
"yAxis": {
"left": {
"showUnits": false,
"label": "Bytes"
}
}
}
},
{
"type": "metric",
"x": 12,
"y": 6,
"width": 12,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"metrics": [
[ { "expression": "SEARCH(' {AWS/TransitGateway, TransitGatewayAttachmentId} MetricName=\"BytesOut\" ', 'Sum', 300)", "id": "e2", "label": "Bytes Out" } ]
],
"title": "TGW: Outgoing Traffic (Per Attachment)",
"period": 300,
"stat": "Sum",
"yAxis": {
"left": {
"showUnits": false,
"label": "Bytes"
}
}
}
},
{
"type": "metric",
"x": 0,
"y": 12,
"width": 24,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"metrics": [
[ { "expression": "SEARCH(' {AWS/TransitGateway, TransitGatewayAttachmentId} MetricName=\"PacketDropCountBlackhole\" ', 'Sum', 300)", "id": "e3", "label": "Dropped Packets" } ]
],
"title": "TGW: Packet Drops (Blackhole)",
"period": 300,
"stat": "Sum",
"yAxis": {
"left": {
"showUnits": false,
"label": "Count"
}
}
}
},
{
"type": "text",
"x": 0,
"y": 18,
"width": 24,
"height": 1,
"properties": {
"markdown": "---"
}
},
{
"type": "metric",
"x": 0,
"y": 19,
"width": 8,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"metrics": [
[ { "expression": "SEARCH(' {AWS/DX, ConnectionId} MetricName=\"ConnectionState\" ', 'Average', 300)", "id": "e4", "label": "State (1=UP, 0=DOWN)" } ]
],
"title": "Direct Connect: Connection State",
"period": 300,
"stat": "Average",
"yAxis": {
"left": {
"min": 0,
"max": 1,
"showUnits": false,
"label": "State"
}
}
}
},
{
"type": "metric",
"x": 8,
"y": 19,
"width": 16,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"region": "${AWS::Region}",
"metrics": [
[ { "expression": "SEARCH(' {AWS/DX, ConnectionId} MetricName=\"ConnectionBpsIngress\" OR MetricName=\"ConnectionBpsEgress\" ', 'Average', 300)", "id": "e5", "label": "Throughput (bps)" } ]
],
"title": "Direct Connect: Throughput (Ingress/Egress)",
"period": 300,
"stat": "Average"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment