Skip to content

Commit

Permalink
Remove storage calculation for non Azure managed instances and add se…
Browse files Browse the repository at this point in the history
…rver version (influxdata#5135)

- Removed the storage calculation for SQL Server instances that are NOT Azure
  Managed Instances, this reduces the time it takes to get this data on an
  instance with a lot of databases and/or database files.
- Added the SQL Server version back to the server properties query.
  • Loading branch information
m82labs authored and otherpirate committed Mar 15, 2019
1 parent 898cf1f commit b759c41
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions plugins/inputs/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ const sqlServerPropertiesV2 = `DECLARE @sys_info TABLE (
IF OBJECT_ID('master.sys.dm_os_sys_info') IS NOT NULL
BEGIN
IF SERVERPROPERTY('EngineEdition') = 8 -- Managed Instance
INSERT INTO @sys_info ( cpu_count, server_memory, sku, engine_edition, hardware_type, total_storage_mb, available_storage_mb, uptime )
SELECT TOP(1)
Expand All @@ -418,19 +417,6 @@ BEGIN
ELSE
BEGIN
DECLARE @total_disk_size_mb BIGINT,
@available_space_mb BIGINT
SELECT @total_disk_size_mb = sum(total_disk_size_mb),
@available_space_mb = sum(free_disk_space_mb)
FROM (
SELECT distinct logical_volume_name AS LogicalName,
total_bytes/(1024*1024)as total_disk_size_mb,
available_bytes /(1024*1024) free_disk_space_mb
FROM sys.master_files AS f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.file_id)
) as osVolumes
INSERT INTO @sys_info ( cpu_count, server_memory, sku, engine_edition, hardware_type, total_storage_mb, available_storage_mb, uptime )
SELECT cpu_count,
(SELECT total_physical_memory_kb FROM sys.dm_os_sys_memory) AS server_memory,
Expand All @@ -440,13 +426,12 @@ BEGIN
WHEN 'NONE' THEN 'PHYSICAL Machine'
ELSE virtual_machine_type_desc
END AS hardware_type,
@total_disk_size_mb,
@available_space_mb,
NULL,
NULL,
DATEDIFF(MINUTE,sqlserver_start_time,GETDATE())
FROM sys.dm_os_sys_info
END
END
SELECT 'sqlserver_server_properties' AS [measurement],
REPLACE(@@SERVERNAME,'\',':') AS [sql_instance],
s.cpu_count,
Expand All @@ -457,6 +442,7 @@ SELECT 'sqlserver_server_properties' AS [measurement],
s.total_storage_mb,
s.available_storage_mb,
s.uptime,
SERVERPROPERTY('ProductVersion') AS sql_version,
db_online,
db_restoring,
db_recovering,
Expand Down

0 comments on commit b759c41

Please sign in to comment.