| 
		
	
	
	
		
	Posts: 3 
	Threads: 1 
	Joined: Jul 2018
	
 Reputation: 
0 
	
	
		I've a requirement where in i'm trying to create clouldwatch dashboard for my service,I've nearly 20 servers for which i wish to create dashboard with multiple widget.
 each widget would contain 'CPUUtilization' martix for all 20 server,other widget would contain ' DiskReadOps' matrics for all 20 servers and so on.
 
 In short
 
 one dashboard would contain multipe widget and one widget would contain matrix from multiple servers
 
 I wish to write cloudformation script for the same in yaml format as i'm using yaml for other stuffs,i tried to refer docs but dint get much about my requirement
 
 
 Any help on this will be appreciated.
 
 Thanks,
 Subham
 
	
	
	
		
	Posts: 61 
	Threads: 31 
	Joined: Jul 2018
	
 Reputation: 
2 
	
	
		 (19-02-2019, 12:46 PM)subham Wrote:  I've a requirement where in i'm trying to create clouldwatch dashboard for my service,I've nearly 20 servers for which i wish to create dashboard with multiple widget.
 I wish to write cloudformation script for the same in yaml format as i'm using yaml for other stuffs,i tried to refer docs but dint get much about my requirement
 
Hello Subham,
 
Below is a sample template you can use for this. This template creates 2 widgets inside a single dashbaord with each widget having 2 resources in it. One widget shows the CPU utilization of 2 instances and the other widget shows the Volume Read Ops of 2 EBS volumes. To add more resources, just replicate the metrics section as many times as you desire. You can of course add resource references to automatically pick up instance ids and volume ids if you wish to.
 Code: AWSTemplateFormatVersion: '2010-09-09'Description: AWS CloudFormation Template Auto Dashboard Creation
 Resources:
 DashboardSideBySide:
 Type: AWS::CloudWatch::Dashboard
 Properties:
 DashboardName: EC2-EBS-Metrics
 DashboardBody: '{
 "widgets":[
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [
 "AWS/EC2",
 "CPUUtilization",
 "InstanceId",
 "i-xxxxxxxxxxxxx"
 ],
 [
 "AWS/EC2",
 "CPUUtilization",
 "InstanceId",
 "i-xxxxxxxxxxxxx"
 ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EC2 Instances CPU"
 }
 },
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [
 "AWS/EBS",
 "VolumeReadOps",
 "VolumeId",
 "vol-xxxxxxxxxxxxx"
 ],
 [
 "AWS/EBS",
 "VolumeReadOps",
 "VolumeId",
 "vol-xxxxxxxxxxxxx"
 ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EBS Volume Read Ops"
 }
 }
 ]
 }'
 
	
	
	
		
	Posts: 3 
	Threads: 1 
	Joined: Jul 2018
	
 Reputation: 
0 
	
	
		Thanks ..It was a great help.
	 
	
	
	
		
	Posts: 61 
	Threads: 31 
	Joined: Jul 2018
	
 Reputation: 
2 
	
	
		 (20-02-2019, 06:16 AM)subham Wrote:  Thanks ..It was a great help. 
You're welcome.
 
