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. SDNU_ACM_ICPC_2020_Winter_Practice_2nd

    A - [The__Flash]的矩阵 给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大. Input输入数据的第一行为一个正整数T,表示有T组测试数据.每一组测试数据 ...

  2. netty(一)---服务端源码阅读

    NIO Select 知识 select 示例代码 : //创建 channel 并设置为非阻塞 ServerSocketChannel serverChannel = ServerSocketCha ...

  3. 【PAT甲级】1069 The Black Hole of Numbers (20 分)

    题意: 输入一个四位的正整数N,输出每位数字降序排序后的四位数字减去升序排序后的四位数字等于的四位数字,如果数字全部相同或者结果为6174(黑洞循环数字)则停止. trick: 这道题一反常态的输入的 ...

  4. zookeeper的安装(单机版)

    一.获取zookeeper的安装包 zookeeper的官网下载:wget  https://archive.apache.org/dist/zookeeper/zookeeper-3.4.10/zo ...

  5. 使用js制作 下拉选择日期列表 (即日期选择器)

    上代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...

  6. C# 面试编程算法题

    求以下表达式的值: 1. 1 - 2 + 3 - 4 + … + m public static int Foo1(int m) { ; ; i <= m; i++) { == ) { sum ...

  7. unittest和unittest2的区别差异、unittest2框架------执行原理

    unittest和unittest2的区别差异 参考:https://pypi.org/project/unittest2/ unittest2是Python 2.7及更高版本中添加到unittest ...

  8. Java 基础--移位运算符

    移位运算符就是在二进制的基础上对数字进行平移.按照平移的方向和填充数字的规则分为三种: <<(左移).>>(带符号右移)和>>>(无符号右移). 1.左移 按 ...

  9. mcast_block_source函数

    #include <errno.h> #include <sys/socket.h> #define SA struct sockaddr int mcast_block_so ...

  10. nginx反向代理实战之轮询、Ip_hash、权重

    实验环境 192.168.200.111 web1 centos7 192.168.200.112 web2 centos7 192.168.200.113 wev3 centos7 三台主机环境: ...