Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save PrateekKumarSingh/5339bb7c6746182596156c1730460d11 to your computer and use it in GitHub Desktop.

Select an option

Save PrateekKumarSingh/5339bb7c6746182596156c1730460d11 to your computer and use it in GitHub Desktop.
Initialize-AWSDefaults -Region us-west-2 `
-AccessKey YOUR_ACCESS_KEY `
-SecretKey YOUR_SECRET_KEY
Function Get-UsersOnlineOnReddit
{
$OnlineUsers = (Invoke-WebRequest https://www.reddit.com/r/PowerShell/).ParsedHtml.all | `
Where-Object{ $_.classname -eq "users-online fuzzed" } | `
ForEach-Object {
($_.innertext -split " " -replace "~","")[0]
}
If($OnlineUsers)
{
$data = New-Object Amazon.CloudWatch.Model.MetricDatum
$data.Timestamp = (Get-Date).ToUniversalTime()
$data.MetricName = "Online Users"
$data.Unit = "Count"
$data.Value = $OnlineUsers
Write-CWMetricData -Namespace "Usage Metrics" -MetricData $data
}
}
$i = 1
While($true)
{
Get-UsersOnlineOnReddit
Start-Sleep -Seconds 30
Write-Host "$i data point recorded on AWS CloudWatch"
$i = $i + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment