mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Adding cpu count and ram size to server info (#1220)
* adding network file validator contract * Adding additional properties to serverInfo * Renaming to serversysinfo * fixing var name * Changed to smo to get the properties * Fixing casting error * renaming to sysinfo * Removing unused sql scripts * Throwing an error and renaming classes * Changing Physicalmemory prop name from kb to mb * pushing prop name change * fixing comment
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Globalization;
|
|||||||
using System.Security;
|
using System.Security;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
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 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
|
// of this, we must detect the presence of the column to determine if we can query for Selective Xml Indexes
|
||||||
public bool IsSelectiveXmlIndexMetadataPresent;
|
public bool IsSelectiveXmlIndexMetadataPresent;
|
||||||
|
|
||||||
public string OsVersion;
|
public string OsVersion;
|
||||||
|
|
||||||
public string MachineName;
|
public string MachineName;
|
||||||
public string ServerName;
|
public string ServerName;
|
||||||
|
public int CpuCount;
|
||||||
|
public int PhysicalMemoryInMB;
|
||||||
public Dictionary<string, object> Options { get; set; }
|
public Dictionary<string, object> Options { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,6 +676,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
public string ServicePackLevel;
|
public string ServicePackLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ServerSystemInfo
|
||||||
|
{
|
||||||
|
public int CpuCount;
|
||||||
|
public int PhysicalMemoryInMB;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken)
|
public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken)
|
||||||
{
|
{
|
||||||
serverInfo = null;
|
serverInfo = null;
|
||||||
@@ -753,6 +759,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
return hostInfo;
|
return hostInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the server host cpu count and memory from sys.dm_os_sys_info view
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">The connection</param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the version of the server. This routine will throw if an exception is encountered.
|
/// Returns the version of the server. This routine will throw if an exception is encountered.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -827,6 +856,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
// otherwise - Windows Server 2019 Standard 10.0
|
// 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);
|
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<string, object>();
|
serverInfo.Options = new Dictionary<string, object>();
|
||||||
|
|
||||||
// Get BDC endpoints
|
// Get BDC endpoints
|
||||||
|
|||||||
@@ -471,7 +471,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
AzureVersion = serverInfo.AzureVersion,
|
AzureVersion = serverInfo.AzureVersion,
|
||||||
OsVersion = serverInfo.OsVersion,
|
OsVersion = serverInfo.OsVersion,
|
||||||
MachineName = serverInfo.MachineName,
|
MachineName = serverInfo.MachineName,
|
||||||
Options = serverInfo.Options,
|
CpuCount = serverInfo.CpuCount,
|
||||||
|
PhysicalMemoryInMB = serverInfo.PhysicalMemoryInMB,
|
||||||
|
Options = serverInfo.Options
|
||||||
};
|
};
|
||||||
connectionInfo.IsCloud = serverInfo.IsCloud;
|
connectionInfo.IsCloud = serverInfo.IsCloud;
|
||||||
connectionInfo.MajorVersion = serverInfo.ServerMajorVersion;
|
connectionInfo.MajorVersion = serverInfo.ServerMajorVersion;
|
||||||
|
|||||||
@@ -67,6 +67,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string MachineName { get; set; }
|
public string MachineName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CPU count of the host running the server.
|
||||||
|
/// </summary>
|
||||||
|
public int CpuCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The physical memory of the host running the server in MBs.
|
||||||
|
/// </summary>
|
||||||
|
public int PhysicalMemoryInMB;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server options
|
/// Server options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user