Unlike AWR in Oracle, Sqlserver does not have offical way to make history performance information for checking. until today.

I made it. you can deploy it safe and easy.

Needless to day:

getCPU

CREATE PROCEDURE [dbo].[getCPU]
AS
BEGIN

DECLARE @ts_now bigint = (SELECT cpu_ticks/(cpu_ticks/ms_ticks)FROM sys.dm_os_sys_info);

SELECT TOP(500) SQLProcessUtilization AS [SQL Server Process CPU Utilization],
SystemIdle AS [System Idle Process],
100 - SystemIdle - SQLProcessUtilization AS [Other Process CPU Utilization],
DATEADD(ms, -6 * (@ts_now - [timestamp]), GETDATE()) AS [Event Time]
FROM (
SELECT record.value('(./Record/@id)[1]', 'int') AS record_id,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int')
AS [SystemIdle],
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]',
'int')
AS [SQLProcessUtilization], [timestamp]
FROM (
SELECT [timestamp], CONVERT(xml, record) AS [record]
FROM sys.dm_os_ring_buffers
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
AND record LIKE '%<SystemHealth>%') AS x
) AS y
ORDER BY record_id DESC;

END

getperformancetest

CREATE PROCEDURE [dbo].[getperformancetest]
AS
BEGIN

SELECT TOP 10

Left(SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1

, ((CASE qs.statement_end_offset

WHEN -1 THEN DATALENGTH(qt.TEXT)

ELSE qs.statement_end_offset

END - qs.statement_start_offset)/2)+1), 200) AS "SQL_TEXT"

, qs.execution_count

, qs.total_worker_time /qs.execution_count/1000 as avg_worker_time

, qs.total_elapsed_time /qs.execution_count /1000 as avg_elapsed_time

, qs.total_physical_reads /qs.execution_count as avg_physical_reads

, qs.total_logical_reads /qs.execution_count as avg_logical_reads

, qp.query_plan

--, CAST(qp.query_plan AS nvarchar(max)) query_plan

FROM sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt

CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp

WHERE qs.last_execution_time > dateadd(minute, -1, getdate())

ORDER BY qs.total_elapsed_time/qs.execution_count DESC

END

checkcputest

create PROCEDURE [dbo].[checkcputest]
AS
BEGIN

DECLARE @SQL2 VARCHAR(MAX)
DECLARE @createtable VARCHAR(MAX)
DECLARE @inserttable VARCHAR(MAX)
DECLARE @inserttable2 VARCHAR(MAX)
DECLARE @@tablename2 VARCHAR(MAX)

SELECT @SQL2 = (select replace(replace(replace(CONVERT(varchar, getdate(), 112 ),'-',''),' ',''),':',''))

set @createtable='create table cpu_'+@SQL2+' ([SQLProcessUtilization] [numeric](3,0),[SystemIdle] [numeric](3,0),[OtherUtilization] [numeric](3,0),[eventime] [datetime2]) ON [PRIMARY];'

exec(@createtable)

set @inserttable='insert into cpu_'+@SQL2+' exec [dbo].[getCPU]'

exec(@inserttable)

END

checkperformancetest

create PROCEDURE [dbo].[checkperformancetest]
AS
BEGIN

DECLARE @SQL2 VARCHAR(MAX)
DECLARE @createtable VARCHAR(MAX)
DECLARE @inserttable VARCHAR(MAX)
DECLARE @inserttable2 VARCHAR(MAX)
DECLARE @@tablename2 VARCHAR(MAX)

SELECT @SQL2 = (select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':',''))

set @createtable='create table perf_'+@SQL2+' ([SQL_TEXT] [nvarchar](max),[execution_count] [numeric](18, 0),[avg_worker_time] [numeric](18, 0),[avg_elapsed_time] [numeric](18, 0),[avg_physical_reads] [numeric](18, 0),[avg_logical_reads] [numeric](18, 0),[query_plan] [xml]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];'

exec(@createtable)

set @inserttable='insert into perf_'+@SQL2+' exec [dbo].[getperformancet

exec(@inserttable)

END

showdelperftable

CREATE PROCEDURE [dbo].[showdelperftable] @days int
AS
BEGIN

select 'drop table dbo.'+name from sys.tables where name like 'perf_%' and create_date < dateadd(day, @days, getdate())
order by name asc,create_date asc

END

checkoldtable2

CREATE PROCEDURE [dbo].[checkoldtable2] @days int
AS
BEGIN
declare @m int
declare @n int
declare @tmp nvarchar(MAX)

