Geeks With Blogs

News This is the *old* blog. The new one is at
Elton Stoneman
This is the *old* blog. The new one is at

This follows on from my last post, Hey Azure, how’s my Cloud Service doing? and it looks at getting similar metrics for Web Apps (née “Azure Websites”).

Web Apps expose a lot of the same detail as Cloud Services through the service APIs, although the content isn’t exactly the same. Here’s how my dashboard looks with key details for one running Web App:


The status block on the left tells me the website name (which would include the slot name if this wasn’t the primary slot), current status and the name of the Web Space and App Service Plan the site is running in. There’s no option to label deployments for Web Apps at the moment, but showing the Web Space & Plan is useful – it shows which sites are sharing the same infrastructure, so you can see where you’re compressing multiple sites into one space.

The CPU metric is different from Cloud Services in that it show the number of milliseconds of compute time being used, as opposed to the percentage CPU. That’s because Web Spaces may be on shared infrastructure, so you don’t get a fixed CPU allocation to see a percentage of. For the sake of the dashboard though, seeing the trend is more important than the absolute value, so the graph is showing millisecond usage at snapshots.

Lastly the scale block – how many nodes are currently running and what size are they, together with the auto-scale settings configured for the App Service Plan.

Web App Details

To get the basic Web App details, we’ll use the WebSiteManagementClient class. The current release of Microsoft.WindowsAzure.Management.WebSites on NuGet is which uses the ‘old’ API pattern – getting a Microsoft.WindowsAzure.SubscriptionCloudCredentials object to authenticate, and then using the CloudContext class to get the API client:

var model = new WebApp();
using (var client = CloudContext.Clients.CreateWebSiteManagementClient(credentials))
    var site = await client.WebSites.GetAsync(_webSpaceName, _webSiteName, new WebSiteGetParameters());
    var website = site.WebSite;

    model.Name = website.Name;
    model.Status = website.State;
    model.WebSpaceName = _webSpaceName;
model.AppServicePlan = website.ServerFarm;

(Compare that to the newer way in Microsoft.WindowsAzure.Management.Compute version where you use a Microsoft.Azure.SubscriptionCloudCredentials object and then new-up the API client directly, without using CloudContext).

You have to load the Web App from the Web Space name and the Web App name, and you can pass a list of additional properties you want to fetch in the WebSiteGetParameters object – like the AppSettings the site is configured with. You get a whole host of details back in the WebSite object, including the SSL configuration, host names in use, and the usage state – which will tell you if the site has exceeded its quota.

Runtime Metrics

You can use the MetricsClient in the same way for Web Apps as Cloud Services, using the ResourceIdBuilder to get the resource ID, but the management client gives you a shortcut so you don’t need to fire up another type of client. For Web Apps you can call GetHistoricalUsageMetrics() passing in a list of metric names you want to retrieve – e.g. ‘CpuTime’ to get the CPU usage in milliseconds – and the time grain.

The API uses xsd:duration format to specify time periods (which gets my vote, because they’re easier to read and harder to get wrong than timespans), so PT1M gets you CPU usage at one-minute intervals:

