Skip to content

Commit e2054f0

Browse files
Merge pull request #669 from erikdarlingdata/dev
Release sp_HealthParser 3.4 — @use_ring_buffer parameter
2 parents 8684453 + 84abcaf commit e2054f0

1 file changed

Lines changed: 90 additions & 71 deletions

File tree

sp_HealthParser/sp_HealthParser.sql

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ALTER PROCEDURE
5050
@wait_round_interval_minutes bigint = 60, /*Nearest interval to round wait stats to*/
5151
@skip_locks bit = 0, /*Skip the blocking and deadlocks*/
5252
@skip_waits bit = 0, /*Skip the wait stats*/
53+
@use_ring_buffer bit = 0, /*Use ring_buffer target instead of file target for system_health session*/
5354
@pending_task_threshold integer = 10, /*Minimum number of pending tasks to care about*/
5455
@log_to_table bit = 0, /*enable logging to permanent tables*/
5556
@log_database_name sysname = NULL, /*database to store logging tables*/
@@ -71,8 +72,8 @@ BEGIN
7172
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
7273

7374
SELECT
74-
@version = '3.3',
75-
@version_date = '20260216';
75+
@version = '3.4',
76+
@version_date = '20260217';
7677

7778
IF @help = 1
7879
BEGIN
@@ -103,6 +104,7 @@ BEGIN
103104
WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for wait stats'
104105
WHEN N'@skip_locks' THEN N'skip the blocking and deadlocking section'
105106
WHEN N'@skip_waits' THEN N'skip the wait stats section'
107+
WHEN N'@use_ring_buffer' THEN N'use ring_buffer target instead of file target for faster collection'
106108
WHEN N'@pending_task_threshold' THEN N'minimum number of pending tasks to display'
107109
WHEN N'@log_to_table' THEN N'enable logging to permanent tables instead of returning results'
108110
WHEN N'@log_database_name' THEN N'database to store logging tables'
@@ -126,6 +128,7 @@ BEGIN
126128
WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for top wait stats by count and duration'
127129
WHEN N'@skip_locks' THEN N'0 or 1'
128130
WHEN N'@skip_waits' THEN N'0 or 1'
131+
WHEN N'@use_ring_buffer' THEN N'0 or 1'
129132
WHEN N'@pending_task_threshold' THEN N'a valid integer'
130133
WHEN N'@log_to_table' THEN N'0 or 1'
131134
WHEN N'@log_database_name' THEN N'any valid database name'
@@ -149,6 +152,7 @@ BEGIN
149152
WHEN N'@wait_round_interval_minutes' THEN N'60'
150153
WHEN N'@skip_locks' THEN N'0'
151154
WHEN N'@skip_waits' THEN N'0'
155+
WHEN N'@use_ring_buffer' THEN N'0'
152156
WHEN N'@pending_task_threshold' THEN N'10'
153157
WHEN N'@log_to_table' THEN N'0'
154158
WHEN N'@log_database_name' THEN N'NULL (current database)'
@@ -461,6 +465,7 @@ AND ca.utc_timestamp < @end_date';
461465
@wait_round_interval_minutes = ISNULL(@wait_round_interval_minutes, 60),
462466
@skip_locks = ISNULL(@skip_locks, 0),
463467
@skip_waits = ISNULL(@skip_waits, 0),
468+
@use_ring_buffer = ISNULL(@use_ring_buffer, 0),
464469
@pending_task_threshold = ISNULL(@pending_task_threshold, 10);
465470

466471
/*Validate what to check*/
@@ -1540,87 +1545,101 @@ AND ca.utc_timestamp < @end_date';
15401545
ORDER BY
15411546
ca.id;
15421547

1543-
OPEN @collection_cursor;
1548+
/*
1549+
File target collection: read from system_health .xel files on disk
1550+
Skip this path when using ring_buffer target or on Managed Instance
1551+
*/
1552+
IF @mi = 0
1553+
AND @use_ring_buffer = 0
1554+
BEGIN
1555+
OPEN @collection_cursor;
15441556

