How to find total used and remaining space in Azure SQL mi I queried sp_databases and the sum of space occupied by all db's was 380Gb. The total allocated space for the managed instance is 800Gb. 

But, enquiring with the infra team found that we have only 40gb of space left.

What am I getting wrong here? How to check the total used and remaining space in a MI.?
sp_databases doesn't seem to be applies to Azure SQL Database (as per MS Official Documentation) which is the same case for sys.dm_os_volume_stats and sys.master_files.   

However, you may want try with following query, this basically gives break-down of utilized and available space with all mounted drives that are hosting database related files.  


SELECT  SERVERPROPERTY('MachineName') as HostName,
        volume_mount_point, 
        max(total_bytes / 1048576.0) / 1024 as TotalSize_Gb, 
        max(available_bytes / 1048576.0) / 1024 as Avalable_Size_Gb 
FROM sys.master_files AS f  
    CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.file_id)
Group by volume_mount_point
go

select DB_NAME(database_id) as DBName, 
        SUM (CASE WHEN type_desc = 'ROWS' THEN ((size * 8) / 1024.0)/1024 end) as Data_Size_GB,
        SUM (CASE WHEN type_desc = 'LOG' THEN ((size * 8) / 1024.0)/1024 end) as Log_Size_GB,
        SUM (CASE WHEN type_desc = 'ROWS' THEN ((size * 8) / 1024.0)/1024 end) +
        SUM (CASE WHEN type_desc = 'LOG' THEN ((size * 8) / 1024.0)/1024 end) as Total_Size_GB
from sys.master_files
group by database_id
go