var metrics = await client.WebSites.GetHistoricalUsageMetricsAsync(_webSpaceName, _webSiteName, new WebSiteGetHistoricalUsageMetricsParameters
    MetricNames = new[] { "CpuTime" },
    TimeGrain = "PT1M"
var latestCpuTimes = metrics.Where(x => x.Data.Name == "CpuTime").Take(1);
var averageCpuTime = latestCpuTimes.Sum(x => x.Data.Values.Sum(y => long.Parse(y.Total)));
model.LatestCpu = new CpuMetric
    MetricName = "CpuTime",
    Value = averageCpuTime

You’ll get back an enumerable of HistoricalUsageMetric objects, which you can plot individually or aggregate. In this code I’m taking the latest minute, but the usage is cumulative, so my CPU graph is an upward trend summary rather than a detailed plot. (The new Azure Portal shows Web App usage as percentages for CPU and Memory, which is better I think, so I may change my dashboards to show the same).

Auto Scale Setup

For the scale data, we get the current setup from the Web Sites management client, and the auto-scale setup (if any), from the generic Autoscale client. Internally the Azure APIs call App Service Plans server farms, which is a more logical name, so we get the current scale and auto-scale at the Server Farm level:

var plan = await client.WebHostingPlans.GetAsync(_webSpaceName, site.WebSite.ServerFarm);
model.CurrentScale = new CurrentScale
    Count = plan.WebHostingPlan.NumberOfWorkers.Value,
    Size = plan.WebHostingPlan.WorkerSize.Value.ToString()

var resourceId = AutoscaleResourceIdBuilder.BuildWebSiteResourceId(_webSpaceName, site.WebSite.ServerFarm);
var autoScaleLoader = new AutoScaleLoader();
model.AutoScale = await autoScaleLoader.LoadAsync(resourceId);
Other than using a different resource ID, the auto-scale details come in the same way as for Cloud Services, so I’ve extracted that into a separate AutoScaleLoader

Sample Data

The model I fill with the various loaders is very similar to the Cloud Service model, and when it’s populated it looks like this:

    "Name": "my-web-app",
    "WebSpaceName": "NorthEuropewebspace",
"AppServicePlan" : "Default2",
"Status": "Running", "CurrentScale": { "Count": 1, "Size": "Small" }, "AutoScale": { "UpCount": 1, "UpMetricName": "AveragePercentageCpu", "UpThreshold": 90.0, "DownCount": 1, "DownMetricName": "AveragePercentageCpu", "DownThreshold": 75.0 }, "LatestCpu": { "Value": 57.0, "MetricName": "CpuTime" } }

One thing to be aware of with Web Apps is that in the current portal auto-scale is configured as a CPU percentage (in this case, scaling up by one server at 90% and down by one server at 75%), but the actual metrics we can see are for CPU time in milliseconds. That’s why the model includes the metric name, so we can see whether the current load and auto-scale are using the same metrics.

Really, no github link?

Not yet. There’s one more of these to come, on loading stats for Azure Storage Accounts, and then I’ll release V1 of the dashboard.

Posted on Tuesday, July 7, 2015 12:19 PM Azure | Back to top

Comments on this post: Hey Azure, how's my Web App doing?

# re: Hey Azure, how's my Web App doing?
Requesting Gravatar...
Thanks for an amzing app. This app currently available on Appvn App store.
Left by Morgon on Aug 28, 2016 3:35 PM

# re: Hey Azure, how's my Web App doing?
Requesting Gravatar...
That is really good app I downloaded this app from Appvn App Store
Left by Jhonrey on Dec 10, 2016 2:31 PM

# re: Hey Azure, how's my Web App doing?
Requesting Gravatar...
Thanks for such a great app and I need app like Kingroot please make such apps tokingroot download
Left by Kishore on Dec 10, 2016 2:34 PM

# re: Hey Azure, how's my Web App doing?
Requesting Gravatar...
Thanks for providing the info to get this app.Delta ios emulator is the best solution for all the game lovers problems to play all kinds of games for free.
Left by sarah on Dec 30, 2016 7:08 PM

# re: Hey Azure, how's my Web App doing?
Requesting Gravatar...
nice article have a look at these site appvn in the ios devices for the movies apps,
Left by aaaaa on Jan 13, 2017 8:47 AM

# app download
Requesting Gravatar...
the app fastpokemon apk for your devices
downloads range between 0 and 0 as
Left by pokemap on Feb 04, 2017 7:21 PM

# drama
Requesting Gravatar...
greate article to exiting ondemandkorea app
Left by lovely on May 06, 2017 4:35 PM

Your comment:
 (will show your gravatar)

Copyright © Elton Stoneman | Powered by: