@irshadTo configure autoscaling for a Virtual Machine Scale Set (VMSS) behind an Azure Application Gateway based on the number of concurrent sessions, you'll need to follow these steps:
1- Create an Azure Application Gateway:
If you haven't already, create an Azure Application Gateway and configure it to route traffic to
your VMSS. Follow the instructions in the Microsoft documentation for setting up an
Application Gateway with VMSS:
https://docs.microsoft.com/en-us/azure/application-gateway/configure-autoscaling-vmss
2- Create a custom metric for concurrent sessions:
Unfortunately, Azure Monitor does not provide a built-in metric to monitor concurrent
sessions directly. Instead, you can use the Application Gateway's "Active Connections" metric
as a proxy for concurrent sessions. Alternatively, you can use a custom metric from your
application to monitor concurrent sessions. To do this, you will need to configure your
application to send custom metrics to Azure Monitor using the Application Insights SDK or
another supported method:
https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource
3- Create an autoscale setting for your VMSS based on the custom metric:
Once you have a custom metric or you're using the "Active Connections" metric, you can
create an autoscale setting for your VMSS based on that metric. Follow these steps to
configure autoscaling based on a custom metric:
a. In the Azure Portal, navigate to your VMSS resource.
b. Click on "Scaling" under the "Settings" section.
c. Click on "Add a rule" and configure the scale-out rule:
- Select your custom metric or "Active Connections" from the "Metric" dropdown.
- Set the "Aggregation type" to "Average" or another appropriate option.
- Configure the "Operator" and "Threshold" according to your requirements, e.g., Operator:
Greater than, Threshold: 100 (for 100 concurrent sessions).
- Set "Duration" to the desired time window for the metric evaluation.
- Set "Action" to "Increase count by" and choose the number of instances to add when
scaling out.
d. Configure a scale-in rule similarly, with an appropriate threshold and "Decrease count by"
action.
e. Save the rules and set the "Cooldown" period to the desired value.
With these configurations in place, your VMSS will automatically scale out when the concurrent sessions (or active connections) increase beyond the defined threshold and scale in when the load decreases.