利用內建函數監控SQL Server 效能和活動 Monitor SQL Server Performance and Activity with Built-In Functions

除了使用交易紀錄檔和Transact-SQL陳述式外,你將發現還有一系列的內建函數可以傳回系統資訊.這裡我大略列出幾個關鍵的內建函數和它們的使用方法.返回的數值都是自SQL Server 最後一次啟動時間之後開始累積來的.

監控 SQL Server 效能和活動的內建函數

函數

描述

範例

@@connections

傳回嘗試連接SQL Server的連接次數

select @@connections as ‘Total Login Attempts”

@@cpu_busy

傳回SQL Server上次啟動之後的工作時間(毫秒為單位)

select @@cpu_busy as ‘CPU Busy’, getdate() as ‘Since’

@@idle

傳回SQL Server的閒置時間(毫秒為單位)

select @@idle as ‘Idle Time’, getdate() as ‘Since’

@@io_busy

傳回SQL Server執行輸入和輸出作業的時間(毫秒為單位)

select @@io_busy as ‘IO Time’, getdate() as ‘Since’ for SQL

@@pack_received

傳回SQL Server 讀取網路中的輸入封包數目

select @@pack_received as ‘Packets Received’

@@pack_sent

傳回SQL Server寫入網路中的輸出封包數目

select @@pack_sent as ‘Packets Sent’

@@packet_errors

SQL Server連接上的網路封包錯誤數目

select @@packet_errors as ‘Packet Errors’

@@timeticks

傳回每個刻度的百萬分之一秒數

select @@timeticks as ‘Clock Ticks’

@@total_errors

傳回SQL Server 磁碟讀取/寫入錯誤數目

select @@total_errors as ‘Total Errors’, getdate() as ‘Since’

@@total_read

傳回SQL Server 磁碟讀取數目

select @@total_read as ‘Reads’, getdate() as ‘Since’

@@total_write

傳回SQL Server磁碟寫入數目

select @@total_write as ‘Writes’, getdate() as ‘Since’

fn_virtualfilestats

傳回資料庫檔案的I/O統計資料

select * from fn_virtualfilestats(null,null)

來源出處: Microsoft Press book Microsoft SQL Server 2008 Administrator’s Pocket Consultant