如何在Ubuntu上设置AWS CloudWatch的代理以获取(正确的)自定义指标,例如cpu,内存和磁盘使用率%

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Ubuntu上设置AWS CloudWatch的代理以获取(正确的)自定义指标,例如cpu,内存和磁盘使用率%相关的知识,希望对你有一定的参考价值。

我正在运行一个AWS EC2 m5.large(不可爆裂的实例)。我在仪表板上设置了AWS CloudWatch的默认指标(CPU%)之一和一些自定义指标(内存+磁盘使用率)。

但是当我比较CloudWatch报告的数字时,它们与我登录Ubuntu 20.04服务器时的实际使用情况相差很远...

实际用法:

CPU: ~ 35 %
Memory: ~ 33 %

CloudWatch报告:

CPU ~ 10 %
Memory: ~ 50-55

https://www.screencast.com/t/o1nAnOFjVZW

我遵循AWS自己的说明添加了内存和磁盘使用量指标(因为CloudWatch并非开箱即用,因此可以访问O / S级别的内容:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html

当数字彼此相距太远时,就不可能设置有用的警报和通知。我真不敢相信,AWS希望向选择遵循原始说明的人们提供什么?唯一匹配的是磁盘使用率%。

答案

如何在UBUNTU 20.04上安装AWS Agent(替代旧脚本的新方法:“ CloudWatchMonitoringScripts”)

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html

1. sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb
2. sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
3. sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
4. Go through all the steps in the wizard (The result is saved here: /opt/aws/amazon-cloudwatch-agent/bin/config.json)

提示:我回答:

 - Default to most questions and otherwise:
 - NO  --> Do you want to store the config in the SSM parameter store? (Because when I answered YES it failed later on because of some permission-issue and I didn't know how to make it happy and I don't think I need SSM in regards to this)
 - YES --> Do you want to turn on StatsD daemon?
 - YES --> Do you want to monitor metrics from CollectD?
 - NO  --> Do you have any existing CloudWatch Log Agent?

现在要防止此错误:解析/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml时出错,打开/usr/share/collectd/types.db:没有这样的文件或目录https://github.com/awsdocs/amazon-cloudwatch-user-guide/issues/1

5. sudo mkdir -p /usr/share/collectd/
6. sudo touch /usr/share/collectd/types.db
7. 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
8. /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status

{
  "status": "running",
  "starttime": "2020-06-07T10:04:41+00:00",
  "version": "1.245315.0"
}
  1. [https://www.screencast.com/t/42VWgoS88Z(创建IAM角色,添加策略并使其成为服务器默认角色)。
  2. [https://www.screencast.com/t/fAUUHCPe(CloudWatch新的自定义指标)]
  3. https://www.screencast.com/t/8J0Saw0co(现在数据匹配确定)
  4. https://www.screencast.com/t/x0PxOa799(现在数据匹配确定)

[我意识到-我登录计算机的那一刻,CPU%的使用率从10%上升到30%并停留在该位置(当然可以预料会有一些增加-但我认为不是那么多),在我的情况下早先解释了巨大的差异...老实说,我现在不知道这种方法是否比旧脚本更精确-但这应该是在2020年实现的正确方法:-)在以下情况下,您可以访问179个自定义指标在向导中选择“高级”(即使只有少数几个对大多数人有价值)

以上是关于如何在Ubuntu上设置AWS CloudWatch的代理以获取(正确的)自定义指标,例如cpu,内存和磁盘使用率%的主要内容,如果未能解决你的问题,请参考以下文章

无法将json文件上传到AWS CloudWatch

使用 CentOS 在 AWS GPU 实例上运行 OpenGL

减少 ubuntu@aws 微实例上 mysql 的内存消耗

如何在运行 Ubuntu 的 AWS EC2 上配置多个虚拟主机? [关闭]

声音驱动程序 - AWS EC2 ubuntu 16.04 实例的 snd-aloop 内核模块设置问题

aws_cloudwatch_log_resource_policy 创建哪些资源?