sp_monitor (Transact-SQL)

适用范围:SQL Server

显示有关 SQL Server 的统计信息。

Transact-SQL 语法约定

语法

sp_monitor
[ ; ]

参数

无。

返回代码值

0(成功)或 1(失败)。

结果集

列名 说明
last_run 上次运行时间 sp_monitor
current_run 正在运行时间 sp_monitor
seconds 自运行以来 sp_monitor 的已用秒数。
cpu_busy 服务器计算机的 CPU 已完成 SQL Server 工作的秒数。
io_busy SQL Server 执行输入和输出操作所用的秒数。
idle SQL Server 空闲的秒数。
packets_received SQL Server 读取的输入数据包数。
packets_sent SQL Server 写入的输出数据包数。
packet_errors 读取和写入数据包时 SQL Server 遇到的错误数。
total_read SQL Server 读取次数。
total_write SQL Server 的写入数。
total_errors 读取和写入时 SQL Server 遇到的错误数。
connections 登录到 SQL Server 或尝试登录的登录次数。

注解

SQL Server 通过一系列函数跟踪已完成多少工作。 执行 sp_monitor 显示这些函数返回的当前值,并显示自上次运行过程以来更改了多少。

对于每列,统计信息以表单编号(number)或 number(number打印。 第一个 数字 是指自 SQL Server 重新启动以来的秒数(for cpu_busyio_busyidle)或总数(对于其他变量)。 括号中的数字是指自上次运行以来sp_monitor的秒数或总数。 百分比是自上次运行以来 sp_monitor 的时间百分比。 例如,如果报告显示cpu_busy4250(215)-68%,自上次启动 SQL Server 以来 CPU 正忙 4,250 秒,自上次运行以来为 215 秒sp_monitor,自上次运行以来sp_monitor的总时间的 68%。

权限

需要 sysadmin 固定服务器角色的成员身份,或直接在此存储过程上执行权限。

示例

以下示例报告有关 SQL Server 繁忙程度的信息。

USE master;
GO

EXEC sp_monitor;

下面是结果集:

last_run                   current_run                seconds
-----------------------    -----------------------    ---------
2024-05-01 15:27:51.287    2024-08-21 17:20:34.097    9683563

cpu_busy           io_busy         idle
---------------    -------------   --------------------
14452(14451)-0%    2555(2554)-0%   4371742(4371629)-45%

packets_received       packets_sent    packet_errors
----------------       ------------    -------------
18032(17993)           64572(64533)    0(0)

total_read     total_write   total_errors    connections
-----------    -----------   -------------   --------------
1593(1593)     4687(4687)    0(0)            155625(155557)