declare @droptableList TABLE (id int IDENTITY(1,1) NOT NULL,contents VARCHAR(35) NOT NULL)
SET NOCOUNT ON

INSERT @droptableList (contents) exec showdelperftable @days

set @m=(select count(*) from @droptableList)

set @n=1

while @n<=@m
begin

set @tmp=(select contents from @droptableList where id=@n)
exec (@tmp)
--print (@tmp+CHAR(5))
set @n=@n+1

end
end

checkperformance_every_6_minutes

exec checkperformancetest
go

heckoldtable2_daily_08:30

EXEC checkoldtable2 -7
go

checkcputest_daily_09:00
EXEC checkcputest
go

you can see final example

free to monitor your sqlserver easy and safe and ...的更多相关文章

  1. Open Sourcing Kafka Monitor

    https://engineering.linkedin.com/blog/2016/05/open-sourcing-kafka-monitor     https://github.com/lin ...

  2. JTAG 引脚自动识别 JTAG Finder, JTAG Pinout Tool, JTAG Pin Finder, JTAG pinout detector, JTAGULATOR, Easy-JTAG, JTAG Enumeration

    JTAG Finder Figuring out the JTAG Pinouts on a Device is usually the most time-consuming and frustra ...

  3. Posterior visual bounds retrieval for the Plato framework

    Plato is a MVVM compliant 2D on-canvas graphics framework I've been designing and implementing for d ...

  4. 每日英语:Success Outside the Dress Code

    Anyone who has felt like the odd duck of the group can take heart from new research from Harvard Bus ...

  5. Arduino VS. Raspberry Pi VS. Beaglebone Black

    The Arduino is a small Atmel-based microcontroller development board easily integrated into many dif ...

  6. 必读的 Android 文章

    必读的 Android 文章 掘金官方 关注 2017.06.07 13:58* 字数 25218 阅读 8782评论 2喜欢 218 写给 Android 开发者的混淆使用手册 - Android ...

  7. ##C++ format 格式化字符串

    C++ format 格式化字符串实现方式 1. http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprint ...

  8. Going Deeper with Convolutions阅读摘要

      论文链接:Going deeper with convolutions 代码下载: Abstract We propose a deep convolutional neural network ...

  9. nuros安全报告

    We believe that great technology should benefit everyone. Self-driving vehicles promise to save live ...

随机推荐

  1. OGG在windows环境下字符集的配置

    windows环境下不配置字符集(默认使用windows自己的字符集),从linux等系统同步过来的表中如果含有中文字符列将显示为乱码,被ogg误认为虚拟列,从而导致进程abend. 设置ogg进程在 ...

  2. Java SimpleDateFormat 日期-时间格式参数

    字母          日期或时间元素 表示          示例           G     Era 标志符 Text  AD y 年 Year 1996; 96 M 年中的月份 Month ...

  3. HDU 1312 Red and Black(经典DFS)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...

  4. layui 延时加载

    //延时关闭当前页面,并刷新父页面layer.msg('提交成功',{time: 1800},function () { parent.layer.close(index); window.paren ...

  5. 微信小程序媒体音乐API更新小记,以及音乐外链制作方法

    假期开发微信小程序玩的时候发现音乐播放功能,但是教程中的旧版API已经不能成成功打开 官方文档写的很清楚,旧版接口不再维护,使用新版接口,换API后,又出现了新的问题,虽然没有报错信息,但是播放器闪退 ...

  6. php mongdb driver 1.17

    Installation To build and install the driver: $ pecl install mongodb $ echo "extension=mongodb. ...

  7. 匹配 $gdinfo 中的数字

    <?php /* //下载 $filename = 'av.zip'; // 设置类型:可以省略 // header("content-type:image/jpeg"); ...

  8. ETCD授权认证

    export ETCDCTL_API=3 ENDPOINTS=localhost:2379 etcdctl --endpoints=${ENDPOINTS} role add root etcdctl ...

  9. 【转】弹出USB大容量存储设备时出问题的解决方法

    原文链接 如下图所示,这个问题,相信很多人都有遇到过,而且经常难以解决,试了很多方法都无效.到最后,只能抱着侥幸的心理直接拔出,如果运气好,可能没有事,如果运气不好,你的U盘或者移动硬盘就要从此报废了 ...

  10. ANSYS热分析简介1

    目录 1. ANSYS热分析简介 1.1 传导 1.2 热载荷分类 1.2.1 载荷施加 1.3 热分析分类 1.3.1 稳态热分析 1.3.2 瞬态热分析 1.3.3 非线性分析综述 2. 热分析单 ...