free to monitor your sqlserver easy and safe and ...
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 ...的更多相关文章
- Open Sourcing Kafka Monitor
https://engineering.linkedin.com/blog/2016/05/open-sourcing-kafka-monitor https://github.com/lin ...
- 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 ...
- 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 ...
- 每日英语: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 ...
- Arduino VS. Raspberry Pi VS. Beaglebone Black
The Arduino is a small Atmel-based microcontroller development board easily integrated into many dif ...
- 必读的 Android 文章
必读的 Android 文章 掘金官方 关注 2017.06.07 13:58* 字数 25218 阅读 8782评论 2喜欢 218 写给 Android 开发者的混淆使用手册 - Android ...
- ##C++ format 格式化字符串
C++ format 格式化字符串实现方式 1. http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprint ...
- Going Deeper with Convolutions阅读摘要
论文链接:Going deeper with convolutions 代码下载: Abstract We propose a deep convolutional neural network ...
- nuros安全报告
We believe that great technology should benefit everyone. Self-driving vehicles promise to save live ...
随机推荐
- 使用node.js实现多人聊天室(socket.io、B/S)
通过B/S架构实现多人聊天,客户端连接服务器,发送信息,服务器接收信息之后返回给客户端. 主要是通过socket.io实现浏览器和服务器之间进行实时,双向和基于事件的通信. socket.io官方文档 ...
- wordpress 修改默认分页条数
哎,终于快做完了,今天弄了弄分页,真是网上扒的模板太高级了,把分页和导航的css和js冲突了,终于解决了, 然后有一个模板是三和一排显示的,其他的是单挑显示的,它默认10条,我寻思改成9条,找了半天, ...
- Android SDK Tools,Platform-tools,Build-tools分别有什么作用?
SDK Tools:是下载sdk最基础的,由它再来下载Platform-tools,Build-tools platform-tools包含开发app的平台依赖的开发和调试工具,包括 adb.fast ...
- STM32 MDK C 常见易错点
1.MDK编译器单字节的负数-1,-2,-3... ... 处理:存储,类型转换,位对齐. char 定义的变量在运算过程尤其类型转换,逻辑比大少会被当做 unsigned char 处理,这里很容易 ...
- 三星前有note7,现有GalaxyS10,爆炸原因外力?
编辑 | 于斌 出品 | 于见(mpyujian) 提到三星,不知道大家什么感觉,反正首先映入脑海的是在Note 7系列爆炸中,三星就让中国消费者欲哭无泪的画面.而也正是三星的态度,三星手机在这件事情 ...
- 安卓之视图View的基本属性
一.在xml布局文件中常用的属性定义 (1) id:指定该视图的编号 (2) layout_width:指定该视图的宽度可以是具体的dp值:可以是match_parent,表示与上级视图一 ...
- Javascript——(1)
1.Javascript有两种解释表示形式:1)在html的<header>中写<script><script/>,另一种是将另一个文件保存为xxx.js文档,然后 ...
- gitlab回退到某次commit——本地+远程
## 查看所有commits记录$ git log ## gitlab回退到某次commit$ git reset --hard 3018a546427e1f865524b82b488d6a2721d ...
- C++11特性中的to_string
写在最前面,本文摘录于柳神笔记 to_string 的头⽂件是 #include , to_string 最常⽤的就是把⼀个 int 型变量或者⼀个数字转化 为 string 类型的变量,当然也可以转 ...
- Nginx企业级优化!(重点)
隐藏Nginx版本号!(重点) 在生产环境中,需要隐藏 Nginx 的版本号,以避免安全漏洞的泄漏 一旦有黑客知道Nginx版本号便可以利用Nginx漏洞进行攻击,严重影响到了公司的安全 查看隐藏版本 ...