Here is the upgraded version of the template that allows you to use variables input by user into the template using "Ref" with "Fn::Join"
 Code: JSON
 {
 "AWSTemplateFormatVersion": "2010-09-09",
 "Description": "AWS CloudFormation Template Auto Dashboard Creation",
 "Metadata" : {"Created By": "Faizal Khan @ Ecomm India Cloud IT"},
 "Parameters": {
 "Server1CPU": {
 "Description": "What is the instance id of Server 1 for CPU Utilization?",
 "Type": "String"
 },
 "Server2CPU": {
 "Description": "What is the instance id of Server 2 for CPU Utilization?",
 "Type": "String"
 },
 "EBS1Disk": {
 "Description": "What is the volume id of Disk 1 for Volume Read Ops?",
 "Type": "String"
 },
 "EBS2Disk": {
 "Description": "What is the volume id of Disk 2 for Volume Read Ops?",
 "Type": "String"
 }
 },
 "Resources": {
 "AutomatedDashboard": {
 "Type": "AWS::CloudWatch::Dashboard",
 "Properties": {
 "DashboardName": "Dashboard-Multiple-EC2-EBS-Metrics",
 "DashboardBody": {
 "Fn::Join": [
 "",
 [
 "{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EC2\",\"CPUUtilization\",\"InstanceId\",\"",
 {
 "Ref": "Server1CPU"
 },
 "\"],[\".\",\".\",\".\",\"",
 {
 "Ref": "Server2CPU"
 },
 "\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EC2 Instances CPU Utilization\"}},{\"type\":\"metric\",\"x\":12,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EBS\",\"VolumeReadOps\",\"VolumeId\",\"",
 {
 "Ref": "EBS1Disk"
 },
 "\"],[\".\",\".\",\".\",\"",
 {
 "Ref": "EBS2Disk"
 },
 "\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EBS Volumes ReadOps\"}}]}"
 ]
 ]
 }
 }
 }
 }
 }
 
 
 
 
 
 YAML
 
 AWSTemplateFormatVersion: 2010-09-09
 Description: AWS CloudFormation Template Auto Dashboard Creation
 Metadata:
 Created By: Faizal Khan @ Ecomm India Cloud IT
 Parameters:
 Server1CPU:
 Description: What is the instance id of Server 1 for CPU Utilization?
 Type: String
 Server2CPU:
 Description: What is the instance id of Server 2 for CPU Utilization?
 Type: String
 EBS1Disk:
 Description: What is the volume id of Disk 1 for Volume Read Ops?
 Type: String
 EBS2Disk:
 Description: What is the volume id of Disk 2 for Volume Read Ops?
 Type: String
 Resources:
 AutomatedDashboard:
 Type: 'AWS::CloudWatch::Dashboard'
 Properties:
 DashboardName: Dashboard-Multiple-EC2-EBS-Metrics
 DashboardBody: !Join
 - ''
 - - >-
 {"widgets":[{"type":"metric","x":0,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EC2","CPUUtilization","InstanceId","
 - !Ref Server1CPU
 - '"],[".",".",".","'
 - !Ref Server2CPU
 - >-
 "]],"period":300,"stat":"Average","region":"us-east-1","title":"EC2
 Instances CPU
 Utilization"}},{"type":"metric","x":12,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EBS","VolumeReadOps","VolumeId","
 - !Ref EBS1Disk
 - '"],[".",".",".","'
 - !Ref EBS2Disk
 - >-
 "]],"period":300,"stat":"Average","region":"us-east-1","title":"EBS
 Volumes ReadOps"}}]}
 
	
	
	
		
	Posts: 3 
	Threads: 1 
	Joined: Jul 2018
	
 Reputation: 
0 
	
	
		Thanks for the above...Below is what i've tried something similar and get this working..Posting it here Code: AWSTemplateFormatVersion: '2010-09-09'Description: AWS CloudFormation Template  Dashboard Creation
 Resources:
 CloudwatchDashboard:
 Type: AWS::CloudWatch::Dashboard
 Properties:
 DashboardName: EC2-Sample-Dashboard
 DashboardBody: { "Fn::Join": [ "", ['{
 "widgets":[
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [ "AWS/EC2", "CPUUtilization", "InstanceId", "', { Ref: Ec2Instance1 }, '" ],
 [ "AWS/EC2", "CPUUtilization", "InstanceId", "', { Ref: Ec2Instance2 }, '" ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EC2 Instances CPU Details"
 }
 },
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [ "AWS/EBS", "VolumeReadOps", "VolumeId", "vol-0e7060d9" ],
 [ "AWS/EBS", "VolumeReadOps", "VolumeId", "vol-023c57f" ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EBS Details"
 }
 },
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [ "AWS/S3", "BucketSizeBytes", "BucketName", "bucket1" ],
 [ "AWS/S3", "BucketSizeBytes", "BucketName", "bucket2" ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"S3 Buckets Details"
 }
 },
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [ "AWS/EFS", "PermittedThroughput", "FileSystemId", "fs-f29a1" ],
 [ "AWS/EFS", "PermittedThroughput", "FileSystemId", "fs-db382" ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EFS Details"
 }
 },
 {
 "type":"metric",
 "x":0,
 "y":0,
 "width":12,
 "height":6,
 "properties":{
 "metrics":[
 [ "AWS/EC2", "DiskReadOps", "InstanceId", "', { Ref: Ec2Instance1 }, '" ],
 [ "AWS/EC2", "DiskReadOps", "InstanceId", "', { Ref: Ec2Instance2 }, '" ]
 ],
 "period":300,
 "stat":"Average",
 "region":"us-east-1",
 "title":"EC2 Disk Readops Details"
 }
 }
 ]
 }'
 ] ]  }
 
 Ec2Instance1:
 Type: AWS::EC2::Instance
 Properties:
 ImageId: ami-04a5ff1d83d13aa06
 InstanceType: t2.micro
 AvailabilityZone: ap-southeast-1a
 Ec2Instance2:
 Type: AWS::EC2::Instance
 Properties:
 ImageId: ami-04a5ff1d83d13aa06
 InstanceType: t2.micro
 AvailabilityZone: ap-southeast-1a
 
	
	
	
		
	Posts: 1 
	Threads: 0 
	Joined: Sep 2019
	
 Reputation: 
0 
	
	
		Thanks for sharing the informative concept and coding above. I also learn AWS I know something which I used to get started with CloudWatch dashboards, you must first create a dashboard. You can create multiple dashboards. There is no limit on the number of CloudWatch dashboards in your AWS account. All dashboards are global, not Region-specific.
	 |