Created
March 21, 2017 19:00
-
-
Save PrateekKumarSingh/5339bb7c6746182596156c1730460d11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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