Resources

Arrow Image

Blog & News

Arrow Image

Automate Monitoring of Production Capacity Utilization in Frame

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.

News & Blog

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
Figure 1. Script Start message in Slack

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
Figure 2. Slack alert message

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
Figure 3. Closing Slack message

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.

About the Author

Dizzion

Dizzion was founded in 2011 with a visionary mission to redefine the way the world works.

In an era of legacy Virtual Desktop Infrastructure (VDI), Dizzion set out to challenge the status quo by making it simple for all customers to transform their workspace experience. By building a powerful automation and services platform on top of the VMware stack, Dizzion delivered virtual desktops as a service before Desktop as a Service (DaaS) even existed.

David Horvath

Senior Solutions Architect

William Wong is the VP of Service Delivery for Dizzion, responsible for service delivery (professional and managed services), solutions architecture, and support. He works actively with customers to transform their business and operations leveraging DaaS in a hybrid and multi-cloud world. Before joining Dizzion as part of the Frame spinout from Nutanix, William was Head of Enterprise Solutions at Frame and following Nutanix's acquisition of Frame in 2018, Director of Solutions Architecture (Frame) at Nutanix. Prior to his work in DaaS, William led the development and adoption of innovative Internet software solutions and services, including Internet-based credit card and check processing and eCommerce platforms. William spent over 30 years at Cancer Commons, NetDeposit, Hewlett-Packard, VeriFone, and multiple Internet, payment, and eCommerce startups in executive management, program management, engineering management, and executive advisory positions. William received his B.S., M.S., and Ph.D. in Electrical Engineering from Stanford University.

More about the author

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!