diff --git a/src/Microsoft.SqlTools.ManagedBatchParser/ReliableConnection/ReliableConnectionHelper.cs b/src/Microsoft.SqlTools.ManagedBatchParser/ReliableConnection/ReliableConnectionHelper.cs index 247153be..3b9f0665 100644 --- a/src/Microsoft.SqlTools.ManagedBatchParser/ReliableConnection/ReliableConnectionHelper.cs +++ b/src/Microsoft.SqlTools.ManagedBatchParser/ReliableConnection/ReliableConnectionHelper.cs @@ -13,6 +13,7 @@ using System.Globalization; using System.Security; using Microsoft.SqlTools.Utility; using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Management.Smo; namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection { @@ -649,12 +650,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection // of SQL Server do not have their metadata upgraded to include the xml_index_type column in the sys.xml_indexes view. Because // of this, we must detect the presence of the column to determine if we can query for Selective Xml Indexes public bool IsSelectiveXmlIndexMetadataPresent; - public string OsVersion; - public string MachineName; public string ServerName; - + public int CpuCount; + public int PhysicalMemoryInMB; public Dictionary Options { get; set; } } @@ -676,6 +676,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection public string ServicePackLevel; } + public class ServerSystemInfo + { + public int CpuCount; + public int PhysicalMemoryInMB; + } + public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken) { serverInfo = null; @@ -753,6 +759,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection return hostInfo; } + /// + /// Gets the server host cpu count and memory from sys.dm_os_sys_info view + /// + /// The connection + public static ServerSystemInfo GetServerSystemInfo(IDbConnection connection) + { + var sysInfo = new ServerSystemInfo(); + try + { + SqlConnection sqlConnection = GetAsSqlConnection(connection); + var server = new Server(new ServerConnection(sqlConnection)); + server.SetDefaultInitFields(server.GetType(), new String[] { nameof(server.Processors), nameof(server.PhysicalMemory) }); + sysInfo.CpuCount = server.Processors; + sysInfo.PhysicalMemoryInMB = server.PhysicalMemory; + } + catch (Exception ex) + { + Logger.Write(TraceEventType.Error, ex.ToString()); + throw ex; + } + return sysInfo; + } + /// /// Returns the version of the server. This routine will throw if an exception is encountered. /// @@ -827,6 +856,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection // otherwise - Windows Server 2019 Standard 10.0 serverInfo.OsVersion = hostInfo.Distribution != null ? string.Format("{0} {1}", hostInfo.Distribution, hostInfo.Release) : string.Format("{0} {1}", hostInfo.Platform, hostInfo.Release); + var sysInfo = GetServerSystemInfo(connection); + + serverInfo.CpuCount = sysInfo.CpuCount; + serverInfo.PhysicalMemoryInMB = sysInfo.PhysicalMemoryInMB; + serverInfo.Options = new Dictionary(); // Get BDC endpoints diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 5823fda1..3b13c2bc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -471,7 +471,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection AzureVersion = serverInfo.AzureVersion, OsVersion = serverInfo.OsVersion, MachineName = serverInfo.MachineName, - Options = serverInfo.Options, + CpuCount = serverInfo.CpuCount, + PhysicalMemoryInMB = serverInfo.PhysicalMemoryInMB, + Options = serverInfo.Options }; connectionInfo.IsCloud = serverInfo.IsCloud; connectionInfo.MajorVersion = serverInfo.ServerMajorVersion; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs index 881f41b3..c8aa3195 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs @@ -67,6 +67,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts /// public string MachineName { get; set; } + /// + /// The CPU count of the host running the server. + /// + public int CpuCount; + + /// + /// The physical memory of the host running the server in MBs. + /// + public int PhysicalMemoryInMB; + /// /// Server options ///