AWS CloudWatch Agent在EC2上异常:误判为On-Premise环境
Amazon Linux 2 EC2实例CloudWatch Agent配置失败问题
环境与配置详情
运行Amazon Linux 2的EC2实例上安装了AWS CloudWatch Agent,配置文件内容如下:
{ "agent": { "metrics_collection_interval": 60, "run_as_user": "cwagent" }, "metrics": { "append_dimensions": { "InstanceId": "${aws:InstanceId}" }, "metrics_collected": { "disk": { "measurement": [ "used_percent" ], "metrics_collection_interval": 60, "resources": [ "/" ] } } } }
执行命令tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log验证配置时,出现以下错误:
I! Detected the instance is OnPremise 2023/06/21 11:52:36 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ... 2023/06/21 11:52:36 I! Valid Json input schema. I! Detecting run_as_user... 2023/06/21 11:52:36 E! Credentials path is not set while runasuser is not root 2023/06/21 11:52:36 E! Credentials path is not set while runasuser is not root 2023/06/21 11:52:36 Configuration validation first phase failed. Agent version: 1.0. Verify the JSON input is only using features supported by this version. 2023/06/21 11:52:36 I! Return exit error: exit code=1 2023/06/21 11:52:36 E! Cannot translate JSON config into TOML, ERROR is exit status 1
已按官方文档安装配置Agent,确认网络连通正常,尝试过重新安装,问题未解决。
补充测试结果
已确认运行最新版本CloudWatch Agent,检查过防火墙,日志显示:
2023/07/05 07:59:41 I! D! [EC2] Found active network interface E! ec2metadata is not available I! Detected the instance is OnPremise 2023/07/05 07:59:41 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ... 2023/07/05 07:59:41 E! Failed to generate merged json config: unable to get old json config file with error: unable to parse json, error: invalid character '}' after top-level value 2023/07/05 07:59:41 E! Failed to generate merged json config: unable to get old json config file with error: unable to parse json, error: invalid character '}' after top-level value 2023/07/05 07:59:41 Configuration validation first phase failed. Agent version: 1.0. Verify the JSON input is only using features supported by this version. 2023/07/05 07:59:41 I! Return exit error: exit code=1 2023/07/05 07:59:41 E! Cannot translate JSON config into TOML, ERROR is exit status 1
使用命令wget -q -O - http://169.254.169.254/latest/meta-data/instance-id && echo 测试元数据服务连接,成功获取到实例ID,但问题仍存在。
内容的提问来源于stack exchange,提问作者Roei Sagi
相关产品推荐
相关产品推荐

