본문 바로가기
[AWS]/ROG

[AWS] [참고] EC2 Userdata Windows CWAgent 설정

by SAMSUNG CLOUD-OKY 2022. 3. 28.
반응형

 

<powershell>
$UserData = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Script))
 
# agent install
mkdir "c:\cwagent"
cd "c:\cwagent"
wget "https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi" -OutFile "C:\cwagent\amazon-cloudwatch-agent.msi"
Start-Process msiexec.exe -Wait -ArgumentList '/I C:\cwagent\amazon-cloudwatch-agent.msi /quiet'
 
 
 
 
# service start
& $Env:ProgramFiles\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1 -m ec2 -a start
 
 
# config json file create
New-Item -Path "C:\Program Files\Amazon\AmazonCloudWatchAgent" -Name config.json -ItemType file -Value '{
    "metrics": {
    "namespace": "CWA_Windows_Custom",
        "append_dimensions": {
            "InstanceId": "${aws:InstanceId}"
        },
        "metrics_collected": {
            "LogicalDisk": {
                "measurement": [
                    "% Free Space"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                    "*"
                ]
            },
            "Memory": {
                "measurement": [
                    "Available MBytes",
                    "% Committed Bytes In Use"
                ],
                "metrics_collection_interval": 60
            },
            "Paging File": {
                "measurement": [
                    "% Usage"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                    "*"
                ]
            },      
            "statsd": {
                "metrics_aggregation_interval": 60,
                "metrics_collection_interval": 10,
                "service_address": ":8125"
            }
        }
    }
}'
 
# cd root 
cd "C:\Program Files\Amazon\AmazonCloudWatchAgent"
 
# wizard run
& "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json"
</powershell>
 

 

 

반응형

댓글