1545-
FETCH NEXT
1546-
FROM @collection_cursor
1547-
INTO
1548-
@area_name,
1549-
@object_name,
1550-
@temp_table,
1551-
@insert_list;
1557+
FETCH NEXT
1558+
FROM @collection_cursor
1559+
INTO
1560+
@area_name,
1561+
@object_name,
1562+
@temp_table,
1563+
@insert_list;
15521564

1553-
WHILE @@FETCH_STATUS = 0
1554-
BEGIN
1555-
/* Build the SQL statement for this collection area */
1556-
SET
1557-
@collection_sql =
1558-
REPLACE
1559-
(
1565+
WHILE @@FETCH_STATUS = 0
1566+
BEGIN
1567+
/* Build the SQL statement for this collection area */
1568+
SET
1569+
@collection_sql =
15601570
REPLACE
15611571
(
15621572
REPLACE
15631573
(
1564-
@sql_template,
1565-
'{object_name}',
1566-
@object_name
1574+
REPLACE
1575+
(
1576+
@sql_template,
1577+
'{object_name}',
1578+
@object_name
1579+
),
1580+
'{temp_table}',
1581+
@temp_table
15671582
),
1568-
'{temp_table}',
1569-
@temp_table
1570-
),
1571-
'{insert_list}',
1572-
@insert_list
1573-
);
1583+
'{insert_list}',
1584+
@insert_list
1585+
);
15741586

1575-
IF @debug = 1
1576-
BEGIN
1577-
RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT;
1578-
PRINT @collection_sql;
1579-
END;
1587+
IF @debug = 1
1588+
BEGIN
1589+
RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT;
1590+
PRINT @collection_sql;
1591+
END;
15801592

1581-
IF @debug = 1
1582-
BEGIN
1583-
RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT;
1584-
SET STATISTICS XML ON;
1585-
END;
1593+
IF @debug = 1
1594+
BEGIN
1595+
RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT;
1596+
SET STATISTICS XML ON;
1597+
END;
15861598

1587-
EXECUTE sys.sp_executesql
1588-
@collection_sql,
1589-
@params,
1590-
@start_date,
1591-
@end_date;
1599+
EXECUTE sys.sp_executesql
1600+
@collection_sql,
1601+
@params,
1602+
@start_date,
1603+
@end_date;
1604+
1605+
IF @debug = 1
1606+
BEGIN
1607+
SET STATISTICS XML OFF;
1608+
END;
1609+
1610+
UPDATE
1611+
@collection_areas
1612+
SET
1613+
is_processed = 1
1614+
WHERE temp_table = @temp_table
1615+
AND should_collect = 1;
1616+
1617+
FETCH NEXT
1618+
FROM @collection_cursor
1619+
INTO
1620+
@area_name,
1621+
@object_name,
1622+
@temp_table,
1623+
@insert_list;
1624+
END;
15921625

15931626
IF @debug = 1
15941627
BEGIN
1595-
SET STATISTICS XML OFF;
1628+
RAISERROR('Data collection complete', 0, 0) WITH NOWAIT;
15961629
END;
1630+
END; /*End file target collection*/
15971631

1598-
UPDATE
1599-
@collection_areas
1600-
SET
1601-
is_processed = 1
1602-
WHERE temp_table = @temp_table
1603-
AND should_collect = 1;
1604-
1605-
FETCH NEXT
1606-
FROM @collection_cursor
1607-
INTO
1608-
@area_name,
1609-
@object_name,
1610-
@temp_table,
1611-
@insert_list;
1612-
END;
1613-
1614-
IF @debug = 1
1615-
BEGIN
1616-
RAISERROR('Data collection complete', 0, 0) WITH NOWAIT;
1617-
END;
1618-
1632+
/*
1633+
Ring buffer collection: read from system_health ring_buffer target
1634+
Used for Managed Instance (always) and on-prem when @use_ring_buffer = 1
1635+
Faster than file target because it avoids disk I/O
1636+
*/
16191637
IF @mi = 1
1638+
OR @use_ring_buffer = 1
16201639
BEGIN
16211640
IF @debug = 1
16221641
BEGIN
1623-
RAISERROR('Starting Managed Instance analysis', 0, 0) WITH NOWAIT;
1642+
RAISERROR('Starting ring_buffer analysis', 0, 0) WITH NOWAIT;
16241643
RAISERROR('Inserting #x', 0, 0) WITH NOWAIT;
16251644
END;
16261645

