Forum Discussion
Settings an alert if available sessions is low
- Jun 28, 2021
DeletedHey, Vinisz
I don't have the Kusto query for you, but this could be an alternative option. look at this (full Credit goes to Travis, I just pulled the relevant parts out - replace the hostpool variables with your own), you should be able to turn the below into an Azure Automation runbook to trigger an email based on count:
#https://raw.githubusercontent.com/tsrob50/WVD-Public/master/WVDARM_ScaleHostPoolVMs.ps1
# Set default error action
$defaultErrorAction = $ErrorActionPreference# Enable Verbose logging
$VerbosePreference = 'SilentlyContinue'$hostPoolName = 'avd-pooled'
$hostPoolRg = 'avd_prod'$hostPool = Get-AzWvdHostPool -ResourceGroupName $hostPoolRg -HostPoolName $hostPoolName
$sessionHosts = Get-AzWvdSessionHost -ResourceGroupName $hostPoolRg -HostPoolName $hostPoolName | Where-Object { $_.AllowNewSession -eq $true }
$runningSessionHosts = $sessionHosts | Where-Object { $_.Status -eq "Available" }
# Get the Max Session Limit on the host pool
# This is the total number of sessions per session host
$maxSession = $hostPool.MaxSessionLimit
# Get current active user sessions
$currentSessions = 0
foreach ($sessionHost in $sessionHosts) {
$count = $sessionHost.session
$currentSessions += $count
}
$runningSessionHostsCount = $runningSessionHosts.count
$sessionHostTarget = [math]::Ceiling((($currentSessions) / $maxSession))
if ($runningSessionHostsCount -lt $sessionHostTarget) {
Write-Verbose "Running session host count $runningSessionHostsCount is less than session host target count $sessionHostTarget"}
elseif ($runningSessionHostsCount -gt $sessionHostTarget) {
Write-Verbose "Running session hosts count $runningSessionHostsCount is greater than session host target count $sessionHostTarget"}
else {
Write-Verbose "Running session host count $runningSessionHostsCount matches session host target count $sessionHostTarget, doing nothing"
}
- AnonymousJun 27, 2021I know the sepago solution and I think it was nice before Azure monitor workbook was there, but I'm not talking about monitoring with all kinds of dashboards and graphs, that is all nice but I'm not going to watch a screen the entire day, I just want to receive alerts when available sessions is low.
It think it all has to do with the right LA query, if someone can provide that it would help a lot.- lukemurraynzJun 28, 2021Learn Expert
DeletedHey, Vinisz
I don't have the Kusto query for you, but this could be an alternative option. look at this (full Credit goes to Travis, I just pulled the relevant parts out - replace the hostpool variables with your own), you should be able to turn the below into an Azure Automation runbook to trigger an email based on count:
#https://raw.githubusercontent.com/tsrob50/WVD-Public/master/WVDARM_ScaleHostPoolVMs.ps1
# Set default error action
$defaultErrorAction = $ErrorActionPreference# Enable Verbose logging
$VerbosePreference = 'SilentlyContinue'$hostPoolName = 'avd-pooled'
$hostPoolRg = 'avd_prod'$hostPool = Get-AzWvdHostPool -ResourceGroupName $hostPoolRg -HostPoolName $hostPoolName
$sessionHosts = Get-AzWvdSessionHost -ResourceGroupName $hostPoolRg -HostPoolName $hostPoolName | Where-Object { $_.AllowNewSession -eq $true }
$runningSessionHosts = $sessionHosts | Where-Object { $_.Status -eq "Available" }
# Get the Max Session Limit on the host pool
# This is the total number of sessions per session host
$maxSession = $hostPool.MaxSessionLimit
# Get current active user sessions
$currentSessions = 0
foreach ($sessionHost in $sessionHosts) {
$count = $sessionHost.session
$currentSessions += $count
}
$runningSessionHostsCount = $runningSessionHosts.count
$sessionHostTarget = [math]::Ceiling((($currentSessions) / $maxSession))
if ($runningSessionHostsCount -lt $sessionHostTarget) {
Write-Verbose "Running session host count $runningSessionHostsCount is less than session host target count $sessionHostTarget"}
elseif ($runningSessionHostsCount -gt $sessionHostTarget) {
Write-Verbose "Running session hosts count $runningSessionHostsCount is greater than session host target count $sessionHostTarget"}
else {
Write-Verbose "Running session host count $runningSessionHostsCount matches session host target count $sessionHostTarget, doing nothing"
}- AnonymousJul 12, 2021
lukemurraynz
I'm no powershell guru, but there is not output at all from this script.
Also, it gives an error like:elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + elseif ($runningSessionHostsCount -gt $sessionHostTarget) { + ~~~~~~ + CategoryInfo : ObjectNotFound: (elseif:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException