From 8b9883e2eca63f9e4f51e9af1efc7925f7012e3e Mon Sep 17 00:00:00 2001 From: Giovanni Luisotto Date: Tue, 11 May 2021 23:08:25 +0200 Subject: [PATCH] SQL Server - sqlServerRingBufferCPU - removed whitespaces (#9130) ### Required for all PRs: - [ ] Updated associated README.md. - [ ] Wrote appropriate unit tests. Removed a pair of whitespace chars from the **sqlServerRingBufferCPU** SQL statement and added some formatting. This query exists only for the on-prem version of SQL Server (`database_type = "SQLServer"`) If you were unlucky enough to have some SQL 2008 the query wouldn't work as the whitespace char is not allowed inside the statement. --- plugins/inputs/sqlserver/sqlserverqueries.go | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/inputs/sqlserver/sqlserverqueries.go b/plugins/inputs/sqlserver/sqlserverqueries.go index 76a771252..756d8a8be 100644 --- a/plugins/inputs/sqlserver/sqlserverqueries.go +++ b/plugins/inputs/sqlserver/sqlserverqueries.go @@ -1141,7 +1141,7 @@ END; WITH utilization_cte AS ( SELECT - [SQLProcessUtilization] AS [sqlserver_process_cpu] + [SQLProcessUtilization] AS [sqlserver_process_cpu] ,[SystemIdle] AS [system_idle_cpu] ,100 - [SystemIdle] - [SQLProcessUtilization] AS [other_process_cpu] FROM ( @@ -1170,8 +1170,8 @@ WITH utilization_cte AS ), processor_Info_cte AS ( - SELECT (cpu_count / hyperthread_ratio) as number_of_physical_cpus -  FROM sys.dm_os_sys_info + SELECT ([cpu_count] / [hyperthread_ratio]) as [number_of_physical_cpus] + FROM sys.dm_os_sys_info ) SELECT 'sqlserver_cpu' AS [measurement] @@ -1179,16 +1179,15 @@ SELECT ,[sqlserver_process_cpu] ,[system_idle_cpu] ,100 - [system_idle_cpu] - [sqlserver_process_cpu] AS [other_process_cpu] -FROM - ( - SELECT - (case - when [other_process_cpu] < 0 then [sqlserver_process_cpu] / a.number_of_physical_cpus - else [sqlserver_process_cpu] -  end) as [sqlserver_process_cpu] - ,[system_idle_cpu] - FROM utilization_cte - CROSS APPLY processor_Info_cte a +FROM ( + SELECT + (CASE + WHEN u.[other_process_cpu] < 0 THEN u.[sqlserver_process_cpu] / p.[number_of_physical_cpus] + ELSE u.[sqlserver_process_cpu] + END) AS [sqlserver_process_cpu] + ,u.[system_idle_cpu] + FROM utilization_cte AS u + CROSS APPLY processor_Info_cte AS p ) AS b `