From 192e76c5e3856f8d920443290b63a28df6a759fa Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Fri, 22 Nov 2019 17:22:49 -0700 Subject: [PATCH] Add V2 query for log file sizes Signed-off-by: Nick Neisen --- plugins/inputs/sqlserver/README.md | 2 ++ plugins/inputs/sqlserver/sqlserver.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/plugins/inputs/sqlserver/README.md b/plugins/inputs/sqlserver/README.md index b586ecd2703a7..1d2ff1bbf58e0 100644 --- a/plugins/inputs/sqlserver/README.md +++ b/plugins/inputs/sqlserver/README.md @@ -70,6 +70,7 @@ GO ## - AzureDBResourceGovernance ## - SqlRequests ## - ServerProperties + ## - LogFileSizes exclude_query = [ 'Schedulers' , 'SqlRequests'] ``` @@ -110,6 +111,7 @@ The new (version 2) metrics provide: - *Wait stats*: Wait time in ms, number of waiting tasks, resource wait time, signal wait time, max wait time in ms, wait type, and wait category. The waits are categorized using the same categories used in Query Store. - *Schedulers* - This captures sys.dm_os_schedulers. - *SqlRequests* - This captures a snapshot of dm_exec_requests and dm_exec_sessions that gives you running requests as well as wait types and blocking sessions +- _Log File Sizes_: Current and maximum log file sizes from `sys.master_files` - *Azure Managed Instances* - Stats from `sys.server_resource_stats`: - cpu_count diff --git a/plugins/inputs/sqlserver/sqlserver.go b/plugins/inputs/sqlserver/sqlserver.go index c2c852749bc4a..e4a2d80b9930d 100644 --- a/plugins/inputs/sqlserver/sqlserver.go +++ b/plugins/inputs/sqlserver/sqlserver.go @@ -69,6 +69,7 @@ const sampleConfig = ` ## - AzureDBResourceGovernance ## - SqlRequests ## - ServerProperties + ## - LogFileSizes exclude_query = [ 'Schedulers' ] ` @@ -104,6 +105,7 @@ func initQueries(s *SQLServer) { queries["MemoryClerk"] = Query{Script: sqlMemoryClerkV2, ResultByRow: false} queries["Schedulers"] = Query{Script: sqlServerSchedulersV2, ResultByRow: false} queries["SqlRequests"] = Query{Script: sqlServerRequestsV2, ResultByRow: false} + queries["LogFileSizes"] = Query{Script: sqlLogFileSizesV2, ResultByRow: false} } else { queries["PerformanceCounters"] = Query{Script: sqlPerformanceCounters, ResultByRow: true} queries["WaitStatsCategorized"] = Query{Script: sqlWaitStatsCategorized, ResultByRow: false} @@ -1362,6 +1364,24 @@ BEGIN END; ` +const sqlLogFileSizesV2 string = `SET DEADLOCK_PRIORITY -10; +WITH fs +AS +( + SELECT database_id, type, size * 8 / 1024 size, max_size * 8 / 1024 max_size + FROM sys.master_files + WHERE database_id NOT IN (3,1,4) +) +SELECT + 'sqlserver_log_size' AS [measurement], + REPLACE(@@SERVERNAME,'\',':') AS [sql_instance], + DB_NAME() as [database_name], + (SELECT SUM(size) FROM fs WHERE type = 0 AND fs.database_id = db.database_id) log_size_mb, + (SELECT SUM(max_size) FROM fs WHERE type = 1 AND fs.database_id = db.database_id) max_log_size_mb +FROM sys.databases db +WHERE database_id NOT IN (3,1,4) +` + const sqlServerRequestsV2 string = ` SET NOCOUNT ON; SELECT blocking_session_id into #blockingSessions FROM sys.dm_exec_requests WHERE blocking_session_id != 0