Skip to content

Commit 31f97ee

Browse files
Add Host OS column to Server Inventory in Dashboard and Lite (#748) (#823)
Queries sys.dm_os_host_info (SQL 2017+) for the host_distribution value. Falls back to parsing @@Version for SQL 2016 and Azure SQL DB. No schema changes — the data is queried live alongside existing server properties. Fixes #748 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f554d3b commit 31f97ee

4 files changed

Lines changed: 53 additions & 3 deletions

File tree

Dashboard/Controls/FinOpsContent.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,14 @@
24472447
</StackPanel>
24482448
</DataGridTextColumn.Header>
24492449
</DataGridTextColumn>
2450+
<DataGridTextColumn Binding="{Binding HostOsVersion}" Width="200">
2451+
<DataGridTextColumn.Header>
2452+
<StackPanel Orientation="Horizontal">
2453+
<Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="HostOsVersion" Click="FinOpsFilter_Click" Margin="0,0,4,0"/>
2454+
<TextBlock Text="Host OS" FontWeight="Bold" VerticalAlignment="Center"/>
2455+
</StackPanel>
2456+
</DataGridTextColumn.Header>
2457+
</DataGridTextColumn>
24502458
<DataGridTextColumn Binding="{Binding CpuCount, StringFormat='{}{0:N0}'}" Width="70">
24512459
<DataGridTextColumn.Header>
24522460
<StackPanel Orientation="Horizontal">

Dashboard/Services/DatabaseService.FinOps.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@ public static async Task<FinOpsServerInventory> GetServerPropertiesLiveAsync(str
391391
await connection.OpenAsync();
392392

393393
const string query = @"
394+
DECLARE @host_os nvarchar(256);
395+
IF OBJECT_ID(N'sys.dm_os_host_info', N'V') IS NOT NULL
396+
EXEC sys.sp_executesql N'SELECT @os = host_distribution FROM sys.dm_os_host_info',
397+
N'@os nvarchar(256) OUTPUT', @os = @host_os OUTPUT;
398+
399+
IF @host_os IS NULL
400+
BEGIN
401+
/* SQL 2016 or Azure SQL DB: parse OS from @@VERSION */
402+
DECLARE @ver nvarchar(4000) = @@VERSION;
403+
DECLARE @on_pos int = CHARINDEX(N' on ', @ver);
404+
IF @on_pos > 0
405+
SET @host_os = LTRIM(SUBSTRING(@ver, @on_pos + 4, LEN(@ver)));
406+
END;
407+
394408
SELECT
395409
edition =
396410
CONVERT(nvarchar(256), SERVERPROPERTY('Edition')),
@@ -417,7 +431,9 @@ public static async Task<FinOpsServerInventory> GetServerPropertiesLiveAsync(str
417431
is_hadr_enabled =
418432
CONVERT(int, SERVERPROPERTY('IsHadrEnabled')),
419433
is_clustered =
420-
CONVERT(int, SERVERPROPERTY('IsClustered'))
434+
CONVERT(int, SERVERPROPERTY('IsClustered')),
435+
host_os =
436+
@host_os
421437
FROM sys.dm_os_sys_info AS si;";
422438

423439
using var command = new SqlCommand(query, connection);
@@ -446,6 +462,7 @@ public static async Task<FinOpsServerInventory> GetServerPropertiesLiveAsync(str
446462
EngineEdition = reader.IsDBNull(10) ? null : Convert.ToInt32(reader.GetValue(10)),
447463
IsHadrEnabled = reader.IsDBNull(11) ? null : Convert.ToInt32(reader.GetValue(11)) == 1,
448464
IsClustered = reader.IsDBNull(12) ? null : Convert.ToInt32(reader.GetValue(12)) == 1,
465+
HostOsVersion = reader.IsDBNull(13) ? "" : reader.GetString(13),
449466
LastUpdated = DateTime.Now
450467
};
451468
}
@@ -2496,6 +2513,7 @@ public class FinOpsServerInventory
24962513
public string ServerName { get; set; } = "";
24972514
public string Edition { get; set; } = "";
24982515
public string SqlVersion { get; set; } = "";
2516+
public string HostOsVersion { get; set; } = "";
24992517
public int CpuCount { get; set; }
25002518
public long PhysicalMemoryMb { get; set; }
25012519
public int? SocketCount { get; set; }

Lite/Controls/FinOpsTab.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,14 @@
22342234
</StackPanel>
22352235
</DataGridTextColumn.Header>
22362236
</DataGridTextColumn>
2237+
<DataGridTextColumn Binding="{Binding HostOsVersion}" Width="200">
2238+
<DataGridTextColumn.Header>
2239+
<StackPanel Orientation="Horizontal">
2240+
<Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="HostOsVersion" Click="FilterButton_Click" Margin="0,0,4,0"/>
2241+
<TextBlock Text="Host OS" FontWeight="Bold" VerticalAlignment="Center"/>
2242+
</StackPanel>
2243+
</DataGridTextColumn.Header>
2244+
</DataGridTextColumn>
22372245
<DataGridTextColumn Binding="{Binding CpuCount, StringFormat='{}{0:N0}'}" Width="70">
22382246
<DataGridTextColumn.Header>
22392247
<StackPanel Orientation="Horizontal">

Lite/Services/LocalDataService.FinOps.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,23 @@ WHEN CONVERT(int, SERVERPROPERTY('EngineEdition')) = 5
9393
THEN N'SELECT @gb = SUM(CAST(size AS bigint)) * 8.0 / 1024.0 / 1024.0 FROM sys.database_files'
9494
ELSE N'SELECT @gb = SUM(CAST(size AS bigint)) * 8.0 / 1024.0 / 1024.0 FROM sys.master_files'
9595
END,
96-
@storage_gb decimal(19,2);
96+
@storage_gb decimal(19,2),
97+
@host_os nvarchar(256);
9798
9899
EXEC sys.sp_executesql @storage_sql, N'@gb decimal(19,2) OUTPUT', @gb = @storage_gb OUTPUT;
99100
101+
IF OBJECT_ID(N'sys.dm_os_host_info', N'V') IS NOT NULL
102+
EXEC sys.sp_executesql N'SELECT @os = host_distribution FROM sys.dm_os_host_info',
103+
N'@os nvarchar(256) OUTPUT', @os = @host_os OUTPUT;
104+
105+
IF @host_os IS NULL
106+
BEGIN
107+
DECLARE @ver nvarchar(4000) = @@VERSION;
108+
DECLARE @on_pos int = CHARINDEX(N' on ', @ver);
109+
IF @on_pos > 0
110+
SET @host_os = LTRIM(SUBSTRING(@ver, @on_pos + 4, LEN(@ver)));
111+
END;
112+
100113
SELECT
101114
CONVERT(nvarchar(256), SERVERPROPERTY('Edition')),
102115
CONVERT(nvarchar(128), SERVERPROPERTY('ProductVersion')),
@@ -110,7 +123,8 @@ WHEN CONVERT(int, SERVERPROPERTY('EngineEdition')) = 5
110123
si.cores_per_socket,
111124
CONVERT(int, SERVERPROPERTY('EngineEdition')),
112125
CONVERT(int, SERVERPROPERTY('IsHadrEnabled')),
113-
CONVERT(int, SERVERPROPERTY('IsClustered'))
126+
CONVERT(int, SERVERPROPERTY('IsClustered')),
127+
@host_os
114128
FROM sys.dm_os_sys_info AS si;";
115129

116130
using var command = new SqlCommand(query, connection) { CommandTimeout = 30 };
@@ -137,6 +151,7 @@ WHEN CONVERT(int, SERVERPROPERTY('EngineEdition')) = 5
137151
EngineEdition = reader.IsDBNull(10) ? 0 : Convert.ToInt32(reader.GetValue(10)),
138152
IsHadrEnabled = reader.IsDBNull(11) ? null : Convert.ToInt32(reader.GetValue(11)) == 1,
139153
IsClustered = reader.IsDBNull(12) ? null : Convert.ToInt32(reader.GetValue(12)) == 1,
154+
HostOsVersion = reader.IsDBNull(13) ? "" : reader.GetString(13),
140155
LastUpdated = DateTime.Now
141156
};
142157
}
@@ -2295,6 +2310,7 @@ public class ServerPropertyRow
22952310
public string ServerName { get; set; } = "";
22962311
public string Edition { get; set; } = "";
22972312
public string ProductVersion { get; set; } = "";
2313+
public string HostOsVersion { get; set; } = "";
22982314
public string? ProductLevel { get; set; }
22992315
public string? ProductUpdateLevel { get; set; }
23002316
public int EngineEdition { get; set; }

0 commit comments

Comments
 (0)