尽管配置中指定了许多其他指标,但 Amazon Cloudwatch 仅接收 mem_used_percent 而没有其他信息

问题描述 投票:0回答:3

我正在尝试让 CloudWatch 在我的 Lightsail 实例上正常运行,但我似乎只取得了部分成功。

我使用

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
运行了向导,它生成了一个配置文件,概述了许多指标,包括 CPU、内存和磁盘使用情况,如此处所述。该服务加载并启动配置文件,并且不会抱怨无效的 json(这种情况确实发生过几次,但我修复了它)。

我可以通过

sudo amazon-cloudwatch-agent-ctl -a stop

停止服务

然后我用

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -s -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json

重新加载配置

验证服务正在运行:

sudo amazon-cloudwatch-agent-ctl -a status

哪个输出:

 {
  "status": "running",
  "starttime": "2022-01-10T21:53:12+00:00",
  "configstatus": "configured",
  "cwoc_status": "stopped",
  "cwoc_starttime": "",
  "cwoc_configstatus": "not configured",
  "version": "1.247349.0b251399"
}

登录到我的 CloudWatch 控制台,我可以看到正在接收的数据,并且图表上出现的单线对应于我启动和停止服务的时间 - 所以它肯定在做一些事情。然而......该图表上出现的唯一指标是

mem_used_percent
......为什么?为什么只有这一项指标?我的其余与 cpu 等相关的数据在哪里?我做错了什么?

这是我的 config.json,正如我所说,服务正在毫无问题地加载它。

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "metrics": {
        "append_dimensions": {
            "ImageID": "${aws:ImageId}",
            "InstanceId":"${aws:InstanceId}",
            "InstanceType":"${aws:InstanceType}"
        },
        "metrics_collected": {
            "cpu": {
                "resources": [
                   "*"
                ],
                "measurement": [
                    "cpu_usage_active"
                ],
                "metrics_collection_interval": 60,
                "totalcpu": false
            },
            "disk": {
                "measurement": [
                        "free",
                        "total",
                        "used",
                        "used_percent"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                        "*"
                ]
            },
            "mem": {
                "measurement": [
                        "mem_active",
                        "mem_available",
                        "mem_available_percent",
                        "mem_free",
                        "mem_total",
                        "mem_used",
                        "mem_used_percent"
                ],
                "metrics_collection_interval": 60
            },
            "netstat": {
                "measurement": [
                        "tcp_established",
                        "udp_socket"
                ]
            }
        }
    }
}

非常感谢任何帮助。短暂性脑缺血发作。

amazon-cloudwatch
3个回答
1
投票

也许你面临着和我一样的问题。就我而言,有两个配置 json 文件

  • /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json
  • /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json

合并了。

文件随后被翻译为

/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml

当我检查文件时,只获取了

/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json
的mem定义。因此,我删除了该文件并重新启动了服务。

sudo systemctl restart amazon-cloudwatch-agent

重新启动后,toml 文件包含我所期望的内容,并且指标已就位。


0
投票

您可能尚未获取配置。 检查日志文件,即

/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
,查看加载了哪些输入:

2022-05-18T10:18:57Z I! Loaded inputs: mem disk

要获取配置,请执行以下操作(您需要根据您的环境进行调整 - 这是针对本地 systemd,没有 SSM):

sudo amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
sudo systemctl status amazon-cloudwatch-agent.service restart

之后:

2022-05-18T11:45:05Z I! Loaded inputs: mem net netstat swap cpu disk diskio

0
投票

遇到同样的问题,我意识到我看错了地方。 您实际上必须从图表返回: 浏览 -> CWAgent

您会看到还有另一个框,用于存放配置的所有不同“文件夹”:mem、磁盘等。

希望这对某人有帮助

© www.soinside.com 2019 - 2024. All rights reserved.