Home > OS >  AWS CloudWatch agent for windows server not starting
AWS CloudWatch agent for windows server not starting

Time:07-06

I have been trying to setup the AWS CloudWatch agent but it has been constantly giving me error, I have tried using the config file generator as well as placing the config.json file manually in the specified location, the logs are not much help either. I have attached the CloudWatchAgentServer role to the instance, the instance is in public subnet and internet traffic is allowed, I have followed the AWS docs to install the agent.

Below are the logs the command is generating

2022/07/01 06:26:29 I! Return exit error: exit code=99
2022/07/01 06:26:29 I! there is no json configuration when running translator
2022/07/01 06:33:09 I! 2022/07/01 06:33:09 D! [EC2] Found active network interface
I! Detected the instance is EC2
2022/07/01 06:33:09 Reading json config file path: C:\ProgramData\Amazon\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json ...
C:\ProgramData\Amazon\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json does not exist or cannot read. Skipping it.
No json config files found, please provide config, exit now

PS C:\Users\Administrator> & $env:ProgramFiles\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:$env:ProgramFiles\Amazon\AmazonCloudWatchAgent\config.json -s
****** processing amazon-cloudwatch-agent ******
I! Trying to detect region from ec2
2022/07/04 06:10:33 D! [EC2] Found active network interface
2022/07/04 06:10:34 E! Fail to fetch/remove json config: open C:\Program: The system cannot find the file specified.
E! Fail to fetch/remove json config: open C:\Program: The system cannot find the file specified.
Fail to fetch the config!

How I downloaded the agent -

Invoke-WebRequest -Uri https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi -OutFile $env:USERPROFILE\Desktop\amazon-cloudwatch-agent.msi

What config file I am using -

{
"logs": {
    "logs_collected": {
        "windows_events": {
            "collect_list": [
                {
                    "event_format": "xml",
                    "event_levels": [
                        "ERROR",
                        "CRITICAL"
                    ],
                    "event_name": "System",
                    "log_group_name": "WindowEvents",
                    "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": {
        "LogicalDisk": {
            "measurement": [
                "% Free Space"
            ],
            "metrics_collection_interval": 60,
            "resources": [
                "*"
            ]
        },
        "Memory": {
            "measurement": [
                "% Committed Bytes In Use"
            ],
            "metrics_collection_interval": 60
        },
        "Paging File": {
            "measurement": [
                "% Usage"
            ],
            "metrics_collection_interval": 60,
            "resources": [
                "*"
            ]
        },
        "PhysicalDisk": {
            "measurement": [
                "% Disk Time",
                "Disk Write Bytes/sec",
                "Disk Read Bytes/sec",
                "Disk Writes/sec",
                "Disk Reads/sec"
            ],
            "metrics_collection_interval": 60,
            "resources": [
                "*"
            ]
        },
        "Processor": {
            "measurement": [
                "% User Time",
                "% Idle Time",
                "% Interrupt Time"
            ],
            "metrics_collection_interval": 60,
            "resources": [
                "*"
            ]
        },
        "TCPv4": {
            "measurement": [
                "Connections Established"
            ],
            "metrics_collection_interval": 60
        },
        "TCPv6": {
            "measurement": [
                "Connections Established"
            ],
            "metrics_collection_interval": 60
        },
        "statsd": {
            "metrics_aggregation_interval": 60,
            "metrics_collection_interval": 60,
            "service_address": ":8125"
        }
    }
}
}

CodePudding user response:

This error message:

2022/07/04 06:10:34 E! Fail to fetch/remove json config: open C:\Program: The system cannot find the file specified.

Indicates that the path you are passing through isn't being evaluated properly. You need to use double quotes when passing such a path, like this:

& "$env:ProgramFiles\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -c file:"$env:ProgramFiles\Amazon\AmazonCloudWatchAgent\config.json"
  • Related