Skip to content

Commit

Permalink
Splitting WaitStats for AzureDB into separate collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Mar 27, 2020
1 parent 4209ce0 commit 34ce74e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions plugins/inputs/sqlserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ GO
## - Schedulers
## - AzureDBResourceStats
## - AzureDBResourceGovernance
## - AzureDBWaitStats
## - SqlRequests
## - ServerProperties
## A list of queries to include. If not specified, all the above listed queries are used.
Expand Down Expand Up @@ -132,9 +133,9 @@ The new (version 2) metrics provide:
- uptime
- Resource governance stats from sys.dm_instance_resource_governance
- *Azure SQL Database*
- Stats from sys.dm_db_wait_stats
- Resource governance stats from sys.dm_user_db_resource_governance
- Stats from sys.dm_db_resource_stats
- *AzureDBWaitStats* - Stats from sys.dm_db_wait_stats
- *AzureDBResourceGovernance* - Resource governance stats from sys.dm_user_db_resource_governance
- *AzureDBResourceStats* - Stats from sys.dm_db_resource_stats

The following metrics can be used directly, with no delta calculations:
- SQLServer:Buffer Manager\Buffer cache hit ratio
Expand Down
16 changes: 8 additions & 8 deletions plugins/inputs/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const sampleConfig = `
## - VolumeSpace
## - PerformanceMetrics
## - Schedulers
## - AzureDBWaitStats
## - AzureDBResourceStats
## - AzureDBResourceGovernance
## - SqlRequests
Expand Down Expand Up @@ -98,6 +99,7 @@ func initQueries(s *SQLServer) error {
if s.AzureDB {
queries["AzureDBResourceStats"] = Query{Script: sqlAzureDBResourceStats, ResultByRow: false}
queries["AzureDBResourceGovernance"] = Query{Script: sqlAzureDBResourceGovernance, ResultByRow: false}
queries["AzureDBWaitStats"] = Query{Script: sqlAzureDBWaitStats, ResultByRow: false}
}

// Decide if we want to run version 1 or version 2 queries
Expand Down Expand Up @@ -550,10 +552,6 @@ FROM (

//Recommend disabling this by default, but is useful to detect single CPU spikes/bottlenecks
const sqlServerSchedulersV2 string = `
SET DEADLOCK_PRIORITY - 10;
DECLARE @SqlStatement AS nvarchar(max);
SET @SqlStatement = N'
Expand Down Expand Up @@ -794,10 +792,8 @@ WHERE pc.counter_name NOT LIKE '% base'
OPTION(RECOMPILE);
`

// Conditional check based on Azure SQL DB v/s the rest aka (Azure SQL Managed instance OR On-prem SQL Server)
// EngineEdition=5 is Azure SQL DB
// sys.dm_os_wait_stats available in all azure/on-prem tiers, there are times may want to collect it even for single Azure SQL DB
const sqlWaitStatsCategorizedV2 string = `SET DEADLOCK_PRIORITY -10;
IF SERVERPROPERTY('EngineEdition') != 5
SELECT
'sqlserver_waitstats' AS [measurement],
REPLACE(@@SERVERNAME,'\',':') AS [sql_instance],
Expand Down Expand Up @@ -1355,8 +1351,12 @@ ws.wait_type NOT IN (
N'SOS_WORK_DISPATCHER','RESERVED_MEMORY_ALLOCATION_EXT')
AND waiting_tasks_count > 0
AND wait_time_ms > 100;
`

ELSE
// split DB level wait stats that are only relevant to Azure SQL DB into separate collector
// This will only be collected for Azure SQL Database.
const sqlAzureDBWaitStats string = `SET DEADLOCK_PRIORITY -10;
IF SERVERPROPERTY('EngineEdition') = 5 -- Is this Azure SQL DB?
SELECT
'sqlserver_azuredb_waitstats' AS [measurement],
REPLACE(@@SERVERNAME,'\',':') AS [sql_instance],
Expand Down

0 comments on commit 34ce74e

Please sign in to comment.