@@ -1688,7 +1707,7 @@ AND ca.utc_timestamp < @end_date';
16881707
BEGIN
16891708
IF @debug = 1
16901709
BEGIN
1691-
RAISERROR('Checking Managed Instance waits', 0, 0) WITH NOWAIT;
1710+
RAISERROR('Checking ring_buffer waits', 0, 0) WITH NOWAIT;
16921711
RAISERROR('Inserting #wait_info', 0, 0) WITH NOWAIT;
16931712
END;
16941713

@@ -1710,7 +1729,7 @@ AND ca.utc_timestamp < @end_date';
17101729
BEGIN
17111730
IF @debug = 1
17121731
BEGIN
1713-
RAISERROR('Checking Managed Instance sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
1732+
RAISERROR('Checking ring_buffer sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
17141733
RAISERROR('Inserting #sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
17151734
END;
17161735

@@ -1737,7 +1756,7 @@ AND ca.utc_timestamp < @end_date';
17371756
BEGIN
17381757
IF @debug = 1
17391758
BEGIN
1740-
RAISERROR('Checking Managed Instance deadlocks', 0, 0) WITH NOWAIT;
1759+
RAISERROR('Checking ring_buffer deadlocks', 0, 0) WITH NOWAIT;
17411760
RAISERROR('Inserting #xml_deadlock_report', 0, 0) WITH NOWAIT;
17421761
END;
17431762

@@ -1761,7 +1780,7 @@ AND ca.utc_timestamp < @end_date';
17611780
BEGIN
17621781
IF @debug = 1
17631782
BEGIN
1764-
RAISERROR('Checking Managed Instance scheduler monitor', 0, 0) WITH NOWAIT;
1783+
RAISERROR('Checking ring_buffer scheduler monitor', 0, 0) WITH NOWAIT;
17651784
RAISERROR('Inserting #scheduler_monitor', 0, 0) WITH NOWAIT;
17661785
END;
17671786

@@ -1785,7 +1804,7 @@ AND ca.utc_timestamp < @end_date';
17851804
BEGIN
17861805
IF @debug = 1
17871806
BEGIN
1788-
RAISERROR('Checking Managed Instance error reported events', 0, 0) WITH NOWAIT;
1807+
RAISERROR('Checking ring_buffer error reported events', 0, 0) WITH NOWAIT;
17891808
RAISERROR('Inserting #error_reported', 0, 0) WITH NOWAIT;
17901809
END;
17911810

@@ -1809,7 +1828,7 @@ AND ca.utc_timestamp < @end_date';
18091828
BEGIN
18101829
IF @debug = 1
18111830
BEGIN
1812-
RAISERROR('Checking Managed Instance memory broker events', 0, 0) WITH NOWAIT;
1831+
RAISERROR('Checking ring_buffer memory broker events', 0, 0) WITH NOWAIT;
18131832
RAISERROR('Inserting #memory_broker', 0, 0) WITH NOWAIT;
18141833
END;
18151834

@@ -1833,7 +1852,7 @@ AND ca.utc_timestamp < @end_date';
18331852
BEGIN
18341853
IF @debug = 1
18351854
BEGIN
1836-
RAISERROR('Checking Managed Instance memory node OOM events', 0, 0) WITH NOWAIT;
1855+
RAISERROR('Checking ring_buffer memory node OOM events', 0, 0) WITH NOWAIT;
18371856
RAISERROR('Inserting #memory_node_oom', 0, 0) WITH NOWAIT;
18381857
END;
18391858

0 commit comments

Comments
 (0)