Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 getting cpu, memory usage from different servers
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 09/24/2012 :  16:43:38  Show Profile  Reply with Quote
Hello all,

I need to get the cpu,memory, servername, date of all our servers and put that info into a table everyday.

I have figured out how to get most of that information.

SELECT getdate()as Date, cpu_count AS [Logical CPU Count], hyperthread_ratio AS [Hyperthread Ratio],cpu_count/hyperthread_ratio AS [Physical CPU Count],
physical_memory_in_bytes/1048576 AS [Physical Memory (MB)],
sqlserver_start_time --, affinity_type_desc -- (affinity_type_desc is only in 2008 R2)

Here is the table I've created:

create table Infrastructure_changes
(date datetime not null,
ServerName varchar (15) not null,
Logical_CPU_Count int not null,
Hyperthread_Ratio int not null,
Physical_CPU_Count int not null,
Physical_Memory int not null,
sqlserver_start_time datetime not null)

We have a table in DBAWork db that lists all our servers.
How do I get the info from the query above for all of our servers on the network?

Your advice would be greatly appreciated.
Thank you.

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 09/24/2012 :  16:46:59  Show Profile  Reply with Quote
using SSIS package is one method

Add a for each loop to iterate through servers, configure a dynamic connection manager for dynamically connecting to each server and then use the source query in OLEDB source task to capture the required information and populate your table using a static oledb destination

SQL Server MVP

Go to Top of Page

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/24/2012 :  21:15:33  Show Profile  Reply with Quote
If you are on server 2008 you can use a Powershell script. If you are on 2003, you will need to install Powershell if you want to run this. I tested the code below on my two windows 7 machines with windows authentication. Be sure to modify the names in the list of servers and the names of the server and database where you are going to store the results.
# Servers to scan
$servers = ( 

# Server and database where data is stored.
$InfrastructureInfoServer = "InfServer";
$InfrastructureDatabase = "InfDatabase";

## Get data from each server and store.
foreach ($s in $servers)
	# Your query to be run against each server. Assumes windows auth.
	$result = Invoke-sqlcmd " `
	 		GETDATE() AS Date, `
	 		@@servername As servername, `
			cpu_count AS [Logical CPU Count], `
			hyperthread_ratio AS [Hyperthread Ratio], `
			cpu_count / hyperthread_ratio AS [Physical CPU Count], `
			physical_memory_in_bytes / 1048576 AS [Physical Memory (MB)], `
			sqlserver_start_time `
		FROM `
			sys.dm_os_sys_info WITH (NOLOCK) OPTION(RECOMPILE); " `
	-ServerInstance "$s" ;
	#Store the results into the Infrastructure server. Assumes windows auth
	Invoke-Sqlcmd " `
  		INSERT INTO Infrastructure_changes values ( `
  			'$($result[0])', `
  			'$($result[1])', `
  			'$($result[2])', `
  			'$($result[3])', `
  			'$($result[4])', `
  			'$($result[5])', `
  			'$($result[6])'  `
  			) " `
	-ServerInstance $InfrastructureInfoServer `
	-Database $InfrastructureDatabase 
Go to Top of Page

Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 09/25/2012 :  01:26:30  Show Profile  Visit jackv's Homepage  Reply with Quote
Powershell is good for this iteration of servers. As well as option outlined abover, There's a few other options, which may fit in with your current management practises:
1) Powershell and SMO -
2) Invoke SQLMD through Powershell -

Jack Vamvas
Go to Top of Page

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/25/2012 :  07:33:56  Show Profile  Reply with Quote
Another seemingly very interesting approach is to use SQL Server Powershell Provider, which lets you work with SQL Server instances and objects as though they are objects in a hierarchy like a directory structure.

I have only read about it and so I don't know if the problem that OP is trying to solve can be addressed using this approach, but it seemed very novel and seemed like it can be very intuitive to use:
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000