Skip to content

Commit 50ad482

Browse files
Get-DbaAgRingBuffer - Add CollectionMinutes parameter for consistency with Get-DbaCpuRingBuffer
(do Get-DbaAgRingBuffer) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent b2857c2 commit 50ad482

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

public/Get-DbaAgRingBuffer.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function Get-DbaAgRingBuffer {
3535
- RING_BUFFER_HADRDBMGR_COMMIT : Commit-level activity records
3636
- RING_BUFFER_HADR_TRANSPORT_STATE: Connection and transport state transitions
3737
38+
.PARAMETER CollectionMinutes
39+
Specifies how many minutes of historical data to retrieve from the ring buffer. Defaults to 60 minutes.
40+
Use this to extend the analysis window when investigating longer-term AG issues or to focus on recent activity with shorter periods.
41+
3842
.PARAMETER EnableException
3943
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
4044
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
@@ -68,12 +72,17 @@ function Get-DbaAgRingBuffer {
6872
.EXAMPLE
6973
PS C:\> Get-DbaAgRingBuffer -SqlInstance sql2019
7074
71-
Returns all HADR ring buffer records from the sql2019 instance.
75+
Returns HADR ring buffer records from the last 60 minutes from the sql2019 instance.
76+
77+
.EXAMPLE
78+
PS C:\> Get-DbaAgRingBuffer -SqlInstance sql2019 -CollectionMinutes 240
79+
80+
Returns HADR ring buffer records from the last 240 minutes from the sql2019 instance.
7281
7382
.EXAMPLE
7483
PS C:\> Get-DbaAgRingBuffer -SqlInstance sql2019 -RingBufferType RING_BUFFER_HADRDBMGR_API
7584
76-
Returns only RING_BUFFER_HADRDBMGR_API records from the sql2019 instance.
85+
Returns only RING_BUFFER_HADRDBMGR_API records from the last 60 minutes from the sql2019 instance.
7786
7887
.EXAMPLE
7988
PS C:\> Get-DbaAgRingBuffer -SqlInstance sql2019 -RingBufferType RING_BUFFER_HADRDBMGR_API, RING_BUFFER_HADR_TRANSPORT_STATE
@@ -92,6 +101,7 @@ function Get-DbaAgRingBuffer {
92101
[PSCredential]$SqlCredential,
93102
[ValidateSet("RING_BUFFER_HADRDBMGR_API", "RING_BUFFER_HADRDBMGR_STATE", "RING_BUFFER_HADRDBMGR_COMMIT", "RING_BUFFER_HADR_TRANSPORT_STATE")]
94103
[string[]]$RingBufferType,
104+
[int]$CollectionMinutes = 60,
95105
[switch]$EnableException
96106
)
97107

@@ -129,6 +139,7 @@ function Get-DbaAgRingBuffer {
129139
DATEADD(ms, -1 * ($currentTimestamp - [timestamp]), GETDATE()) AS EventTime,
130140
record
131141
FROM HadrRingBuffer
142+
WHERE DATEADD(ms, -1 * ($currentTimestamp - [timestamp]), GETDATE()) > DATEADD(MINUTE, -$CollectionMinutes, GETDATE())
132143
ORDER BY EventTime DESC;"
133144

134145
Write-Message -Level Verbose -Message "Executing SQL Statement: $sql"

tests/Get-DbaAgRingBuffer.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Describe $CommandName -Tag UnitTests {
1414
"SqlInstance",
1515
"SqlCredential",
1616
"RingBufferType",
17+
"CollectionMinutes",
1718
"EnableException"
1819
)
1920
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $hasParameters | Should -BeNullOrEmpty

0 commit comments

Comments
 (0)