Use cloud watch metrics by onpremiss winodows server


# ssm activate 
create new activation
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/what-is-systems-manager.html

https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/sysman-install-managed-win.html

execute this cmd by windows power shell

```.ps1
$code = "activation-code"
$id = "activation-id"
$region = "region"
$dir = $env:TEMP + "\ssm"
New-Item -ItemType directory -Path $dir -Force
cd $dir
(New-Object System.Net.WebClient).DownloadFile("https://amazon-ssm-$region.s3.amazonaws.com/latest/windows_amd64/AmazonSSMAgentSetup.exe", $dir + "\AmazonSSMAgentSetup.exe")
Start-Process .\AmazonSSMAgentSetup.exe -ArgumentList @("/q", "/log", "install.log", "CODE=$code", "ID=$id", "REGION=$region") -Wait
Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration")
Get-Service -Name "AmazonSSMAgent"
```

# install aws-cli
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/awscli-install-windows.html

setup cloudwatch agent
```
aws configure --profile AmazonCloudWatchAgent
```

# ConfigureCloudWatch 
use Run Coomand
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/WindowsGuide/send_logs_to_cwl_instances.html


1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
1. In the navigation pane, choose Systems Manager Services, Run Command.
1. Choose Run a command.
1. For Command document, choose AWS-ConfigureCloudWatch.
1. For Target instances, choose the instances to integrate with CloudWatch. If you do not see an instance in this list, it might not be configured for Run Command. For more information, see Systems Manager Prerequisites in the AWS Systems Manager User Guide.
1. For Status, choose Enabled.
1. For Properties, copy and paste your JSON content.
1. Complete the remaining optional fields and choose Run.

this is my json configuration

send processor , memory and TcpConnections

```.json
{
    "IsEnabled": true,
    "EngineConfiguration": {
        "PollInterval": "00:00:15",
        "Components": [
            {
                "Id": "ProcessorTime",
                "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "CategoryName": "Processor Information",
                    "CounterName": "% Processor Time",
                    "InstanceName": "_Total",
                    "MetricName": "Processor Use",
                    "Unit": "Percent",
                    "DimensionName": "hostname",
                    "DimensionValue": "{hostname}"
                }
            },
            {
                "Id": "Memory",
                "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "CategoryName": "Memory",
                    "CounterName": "Available MBytes",
                    "InstanceName": "",
                    "MetricName": "Memory",
                    "Unit": "Megabytes",
                    "DimensionName": "hostname",
                    "DimensionValue": "{hostname}"
                }
            },
            {
                "Id": "TcpConnections",
                "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "CategoryName": "TCPv4",
                    "CounterName": "Connections Established",
                    "InstanceName": "",
                    "MetricName": "TcpConnections",
                    "Unit": "Count",
                    "DimensionName": "hostname",
                    "DimensionValue": "{hostname}"
                }
            },
            {
                "Id": "CloudWatch",
                "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters":
                {
                    "AccessKey": "",
                    "SecretKey": "",
                    "Region": "",
                    "NameSpace": ""
                }
            }
        ],
        "Flows": {
            "Flows":
            [
                "ProcessorTime,CloudWatch",
                "Memory,CloudWatch",
                "TcpConnections,CloudWatch"
            ]
        }
    }
}


```