diff --git a/Datadog/SQL Server Custom Metric Proc.sql b/Datadog/SQL Server Custom Metric Proc.sql new file mode 100644 index 0000000..8fd7aca Binary files /dev/null and b/Datadog/SQL Server Custom Metric Proc.sql differ diff --git a/Power BI/Query/RING_BUFFER_SCHEDULER_MONITOR.sql b/Power BI/Query/RING_BUFFER_SCHEDULER_MONITOR.sql new file mode 100644 index 0000000..0b74145 --- /dev/null +++ b/Power BI/Query/RING_BUFFER_SCHEDULER_MONITOR.sql @@ -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 '%%' + ) AS x + ) AS y +--ORDER BY record_id DESC; +ORDER BY [Event Time] DESC; diff --git a/Power BI/Query/database_usage.sql b/Power BI/Query/database_usage.sql new file mode 100644 index 0000000..a2313c0 --- /dev/null +++ b/Power BI/Query/database_usage.sql @@ -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 diff --git a/Power BI/Query/dtu_usage.sql b/Power BI/Query/dtu_usage.sql new file mode 100644 index 0000000..a219a7a --- /dev/null +++ b/Power BI/Query/dtu_usage.sql @@ -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 \ No newline at end of file diff --git a/Power BI/Query/resource_pool_cpu_usage.sql b/Power BI/Query/resource_pool_cpu_usage.sql new file mode 100644 index 0000000..2d22cea --- /dev/null +++ b/Power BI/Query/resource_pool_cpu_usage.sql @@ -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 %' \ No newline at end of file diff --git a/Power BI/Query/sys.dm_os_performance_counters.sql b/Power BI/Query/sys.dm_os_performance_counters.sql new file mode 100644 index 0000000..8bc5b17 --- /dev/null +++ b/Power BI/Query/sys.dm_os_performance_counters.sql @@ -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') + +