##やりたいこと
EC2 に CloudWatch Agent をインストールして、EC2 のメモリ使用量をチェックしたい。
##やったこと
AWS のドキュメントに沿ってやりました。
コマンドラインを使用して CloudWatch エージェントをインストールする
common-config.toml の設定は、オプションと書いてあったので、修正していません。
#エラーになった箇所
# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml -s
##知りたいこと
JSON の形式がおかしいとのことですが、どのように直せばいいかわかりません。
ご知見のある方、ご教示お願いします。
##追記
config に書くこともなかったので、
# mv common-config.toml common-config.toml.bak # touch common-config.toml
としたのですが、下記エラーが出ます。
# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml -s /opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source file:/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_common-config.toml.tmp Start configuration validation... /opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 2020/04/29 20:55:35 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_common-config.toml.tmp ... 2020/04/29 20:55:35 Invalid json format, please check. Reason: unexpected end of JSON input 2020/04/29 20:55:35 I! AmazonCloudWatchAgent Version 1.237768.0. 2020/04/29 20:55:35 Configuration validation first phase failed. Agent version: 1.237768.0. Verify the JSON input is only using features supported by this version.
##追記2
amazon-cloudwatch-agent.json
{ "agent": { "metrics_collection_interval": 60, "run_as_user": "root" }, "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/cloudwatch", "log_group_name": "cloudwatch", "log_stream_name": "{instance_id}" } ] } } }, "metrics": { "append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}", "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" }, "metrics_collected": { "collectd": { "metrics_aggregation_interval": 60 }, "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" } } } }
ログ
2020/05/04 12:16:05 I! I! Detected the instance is EC2 2020/05/04 12:16:05 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ... 2020/05/04 12:16:05 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_common-config.toml ... 2020/05/04 12:16:05 Invalid json format, please check. Reason: unexpected end of JSON input 2020/05/04 12:16:05 I! AmazonCloudWatchAgent Version 1.237768.0. 2020/05/04 12:16:05 Configuration validation first phase failed. Agent version: 1.237768.0. Verify the JSON input is only using features supported by this version. 2020/05/04 12:16:05 I! Return exit error: exit code=1 2020/05/04 12:16:05 E! Cannot translate JSON config into TOML, ERROR is exit status 1
cloudwatch agent のステータス
# sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status { "status": "stopped", "starttime": "", "version": "1.237768.0" }
##追記3
config.json
{ "agent": { "metrics_collection_interval": 10, "run_as_user": "root" }, "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/messages", "log_group_name": "messages", "log_stream_name": "{instance_id}" } ] } } }, "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": 10, "resources": [ "*" ], "totalcpu": false }, "disk": { "measurement": [ "used_percent", "inodes_free" ], "metrics_collection_interval": 10, "resources": [ "*" ] }, "diskio": { "measurement": [ "io_time", "write_bytes", "read_bytes", "writes", "reads" ], "metrics_collection_interval": 10, "resources": [ "*" ] }, "mem": { "measurement": [ "mem_used_percent" ], "metrics_collection_interval": 10 }, "netstat": { "measurement": [ "tcp_established", "tcp_time_wait" ], "metrics_collection_interval": 10 }, "statsd": { "metrics_aggregation_interval": 60, "metrics_collection_interval": 10, "service_address": ":8125" }, "swap": { "measurement": [ "swap_used_percent" ], "metrics_collection_interval": 10 } } } }
/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
2020-05-19T08:06:17Z E! refresh EC2 Instance Tags failed: SharedCredsLoad: failed to load shared credentials file caused by: FailedRead: unable to open file caused by: open /root/.aws/credentials: permission denied, metrics will be dropped until it got fixed 2020-05-19T08:16:17Z E! refresh EC2 Instance Tags failed: SharedCredsLoad: failed to load shared credentials file caused by: FailedRead: unable to open file caused by: open /root/.aws/credentials: permission denied, metrics will be dropped until it got fixed
credentials が読めないとありますが、どうしたら読めるようになりますか?
##追記4
# ps aux | grep cloud cwagent 3089 0.1 3.0 158036 30516 ? Ssl 07:15 0:03 /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml -pidfile /opt/aws/amazon-cloudwatch-agent/var/amazon-cloudwatch-agent.pid
# cat amazon-cloudwatch-agent.toml [agent] collection_jitter = "0s" debug = false flush_interval = "1s" flush_jitter = "0s" hostname = "" interval = "60s" logfile = "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log" metric_batch_size = 1000 metric_buffer_limit = 10000 omit_hostname = false precision = "" quiet = false round_interval = false [inputs] [[inputs.disk]] drop_device = false fieldpass = ["used_percent"] [inputs.disk.tags] metricPath = "metrics" [[inputs.mem]] fieldpass = ["used_percent"] [inputs.mem.tags] metricPath = "metrics" [outputs] [[outputs.cloudwatch]] force_flush_interval = "60s" namespace = "CWAgent" region = "ap-northeast-1" shared_credential_file = "/root/.aws/credentials" tagexclude = ["host", "metricPath"] [outputs.cloudwatch.tagpass] metricPath = ["metrics"] [processors] [[processors.ec2tagger]] ec2_instance_tag_keys = ["aws:autoscaling:groupName"] ec2_metadata_tags = ["ImageId", "InstanceId", "InstanceType"] refresh_interval_seconds = "2147483647s" shared_credential_file = "/root/.aws/credentials" [processors.ec2tagger.tagpass] metricPath = ["metrics"]
# cat common-config.toml [credentials] shared_credential_file = "/root/.aws/credentials"
# cat default { "agent": { "run_as_user": "cwagent" }, "metrics": { "metrics_collected": { "mem": { "measurement": [ "mem_used_percent" ] }, "disk": { "measurement": [ "used_percent" ], "resources": [ "*" ] } }, "append_dimensions": { "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}", "AutoScalingGroupName": "${aws:AutoScalingGroupName}" } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/29 11:59
2020/04/29 12:33
2020/04/30 11:07
2020/04/30 11:49
2020/05/01 01:13 編集
2020/05/01 01:20
2020/05/01 01:22
2020/05/01 01:24
2020/05/01 02:17
2020/05/01 02:18
2020/05/01 03:02
2020/05/01 03:58
2020/05/01 04:41
2020/05/01 06:32
2020/05/03 01:38
2020/05/03 01:50
2020/05/03 08:26
2020/05/03 16:44
2020/05/04 03:22
2020/05/04 14:33
2020/05/05 01:34 編集
2020/05/06 11:45
2020/05/07 00:30
2020/05/07 02:11
2020/05/07 08:50
2020/05/07 09:38
2020/05/08 00:15
2020/05/08 02:53
2020/05/08 04:38
2020/05/08 04:43
2020/05/08 05:49 編集
2020/05/08 06:04
2020/05/08 10:30
2020/05/08 21:01
2020/05/09 00:26
2020/05/09 01:12
2020/05/09 12:00
2020/05/10 01:25
2020/05/10 18:36
2020/05/12 11:43
2020/05/12 13:38 編集
2020/05/12 13:43
2020/05/16 07:19
2020/05/16 11:33
2020/05/17 04:22
2020/05/17 11:57 編集
2020/05/18 02:51 編集
2020/05/18 05:11
2020/05/19 08:20
2020/05/20 03:38
2020/05/20 23:10
2020/05/21 00:56
2020/05/21 11:15
2020/05/21 11:27
2020/05/21 15:45 編集
2020/05/23 00:55 編集
2020/05/23 14:38
2020/05/24 04:01 編集
2020/05/24 13:48
2020/05/26 11:28