48 lines
2.0 KiB
SQL
48 lines
2.0 KiB
SQL
SELECT mf.*, volume_mount_point, 1.0 * total_bytes / POWER(1024, 3) AS DISK_SIZE_GB,
|
|
1.0 * available_bytes / POWER(1024, 3) AS FREE_SIZE_GB,
|
|
100 * (1 - 1.0 * available_bytes/total_bytes) PERCENT_USED
|
|
FROM sys.master_files AS mf
|
|
CROSS APPLY sys.dm_os_volume_stats(database_id, file_id);
|
|
|
|
WITH
|
|
disk_activity AS
|
|
(SELECT LEFT(mf.physical_name, 2) AS Drive,
|
|
SUM(num_of_reads) AS num_of_reads,
|
|
SUM(io_stall_read_ms) AS io_stall_read_ms,
|
|
SUM(num_of_writes) AS num_of_writes,
|
|
SUM(io_stall_write_ms) AS io_stall_write_ms,
|
|
SUM(num_of_bytes_read) AS num_of_bytes_read,
|
|
SUM(num_of_bytes_written) AS num_of_bytes_written, SUM(io_stall) AS io_stall
|
|
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs
|
|
INNER JOIN sys.master_files AS mf WITH (NOLOCK)
|
|
ON vfs.database_id = mf.database_id AND vfs.file_id = mf.file_id
|
|
GROUP BY LEFT(mf.physical_name, 2))
|
|
SELECT (SELECT sqlserver_start_time FROM sys.dm_os_sys_info) AS SINCE,
|
|
Drive AS DISK_DRIVE,
|
|
CASE
|
|
WHEN num_of_reads = 0 THEN 0
|
|
ELSE (io_stall_read_ms/num_of_reads)
|
|
END AS READ_LATENCY,
|
|
CASE
|
|
WHEN io_stall_write_ms = 0 THEN 0
|
|
ELSE (io_stall_write_ms/num_of_writes)
|
|
END AS WRITE_LATENCY,
|
|
CASE
|
|
WHEN (num_of_reads = 0 AND num_of_writes = 0) THEN 0
|
|
ELSE (io_stall/(num_of_reads + num_of_writes))
|
|
END AS GLOBAL_LATENCY,
|
|
CASE
|
|
WHEN num_of_reads = 0 THEN 0
|
|
ELSE (num_of_bytes_read/num_of_reads)
|
|
END AS AVG_BYTES_PER_READ,
|
|
CASE
|
|
WHEN io_stall_write_ms = 0 THEN 0
|
|
ELSE (num_of_bytes_written/num_of_writes)
|
|
END AS AVG_BYTES_PER_WRITE,
|
|
CASE
|
|
WHEN (num_of_reads = 0 AND num_of_writes = 0) THEN 0
|
|
ELSE ((num_of_bytes_read + num_of_bytes_written)/(num_of_reads + num_of_writes))
|
|
END AS AVG_BYTES_PER_TRANSFER
|
|
FROM disk_activity AS tab
|
|
ORDER BY GLOBAL_LATENCY
|
|
OPTION (RECOMPILE); |