Implement AWS CloudWatch to the AWS WorkSpaces using System Manager
-
Install System Manager on WorkSpaces – you must follow installing AWS System Manager on-premise.
-
Create Hybrid Activations for your AWS WorkSpaces
Copy code and id to the script that installs it to all AWS instances using PS remoting from your Active Directory Administration Account.
-
Invoke the following code to install a System manager Agent on Workspaces:
Set-ExecutionPolicy Unrestricted
Invoke-Command -ComputerName WSAMZN-AJHQL2HU,WSAMZN-4C2SBR05 -FilePath .\InstallSME.ps1
InstallSME.ps1:
$code = “xxx”
$id = “yyy”
$region = “us-east-1”
$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 Cloud Watch Agent on Work Spaces – that now you are see them as Managed Instances.
- Install Cloud Watch binaries using Run Command From System Manager, search for AWS-ConfigureAWSPackage package.
- Put AmazonCloudWatchAgent in Name and confirm that Action is Install and specify targets.
-
You can use:
aws workspaces describe-workspaces –output json > workspaceinstances.txt
notepad .\workspaceinstances.txt
aws ssm describe-instance-information –output json > managedinstances.txt
notepad .\managedinstances.txt
to fetch instance details and match instanceid against computername.
- Disable the S3 bucket and RUN.
-
Run script that pass config files to the insances:
- Run command and choose AWS-RunPowerShellScript
-
Put script:
New-Item “C:\ProgramData\Amazon\AmazonCloudWatchAgent\credentials” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\credentials” “[AmazonCloudWatchAgent]” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\credentials” “aws_access_key_id = zzz” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\credentials” “aws_secret_access_key = zzz” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\credentials” “region = us-east-1” -Force
Remove-Item “C:\ProgramData\Amazon\AmazonCloudWatchAgent\common-config.toml” -Force
New-Item “C:\ProgramData\Amazon\AmazonCloudWatchAgent\common-config.toml” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\common-config.toml” “[credentials]” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\common-config.toml” ” shared_credential_profile = `”AmazonCloudWatchAgent`”” -Force
Add-content “C:\ProgramData\Amazon\AmazonCloudWatchAgent\common-config.toml” ” shared_credential_file = `”C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\credentials`”” -Force
- Specify targets.
- Disable the S3 bucket and RUN.
-
Configure Parameters:
-
Put Parameters json file to the Parameter Store.
-
-
Push configuration and Launch :
- Run Command From System Manager, search for AmazonCloudWatch-ManageAgent package.
- Action: configure
- Mode: onPremise
- Optional: ssm
- Configuration Location: AmazonCloudWatch-windows
-
Optional Restart: yes
- Specify targets.
- Disable the S3 bucket and RUN.
Access to CloudWatch Events:
- Open AWS CloudWatch console at https://console.aws.amazon.com/cloudwatch
- Select ‘Metrics’ from the left navigation bar. You will see 4 tabs on the right side. Select the first tab ‘All metrics’ and make sure the region is e.g. N.Virginia.
- Here you will see custom Namespaces ‘CWAgent’, click on it. Now it will show multiple subfolders, select ‘host, instance, objectname’ and you will see hostname WSAMZN-IOU56NBQ in the list.
- Select any of the available metrics and it will show a graph on top.
- The fastest way to find any metric for a host is to search the hostname when you click on Metrics on the left navigation bar.
- You can also search with a metric name. For example, search with “Memory % Committed Bytes In Use” to find Memory utilization for systems.
Debug:
Logs: C:\ProgramData\Amazon\AmazonCloudWatchAgent\Logs
Config: C:\ProgramData\Amazon\AmazonCloudWatchAgent
Test Connection:
Test-NetConnection -ComputerName ec2.us-east-1.amazonaws.com -Port 443
Test-NetConnection -ComputerName logs.us-east-1.amazonaws.com -Port 443
Test-NetConnection -ComputerName monitoring.us-east-1.amazonaws.com -Port 443