-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fce0da
commit 4136718
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- https://github.com/Microsoft/azuredatastudio/tree/master/samples/serverReports | ||
SELECT TOP (100) | ||
'CPU%' AS [label] | ||
, [timestamp] AS [Event Time] | ||
, SQLProcessUtilization AS [SQL Server Process CPU Utilization] | ||
, SystemIdle AS [System Idle Process] | ||
, 100 - SystemIdle - SQLProcessUtilization AS [Other Process CPU Utilization] | ||
, [MemoryUtilization] | ||
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] | ||
, record.value('(./Record/SchedulerMonitorEvent/SystemHealth/MemoryUtilization)[1]', 'int') AS [MemoryUtilization] | ||
, [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; | ||
ORDER BY [Event Time] DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
SELECT | ||
DB_NAME() AS database_name, | ||
type_desc, | ||
file_id, | ||
size * 8 / 1024 AS size_mb, | ||
FILEPROPERTY(name,'SpaceUsed') * 8 / 1024 AS space_used_mb, | ||
(size - FILEPROPERTY(name,'SpaceUsed')) * 8 / 1024 AS unallocated_page_mb, | ||
CASE max_size | ||
WHEN -1 THEN -1 | ||
ELSE max_size * 8 / 1024 | ||
END AS max_size_mb | ||
FROM | ||
sys.database_files | ||
UNION ALL | ||
SELECT | ||
database_name, | ||
type_desc, | ||
file_id, | ||
size_mb, | ||
size_mb - unallocated_page_mb AS space_used_mb, | ||
unallocated_page_mb, | ||
max_size_mb | ||
FROM | ||
( | ||
SELECT | ||
'tempdb' AS database_name, | ||
type_desc, | ||
file_id, | ||
size * 8 / 1024 AS size_mb, | ||
(SELECT | ||
allocated_extent_page_count * 8 / 1024 AS allocated_extent_page_mb | ||
FROM | ||
tempdb.sys.dm_db_file_space_usage | ||
WHERE | ||
file_id = T.file_id | ||
) AS unallocated_page_mb, | ||
CASE max_size | ||
WHEN -1 THEN -1 | ||
ELSE max_size * 8 / 1024 | ||
END AS max_size_mb | ||
FROM | ||
tempdb.sys.database_files AS T | ||
) AS T2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SELECT | ||
DATEADD(HOUR, 9, end_time) AT TIME ZONE 'Tokyo Standard Time' AS end_time_jp | ||
,* | ||
FROM | ||
sys.dm_db_resource_stats | ||
ORDER BY end_time ASC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
SELECT | ||
SUBSTRING(RTRIM(T.object_name), CHARINDEX(':', RTRIM(T.object_name)) + 1, LEN(RTRIM(T.object_name)) - CHARINDEX(':', RTRIM(T.object_name))) AS object_name, | ||
T.counter_name, | ||
T.instance_name, | ||
(T.cntr_value * 1.0 / T_BASE.cntr_value) * 100 AS cntr_value | ||
FROM | ||
sys.dm_os_performance_counters AS T | ||
LEFT JOIN | ||
( | ||
SELECT | ||
* | ||
FROM | ||
sys.dm_os_performance_counters | ||
WHERE | ||
object_name like '%Resource Pool Stats%' | ||
AND | ||
counter_name = 'CPU usage % base' | ||
) AS T_Base | ||
ON | ||
T_BASE.instance_name = t.instance_name | ||
|
||
WHERE | ||
T.object_name like '%Resource Pool Stats%' | ||
AND | ||
T.counter_name = 'CPU usage %' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
DECLARE @cntr_value bigint | ||
DECLARE @start_time datetime2(2) | ||
|
||
SELECT | ||
@cntr_value = cntr_value, | ||
@start_time = GETDATE() | ||
FROM | ||
sys.dm_os_performance_counters | ||
WHERE | ||
object_name like '%:SQL Statistics%' | ||
AND | ||
counter_name = 'Batch Requests/sec' | ||
|
||
WAITFOR DELAY '00:00:01' | ||
|
||
SELECT | ||
SUBSTRING(RTRIM(object_name), CHARINDEX(':', RTRIM(object_name)) + 1, LEN(RTRIM(object_name)) - CHARINDEX(':', RTRIM(object_name))) AS object_name, | ||
RTRIM(counter_name) AS counter_name, | ||
RTRIM(instance_name) AS instance_name, | ||
(cntr_value - @cntr_value) / DATEDIFF(SECOND, @start_time, GETDATE())AS cntr_value | ||
FROM | ||
sys.dm_os_performance_counters | ||
WHERE | ||
object_name like '%:SQL Statistics%' | ||
AND | ||
counter_name = 'Batch Requests/sec' | ||
UNION ALL | ||
SELECT | ||
SUBSTRING(RTRIM(object_name), CHARINDEX(':', RTRIM(object_name)) + 1, LEN(RTRIM(object_name)) - CHARINDEX(':', RTRIM(object_name))) AS object_name, | ||
RTRIM(counter_name) AS counter_name, | ||
RTRIM(instance_name) AS instance_name, | ||
cntr_value | ||
FROM | ||
sys.dm_os_performance_counters | ||
WHERE | ||
object_name LIKE '%:Memory Manager%' | ||
UNION ALL | ||
SELECT | ||
SUBSTRING(RTRIM(object_name), CHARINDEX(':', RTRIM(object_name)) + 1, LEN(RTRIM(object_name)) - CHARINDEX(':', RTRIM(object_name))) AS object_name, | ||
CASE | ||
WHEN counter_name = 'Cache Pages' THEN 'Cache Pages (KB)' | ||
ELSE counter_name | ||
END AS counter_name, | ||
RTRIM(instance_name) AS instance_name, | ||
CASE | ||
WHEN counter_name = 'Cache Pages' THEN cntr_value * 8 | ||
ELSE cntr_value | ||
END AS cntr_value | ||
FROM | ||
sys.dm_os_performance_counters | ||
WHERE | ||
object_name LIKE '%:Plan Cache%' | ||
AND | ||
counter_name IN('Cache Pages', 'Cache Object Counts') | ||
|
||
|