1
votes

Azure app services have a limit on the amount of local (temporary) storage used. But, as I understand it, the limit is across the whole app service plan.

I want to maximise usage of the local storage, without hitting the limit. But split across multiple app services in the same app service plan, this gets tricky.

Is there a REST API that returns the app service plan local disk usage? Or even better, some way to get this from the environment?

Usage can be viewed on the Environment tab on Kudu, but I want to do this in code within a running web app.

2
There is an answer to this question that claims to do it. I'm not impressed with the implementation, but if it works you could use it as a guide.Crowcoder
Thanks for your answer Jason, I've not had a chance to review it yet. Will do soon.Justin Caldicott
I didn't see any environment variables that would help either. I may have to resort to catching disk space errors and scaling back the use of local/temporary storage (as a cache) when that is hit. I'll update this if I learn more.Justin Caldicott

2 Answers

0
votes

You can list usages by restapi. There are something wrong when you test in offical document, you need use tools like Postman to test it.

e.g https://management.azure.com/subscriptions/{subscriptions}/resourceGroups/{resourceGroups}/providers/Microsoft.Web/sites/{webappname}/usages?api-version=2019-08-01&$filter=name.value eq 'FileSystemStorage'

enter image description here

0
votes

You can call the GetDiskFreeSpace API to find out disk free space:

public static decimal GetAvailableSpaceInBytes(string path)
{
    uint sectorsPerCluster;
    uint bytesPerSector;
    uint numberOfFreeClusters;
    uint totalNumberOfClusters;

    GetDiskFreeSpace(path, out sectorsPerCluster, out bytesPerSector, out numberOfFreeClusters, out totalNumberOfClusters);
    long bytes = (long)numberOfFreeClusters * sectorsPerCluster * bytesPerSector;
    
    return bytes;
}

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool GetDiskFreeSpace(
    string lpRootPathName,
    out uint lpSectorsPerCluster,
    out uint lpBytesPerSector,
    out uint lpNumberOfFreeClusters,
    out uint lpTotalNumberOfClusters);

Keep in mind that App Service will set quotas to the folders used by the Web App and querying the GetDiskFreeSpace will return the free space in the context of the quotas of the Web App.

It is only interesting to know this for the writable folders for a given Azure App Service Web App.