aws
aws 申请资源地址
aws 认证
Route53简介
AWS Session Manager 管理 EC2 实例
从零开始创建Amazon VPC
aws 考试
aws成本优化方案
IAM
EC2
ec2 网络
ec2 关机 与 终止 注意项
创建 ec2 时,会遇到的问题
信用
vpc
vpc 对等连接
vpc 终端节点
vpc 终端节点服务 aws privateLink
弹性ip
Transit gateway
Auto Scaling
负载均衡 ELB
s3
ACL
RDS
elastic Beanstalk
vpn
route53
部署方式 与 总结
lambda
CloudFront
s3 成本优化
CloudWatch
ec2 指标 日志 到 cloudwatch
AMI
aws systems manager
EBS
EFS
aws storage gateway
SQS、SNS、SWF、API Gateway、Elastic Transcoder、Kinesis
查看 ec2 区域资源
aws ip ranges
使用AWS CloudFront 的原始存取控制(OAC)建立安全的 S3 靜態網站
eks 安装部署入门
部署Nginx测试应用并使用NodePort+NLB模式对外暴露服务
部署AWS Load Balancer Controller
eksctl
eks github
VPC公有子网和私有子网及ELB的位置推荐
aws 策略生成器
纯内网使用Session Manager登录EC2
通过Userdata在创建EC2时候修改Hostname主机名
aws 优秀 blog
使用 VPC Endpoint 从 VPC 或 IDC 内访问 S3
s3 官网参考文档(S3存储桶策略样例)
AWS 备份解决方案
EC2挂载EFS使用说明
中转网关(Transit Gateway)连接同区域(Region)VPC
aws 架构图
centos7 安装 ssm agent
rds
通过 AWS Systems Manager 在 EC2 实例上远程运行命令 教程
本文档使用 MrDoc 发布
-
+
首页
ec2 指标 日志 到 cloudwatch
# 创建 IAM 角色 ![](/media/202312/2023-12-17_204903_4949410.85338625526693.png) ![](/media/202312/2023-12-17_204947_9652220.361273604822389.png) # ec2 ``` #!/bin/bash # install the agent on Amazon Linux 2 sudo yum install amazon-cloudwatch-agent # run the wizard sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard # options: sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-linux -s 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 ``` ``` #run the wizard 后的配置 [root@ip-172-31-4-150 ec2-user]# sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard ================================================================ = Welcome to the Amazon CloudWatch Agent Configuration Manager = = = = CloudWatch Agent allows you to collect metrics and logs from = = your host and send them to CloudWatch. Additional CloudWatch = = charges may apply. = ================================================================ On which OS are you planning to use the agent? 1. linux 2. windows 3. darwin default choice: [1]: 1 Trying to fetch the default region based on ec2 metadata... 2023/12/17 12:54:57 I! imds retry client will retry 1 times Are you using EC2 or On-Premises hosts? 1. EC2 2. On-Premises default choice: [1]: 1 Which user are you planning to run the agent? 1. root 2. cwagent 3. others default choice: [1]: 1 Do you want to turn on StatsD daemon? 1. yes 2. no default choice: [1]: 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? WARNING: CollectD must be installed or the Agent will fail to start 1. yes 2. no default choice: [1]: 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? 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]: Do you want to aggregate ec2 dimensions (InstanceId)? 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]: Current config as follows: { "agent": { "metrics_collection_interval": 60, "run_as_user": "root" }, "metrics": { "aggregation_dimensions": [ [ "InstanceId" ] ], "append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}", "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" }, "metrics_collected": { "disk": { "measurement": [ "used_percent" ], "metrics_collection_interval": 60, "resources": [ "*" ] }, "mem": { "measurement": [ "mem_used_percent" ], "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 additional items. 1. yes 2. no default choice: [1]: 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]: 2 Do you want to monitor any log files? 1. yes 2. no default choice: [1]: 1 Log file path: /var/log/nginx/access.log Log group name: default choice: [access.log] nginx_access.log Log stream name: default choice: [{instance_id}] Log Group Retention in days 1. -1 2. 1 3. 3 4. 5 5. 7 6. 14 7. 30 8. 60 9. 90 10. 120 11. 150 12. 180 13. 365 14. 400 15. 545 16. 731 17. 1096 18. 1827 19. 2192 20. 2557 21. 2922 22. 3288 23. 3653 default choice: [1]: 2 Do you want to specify any additional log files to monitor? 1. yes 2. no default choice: [1]: 1 Log file path: /var/log/nginx/error.log Log group name: default choice: [error.log] nginx_error.log Log stream name: default choice: [{instance_id}] Log Group Retention in days 1. -1 2. 1 3. 3 4. 5 5. 7 6. 14 7. 30 8. 60 9. 90 10. 120 11. 150 12. 180 13. 365 14. 400 15. 545 16. 731 17. 1096 18. 1827 19. 2192 20. 2557 21. 2922 22. 3288 23. 3653 default choice: [1]: 2 Do you want to specify any additional log files to monitor? 1. yes 2. no default choice: [1]: 2 Do you want the CloudWatch agent to also retrieve X-ray traces? 1. yes 2. no default choice: [1]: Do you have an existing X-Ray Daemon configuration file to import for migration? 1. yes 2. no default choice: [1]: What is the file path for the existing X-Ray Daemon configuration file? There was an error reading X-Ray Daemon config file. Using default traces configurations Current Traces Configurations: { "traces": { "traces_collected": { "xray": { "bind_address": "127.0.0.1:2000", "tcp_proxy": { "bind_address": "127.0.0.1:2000" } } }, "concurrency": 8, "buffer_size_mb": 3, "insecure": false } } Enter a number of the field you would like to update (or 0 to exit) 0: Keep this configuration and exit 1: UDP BindAddress 2: TCP BindAddress 3: concurrency 4: buffer_size_mb 5: resource_arn 6: local_mode 7: insecure 8: role_arn 9: endpoint_override 10: region_override 11: proxy_override 0 Existing config JSON identified and copied to: /opt/aws/amazon-cloudwatch-agent/etc/backup-configs 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" }, "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/nginx/access.log", "log_group_name": "nginx_access.log", "log_stream_name": "{instance_id}", "retention_in_days": 1 }, { "file_path": "/var/log/nginx/error.log", "log_group_name": "nginx_error.log", "log_stream_name": "{instance_id}", "retention_in_days": 1 } ] } } }, "metrics": { "aggregation_dimensions": [ [ "InstanceId" ] ], "append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}", "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" }, "metrics_collected": { "disk": { "measurement": [ "used_percent" ], "metrics_collection_interval": 60, "resources": [ "*" ] }, "mem": { "measurement": [ "mem_used_percent" ], "metrics_collection_interval": 60 }, "statsd": { "metrics_aggregation_interval": 60, "metrics_collection_interval": 10, "service_address": ":8125" } } }, "traces": { "buffer_size_mb": 3, "concurrency": 8, "insecure": false, "traces_collected": { "xray": { "bind_address": "127.0.0.1:2000", "tcp_proxy": { "bind_address": "127.0.0.1:2000" } } } } } 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]: 1 What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy) default choice: [AmazonCloudWatch-linux] Trying to fetch the default region based on ec2 metadata... 2023/12/17 12:58:58 I! imds retry client will retry 1 times Which region do you want to store the config in the parameter store? default choice: [ap-east-1] Which AWS credential should be used to send json config to parameter store? 1. ASIAUIPZACUJAOO7IMSI(From SDK) 2. Other default choice: [1]: 1 Successfully put config to parameter store AmazonCloudWatch-linux. Program exits now. ``` # ssm ![](/media/202312/2023-12-17_210058_0858050.10707148288082402.png) # run cli ``` sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-linux -s ```
admin
2023年12月17日 21:05
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码