This commit is contained in:
2025-02-27 11:46:26 +01:00
parent d9af559839
commit 2aa04c696b
16 changed files with 1456 additions and 17 deletions

View File

@@ -85,21 +85,37 @@ WHERE f.type_desc IN (
ORDER BY [d2].[row_size_mb] DESC, d.name DESC, f.name ASC ;
--free disk space
SELECT DISTINCT
CONVERT(VARCHAR(512), [b].[volume_mount_point]) AS [volume_mount_point],
CONVERT(VARCHAR(512), [b].[logical_volume_name]) AS [logical_volume_name],
CONVERT(
DECIMAL(18, 1),
ROUND(((CONVERT(FLOAT, [b].[available_bytes]) / CONVERT(FLOAT, [b].[total_bytes])) * 100), 1)) AS [percent_free],
CONVERT(BIGINT, ROUND((([b].[available_bytes] / 1024.0) / 1024.0 / 1024.0), 0)) AS [free_gb],
CONVERT(BIGINT, ROUND((([b].[available_bytes] / 1024.0) / 1024.0 ), 0)) AS [free_mb],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0 / 1024.0), 0)) AS [total_gb],
CONVERT(BIGINT, ROUND(((([b].[total_bytes] - [b].[available_bytes]) / 1024.0) / 1024.0 / 1024.0), 0)) AS [used_gb],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 5 / 1024.0 AS [5% space in Go is],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 10 / 1024.0 AS [10% space in Go is],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 15 / 1024.0 AS [15% space in Go is],
CURRENT_TIMESTAMP AS now,
REPLACE(@@SERVERNAME, '\apssql', '') AS srvName
SELECT
CONVERT(VARCHAR(512), [b].[volume_mount_point]) AS [volume_mount_point],
CONVERT(VARCHAR(512), [b].[logical_volume_name]) AS [logical_volume_name],
CONVERT(DECIMAL(18, 1), ROUND(((SUM(CONVERT(FLOAT, [b].[available_bytes])) / SUM(CONVERT(FLOAT, [b].[total_bytes]))) * 100), 1)) AS [percent_free],
CONVERT(BIGINT, ROUND(((SUM([b].[available_bytes]) / 1024.0) / 1024.0 / 1024.0), 0)) AS [free_gb],
CONVERT(BIGINT, ROUND(((SUM([b].[available_bytes]) / 1024.0) / 1024.0), 0)) AS [free_mb],
CONVERT(BIGINT, ROUND(((SUM([b].[total_bytes]) / 1024.0) / 1024.0 / 1024.0), 0)) AS [total_gb],
CONVERT(BIGINT, ROUND((((SUM([b].[total_bytes] - [b].[available_bytes])) / 1024.0) / 1024.0 / 1024.0), 0)) AS [used_gb],
CONVERT(BIGINT, ROUND(((SUM([b].[total_bytes]) / 1024.0) / 1024.0), 0)) / 100 * 5 / 1024.0 AS [5% space in Go is],
CONVERT(BIGINT, ROUND(((SUM([b].[total_bytes]) / 1024.0) / 1024.0), 0)) / 100 * 10 / 1024.0 AS [10% space in Go is],
CONVERT(BIGINT, ROUND(((SUM([b].[total_bytes]) / 1024.0) / 1024.0), 0)) / 100 * 15 / 1024.0 AS [15% space in Go is],
CURRENT_TIMESTAMP AS now,
REPLACE(@@SERVERNAME, '\apssql', '') AS srvName
FROM sys.master_files AS [a]
CROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) AS [b]
ORDER BY [percent_free] ASC;
CROSS APPLY (
SELECT [x].[database_id],
[x].[file_id],
[x].[volume_mount_point],
[x].[volume_id],
[x].[logical_volume_name],
[x].[file_system_type],
[x].[total_bytes],
[x].[available_bytes],
[x].[supports_compression],
[x].[supports_alternate_streams],
[x].[supports_sparse_files],
[x].[is_read_only],
[x].[is_compressed],
ROW_NUMBER() OVER (PARTITION BY [x].[volume_mount_point]
ORDER BY [x].[volume_mount_point] DESC) AS rnk
FROM sys.dm_os_volume_stats(a.database_id, a.[file_id]) x ) b
WHERE [b].[rnk] = 1
GROUP BY [b].[logical_volume_name], [b].[volume_mount_point]
ORDER BY [b].[volume_mount_point] ASC;