Automate Monitoring of Production Capacity Utilization in Frame
Frame® Desktop-as-a-Service (DaaS) provides a detailed scheduling capability to ensure that Frame accounts are able to deliver just-in-time production capacity while minimizing the additional cost of having idle cloud capacity. However, Frame does not currently have the built-in feature to alert administrators when an existing production pool is running out of provisioned capacity. This might lead to users not being able to connect to a session because all of the VMs in the production pool are in use at a moment in time. This blog will demonstrate how the Frame Admin API can be used to monitor the actual number of concurrent sessions and send a message to a Slack® channel when the number of active sessions reaches a certain percentage of the provisioned capacity of a Frame production pool.
![](https://cdn.prod.website-files.com/653fe79c68bb383bddf27e59/66166ff6fa4f87b1808e6c23_Group%20352-min.webp)
WRITTEN BY
TABLE OF CONTENT
Solution Architecture
For this solution, I chose to use a Windows® PowerShell® script running on a Frame Utility server since I had already developed an elasticity management solution that runs as a scheduled task on a Frame Utility server. As with that script, we need to gather some values in order to successfully run the Frame Admin API on that account.
$clnt_id = "<ClientID>"
$clnt_secret = "<ClientSecret>"
$acct_id = "<AccountID>
We also need a way to send a notification when the threshold is exceeded. For this blog, I chose to use a Slack webhook. The Slack webhook allows you to "Post" data which will then show up as a message in a Slack channel. This Slack article explains how to set up a Slack webhook.
The script I developed will poll at a regular interval over a 24-hour period and send an alert to Slack if the number of active sessions in any production pool associated with the Frame account is greater than a fixed percentage. You can downloaded the full script but I will break down the individual pieces below (note the snippets below can not be run independently, but are for illustrative purposes only. Download the full script if you wish to use the script as a starting point for your own purposes).
The Script
The script has two environment variables defined.
$session_threshold = 50
$poll_interval = 15
These variables indicate that the script will check every 15 minutes for pools that have active sessions at 50% capacity and alert if it finds any.
With those two parameters, the first thing the script does is to obtain the name of the Frame account and send a message to Slack to confirm it is monitoring the Frame account.
# Get the name of the account ID in question and alert the slack channel that the monitoring is starting
$req_string ="https://api.console.nutanix.com/v1/accounts/" + $acct_id
$res = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
$acct_name = $res.name
$the_text = "Starting the monitoring of " +$acct_name + " with a threshold of " + $session_threshold + " percent of published capacity."
$body_text = @{
text = $the_text
} | ConvertTo-Json
Invoke-RestMethod -uri $slack_webhook -Method Post -body $body_text
Now we can check the percentage and send a message to Slack if the threshold was met.
# Get the name of the account ID in question and alert the slack channel that the monitoring is starting
$req_string ="https://api.console.nutanix.com/v1/accounts/" + $acct_id
$res = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
$acct_name = $res.name
$the_text = "Starting the monitoring of " +$acct_name + " with a threshold of " + $session_threshold + " percent of published capacity."
$body_text = @{
text = $the_text
} | ConvertTo-Json
Invoke-RestMethod -uri $slack_webhook -Method Post -body $body_text
We use a Frame Admin API call to get the "common name" for the account to improve readability and since Slack wants the body of the post to be a JSON object so we use the "ConvertTo-JSON" function to make sure it is formatted correctly.
![Figure 1. Script Start message in Slack](https://cdn.prod.website-files.com/653fe79c68bb383bddf27e84/6644d128d597a3ff6f45d087_img-ref-frame-1-4644d7546a5b9b9cc5a9c1d6c4eaac25.png)
Next we start a 24-hour loop and grab a list of production pools for the Frame account.
for ($poll=0; $poll -lt [int]((60*24)/$poll_interval); $poll++)
{
# Get the list of production Pools
$req_string ="https://api.console.nutanix.com/v1/accounts/" + $acct_id + "/pools?kind=production"
$res = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
Frame accounts can have multiple production pools if different instance types are used and each pool has its own max capacity so we need to count the active sessions from each pool and compare it to the max capacity for that pool to determine the percentage that is in use.
foreach ($i in $res)
{
if ($i.id -ne $null)
{
$req_string = "https://api.console.nutanix.com/v1/pools/" + $i.id + "/elasticity_settings"
$result1 = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
#Write-Host $i.external_id "------" $result1.max_servers
$sessions = Count-ActivePoolSessions -client_id $clnt_id -client_secret $clnt_secret -acct_id $acct_id -ext_pool_id $i.external_id
Now we can check the percentage and send a message to Slack if the threshold was met.
if([int]($sessions*100/$result1.max_servers) -gt $session_threshold )
{
$the_text = $acct_name + "'s "+ $i.name + " pool is at ``" + [int]($sessions*100/$result1.max_servers) + "`` percent of published capacity."
$body_text = @{
text = $the_text
} | ConvertTo-Json
#Write-Host $body_text
Invoke-RestMethod -uri $slack_webhook -Method Post -body $body_text
}
The message appears as shown below.
![Figure 2. Slack alert message](https://cdn.prod.website-files.com/653fe79c68bb383bddf27e84/6644d128058191f78909b6b3_img-ref-frame-2-bdaf26e393ce7f161620e9dd1ad37091.png)
Once all the pools have been checked, the script sleeps for the polling interval.
Start-Sleep -Seconds ($poll_interval*60)
And when the loop is done, we send a closing message to Slack as shown below.
$the_text = "Completed the monitoring of " +$acct_name
$body_text = @{
text = $the_text
} | ConvertTo-Json
Invoke-RestMethod -uri $slack_webhook -Method Post -body $body_text
![Figure 3. Closing Slack message](https://cdn.prod.website-files.com/653fe79c68bb383bddf27e84/6644d1281760603f610d048a_img-ref-frame-3-04aa3dd6e83eb06d6bbe02f99ee24034.png)
Conclusion
The script does write output to the shell, if run interactively, for debugging purposes, but that is less useful if run as a scheduled task since those messages will not be displayed. Message customization into Slack can be easily accomplished by modifying the text strings that are sent and more complex formatting can be accomplished by searching Slack's documentation. Additionally, other non-Slack notification methods could be used as long as a method of triggering them via PowerShell works. The idea of a script that only runs for 24 hours allows for the monitoring period to be customized to meet the needs of the enterprise. For example, maybe a Monday-Friday schedule is appropriate and monitoring on the weekends less so. In the elasticity blog (linked above), I demonstrated how to create .cmd files that can be scheduled via the built-in Windows Task Scheduler.
Subscribe to our newsletter
Register for our newsletter now to unlock the full potential of Dizzion's Resource Library. Don't miss out on the latest industry insights – sign up today!
![](https://cdn.prod.website-files.com/653fe79c68bb383bddf27e59/6618fa27a818a760b7a3bd84_%5Basset%5D%20Newsletter-min.webp)
Dizzion values your privacy. By clicking on the submit button, you agree to the processing of your personal data in the manner indicated in the Dizzion Privacy Policy and consent to receive communications from Dizzion about our products, services, and events.