Download App Service Plan CPU %age using a script

Chris Hammond 21 Reputation points
2021-06-16T08:30:38.58+00:00

I need to do some consolidation on my Azure estate, especially around App Service Plans.

Typically, we would usually create a new App Service Plan for each service we deployed as this would aid us with departmental cross-charging as each ASP would be tagged with each department's cost code.

We now have a massive sprawl of ASPs and each one is probably not running anywhere near capacity, even at S1 level so we're now looking to a more simplified model. And we probably have some over-scaled ASPs that we planned but are never actually needed.

What I would like to do is to have a script (Graph Explorer, PowerShell, C#) that would download the max and/or average CPU useage of over 100 ASPs over a period of time (say, 6 months) and then I can run some "what-if" scenarios on the data once i have it.

I know you can "share -> download" from each individual ASP but with the amount of ASPs we have, that would take forever to do ...

Thanks.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,758 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 26,131 Reputation points Microsoft Employee
    2021-07-13T08:19:28.577+00:00

    To benefit the community; Sharing our offline discussion (cost optimization).

    Firstly, to provide some background on App Service charges - At a basic level, App Service apps are charged by the App Service Plan (ASP) that hosts them.

    The costs associated with your App Service deployment depend on a few main factors:
    Pricing tier SKUs ( S0/1/2/3/4). As you’re aware, higher tiers provide more CPU cores, memory, storage, or features, or combinations of them.
    Instance count dedicated tiers (Basic and above) can be scaled out, and each scaled out instance accrues costs.

    As far as tackling the App Service Plan scale-out (horizontal scaling), the recommended approach would be to leverage the Auto scale built-in feature.
    Autoscale helps applications perform at their best when demand changes. You can configure custom Autoscale policy that scales based on metric(s) thresholds, or schedule instance count which scales during designated time windows.
    Autoscale enables your resource to be performant and cost-effective by adding and removing instances based on demand.

    The example you highlighted is very much possible with Autoscaling.
    With autoscale, you can configure rules that monitor the App Service plan metrics. Rules can increase or decrease the instance count, which can provide additional resources as needed.
    These Rules also help you save money when the app is over-provisioned.

    See - Get started with Autoscale in Azure

    Cost Optimization techniques:
    With Cost Analysis, you can fetch drill-down cost info by App Service | Resource, Service tier (screenshot below).
    Based on your requirement, you could also leverage other feature for further cost optimization - ‘cost alerts’ , ‘budgets’, export, etc.
    -You can also download the usage for any stipulated period.

    Please see these docs:
    Plan and manage costs for Azure App Service
    Quickstart: Explore and analyze costs with cost analysis

    I see there is no direct way to fetch consolidated info for all ASPs. You may leverage Azure Cost Management APIs – it provides the ability to explore cost and usage data.

    114146-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.