Last active
January 28, 2021 16:50
-
-
Save clarencetw/4718e0743e3772627eb8e0ac2691597e to your computer and use it in GitHub Desktop.
use-cloudwatch-agent-add-ec2-instances-monitor-installation-and-teaching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd "C:\Program Files\Amazon\AmazonCloudWatchAgent" | |
PS C:\Program Files\Amazon\AmazonCloudWatchAgent> .\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json" -s # 重新啟動 CloudWatch Agent 並且使用本地 json 設定檔 | |
PS C:\Program Files\Amazon\AmazonCloudWatchAgent> .\amazon-cloudwatch-agent-ctl.ps1 -a start # 開啟 | |
PS C:\Program Files\Amazon\AmazonCloudWatchAgent> .\amazon-cloudwatch-agent-ctl.ps1 -a stop # 停止 | |
PS C:\Program Files\Amazon\AmazonCloudWatchAgent> .\amazon-cloudwatch-agent-ctl.ps1 -a status # 檢查狀態 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update && sudo apt-get install collectd -y // 安裝 collectd | |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s // 重新啟動 CloudWatch Agent 並且使用本地 json 設定檔 | |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:configuration-parameter-store-name -s // 啟動 CloudWatch Agent 並且使用本地 SSM 設定檔 | |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a start // 開啟 | |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop // 停止 | |
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status // 檢查狀態 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ubuntu@ip-10-0-0-1:~$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard | |
============================================================= | |
= Welcome to the AWS CloudWatch Agent Configuration Manager = | |
============================================================= | |
On which OS are you planning to use the agent? | |
1. linux | |
2. windows | |
default choice: [1]: | |
Trying to fetch the default region based on ec2 metadata... | |
Are you using EC2 or On-Premises hosts? | |
1. EC2 | |
2. On-Premises | |
default choice: [1]: | |
Which user are you planning to run the agent? | |
1. root | |
2. cwagent | |
3. others | |
default choice: [1]: | |
Do you want to turn on StatsD daemon? | |
1. yes | |
2. no | |
default choice: [1]: | |
Which port do you want StatsD daemon to listen to? | |
default choice: [8125] | |
What is the collect interval for StatsD daemon? | |
1. 10s | |
2. 30s | |
3. 60s | |
default choice: [1]: | |
What is the aggregation interval for metrics collected by StatsD daemon? | |
1. Do not aggregate | |
2. 10s | |
3. 30s | |
4. 60s | |
default choice: [4]: | |
Do you want to monitor metrics from CollectD? | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to monitor any host metrics? e.g. CPU, memory, etc. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available? | |
1. yes | |
2. no | |
default choice: [1]: | |
Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file. | |
1. 1s | |
2. 10s | |
3. 30s | |
4. 60s | |
default choice: [4]: | |
Which default metrics config do you want? | |
1. Basic | |
2. Standard | |
3. Advanced | |
4. None | |
default choice: [1]: | |
3 | |
Current config as follows: | |
{ | |
"agent": { | |
"metrics_collection_interval": 60, | |
"run_as_user": "root" | |
}, | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"collectd": { | |
"metrics_aggregation_interval": 60 | |
}, | |
"cpu": { | |
"measurement": [ | |
"cpu_usage_idle", | |
"cpu_usage_iowait", | |
"cpu_usage_user", | |
"cpu_usage_system" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
], | |
"totalcpu": false | |
}, | |
"disk": { | |
"measurement": [ | |
"used_percent", | |
"inodes_free" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"diskio": { | |
"measurement": [ | |
"io_time", | |
"write_bytes", | |
"read_bytes", | |
"writes", | |
"reads" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"mem": { | |
"measurement": [ | |
"mem_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"netstat": { | |
"measurement": [ | |
"tcp_established", | |
"tcp_time_wait" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
}, | |
"swap": { | |
"measurement": [ | |
"swap_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
} | |
} | |
} | |
} | |
Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration? | |
1. yes | |
2. no | |
default choice: [2]: | |
Do you want to monitor any log files? | |
1. yes | |
2. no | |
default choice: [1]: | |
2 | |
Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully. | |
Current config as follows: | |
{ | |
"agent": { | |
"metrics_collection_interval": 60, | |
"run_as_user": "root" | |
}, | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"collectd": { | |
"metrics_aggregation_interval": 60 | |
}, | |
"cpu": { | |
"measurement": [ | |
"cpu_usage_idle", | |
"cpu_usage_iowait", | |
"cpu_usage_user", | |
"cpu_usage_system" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
], | |
"totalcpu": false | |
}, | |
"disk": { | |
"measurement": [ | |
"used_percent", | |
"inodes_free" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"diskio": { | |
"measurement": [ | |
"io_time", | |
"write_bytes", | |
"read_bytes", | |
"writes", | |
"reads" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"mem": { | |
"measurement": [ | |
"mem_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"netstat": { | |
"measurement": [ | |
"tcp_established", | |
"tcp_time_wait" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
}, | |
"swap": { | |
"measurement": [ | |
"swap_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
} | |
} | |
} | |
} | |
Please check the above content of the config. | |
The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json. | |
Edit it manually if needed. | |
Do you want to store the config in the SSM parameter store? | |
1. yes | |
2. no | |
default choice: [1]: | |
2 | |
Program exits now. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"agent": { | |
"metrics_collection_interval": 60, | |
"run_as_user": "root" | |
}, | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"collectd": { | |
"metrics_aggregation_interval": 60 | |
}, | |
"cpu": { | |
"measurement": [ | |
"cpu_usage_idle", | |
"cpu_usage_iowait", | |
"cpu_usage_user", | |
"cpu_usage_system" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
], | |
"totalcpu": false | |
}, | |
"disk": { | |
"measurement": [ | |
"used_percent", | |
"inodes_free" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"diskio": { | |
"measurement": [ | |
"io_time", | |
"write_bytes", | |
"read_bytes", | |
"writes", | |
"reads" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"mem": { | |
"measurement": [ | |
"mem_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"netstat": { | |
"measurement": [ | |
"tcp_established", | |
"tcp_time_wait" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
}, | |
"swap": { | |
"measurement": [ | |
"swap_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS C:\Program Files\Amazon\AmazonCloudWatchAgent> .\amazon-cloudwatch-agent-config-wizard.exe | |
============================================================= | |
= Welcome to the AWS CloudWatch Agent Configuration Manager = | |
============================================================= | |
On which OS are you planning to use the agent? | |
1. linux | |
2. windows | |
default choice: [2]: | |
Trying to fetch the default region based on ec2 metadata... | |
Are you using EC2 or On-Premises hosts? | |
1. EC2 | |
2. On-Premises | |
default choice: [1]: | |
Do you want to turn on StatsD daemon? | |
1. yes | |
2. no | |
default choice: [1]: | |
Which port do you want StatsD daemon to listen to? | |
default choice: [8125] | |
What is the collect interval for StatsD daemon? | |
1. 10s | |
2. 30s | |
3. 60s | |
default choice: [1]: | |
What is the aggregation interval for metrics collected by StatsD daemon? | |
1. Do not aggregate | |
2. 10s | |
3. 30s | |
4. 60s | |
default choice: [4]: | |
Do you have any existing CloudWatch Log Agent configuration file to import for migration? | |
1. yes | |
2. no | |
default choice: [2]: | |
Do you want to monitor any host metrics? e.g. CPU, memory, etc. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if | |
the info is available? | |
1. yes | |
2. no | |
default choice: [1]: | |
Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution fo | |
r all metrics, but you can customize for specific metrics in the output json file. | |
1. 1s | |
2. 10s | |
3. 30s | |
4. 60s | |
default choice: [4]: | |
Which default metrics config do you want? | |
1. Basic | |
2. Standard | |
3. Advanced | |
4. None | |
default choice: [1]: | |
3 | |
Current config as follows: | |
{ | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"LogicalDisk": { | |
"measurement": [ | |
"% Free Space" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Memory": { | |
"measurement": [ | |
"% Committed Bytes In Use" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"Paging File": { | |
"measurement": [ | |
"% Usage" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"PhysicalDisk": { | |
"measurement": [ | |
"% Disk Time", | |
"Disk Write Bytes/sec", | |
"Disk Read Bytes/sec", | |
"Disk Writes/sec", | |
"Disk Reads/sec" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Processor": { | |
"measurement": [ | |
"% User Time", | |
"% Idle Time", | |
"% Interrupt Time" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"TCPv4": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"TCPv6": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
} | |
} | |
} | |
} | |
Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additiona | |
l items. | |
1. yes | |
2. no | |
default choice: [1]: | |
Do you want to monitor any customized log files? | |
1. yes | |
2. no | |
default choice: [1]: | |
2 | |
Do you want to monitor any Windows event log? | |
1. yes | |
2. no | |
default choice: [1]: | |
2 | |
Saved config file to config.json successfully. | |
Current config as follows: | |
{ | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"LogicalDisk": { | |
"measurement": [ | |
"% Free Space" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Memory": { | |
"measurement": [ | |
"% Committed Bytes In Use" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"Paging File": { | |
"measurement": [ | |
"% Usage" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"PhysicalDisk": { | |
"measurement": [ | |
"% Disk Time", | |
"Disk Write Bytes/sec", | |
"Disk Read Bytes/sec", | |
"Disk Writes/sec", | |
"Disk Reads/sec" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Processor": { | |
"measurement": [ | |
"% User Time", | |
"% Idle Time", | |
"% Interrupt Time" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"TCPv4": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"TCPv6": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
} | |
} | |
} | |
} | |
Please check the above content of the config. | |
The config file is also located at config.json. | |
Edit it manually if needed. | |
Do you want to store the config in the SSM parameter store? | |
1. yes | |
2. no | |
default choice: [1]: | |
2 | |
Please press Enter to exit... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metrics": { | |
"append_dimensions": { | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}" | |
}, | |
"metrics_collected": { | |
"LogicalDisk": { | |
"measurement": [ | |
"% Free Space" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Memory": { | |
"measurement": [ | |
"% Committed Bytes In Use" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"Paging File": { | |
"measurement": [ | |
"% Usage" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"PhysicalDisk": { | |
"measurement": [ | |
"% Disk Time", | |
"Disk Write Bytes/sec", | |
"Disk Read Bytes/sec", | |
"Disk Writes/sec", | |
"Disk Reads/sec" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"Processor": { | |
"measurement": [ | |
"% User Time", | |
"% Idle Time", | |
"% Interrupt Time" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"TCPv4": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"TCPv6": { | |
"measurement": [ | |
"Connections Established" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"statsd": { | |
"metrics_aggregation_interval": 60, | |
"metrics_collection_interval": 10, | |
"service_address": ":8125" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment