1

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.

Justin Caldicott
  • 739
  • 8
  • 22
  • 1
    There is an [answer to this question](https://stackoverflow.com/questions/44303809/is-there-any-way-to-set-up-an-alert-on-low-disk-space-for-azure-app-service) that claims to do it. I'm not impressed with the implementation, but if it works you could use it as a guide. – Crowcoder Jul 11 '20 at 11:58
  • 1
    Thanks for your answer Jason, I've not had a chance to review it yet. Will do soon. – Justin Caldicott Jul 14 '20 at 10:37
  • 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 Jul 24 '20 at 16:16

2 Answers2

1

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

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thanks Jason, but I'm looking to get the the amount of free local/temporary storage, not persistent storage which I believe this value is. – Justin Caldicott Jul 24 '20 at 16:15
0

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.

Joaquín Vano
  • 414
  • 1
  • 3
  • 5