This sounds like a physical SQL server environment :-) in any case - yes you can - but you need to overcome some hurdles.
Please understand first that a SQL server will run as a service - eventually as a process. Each process gets assigned a process ID - respective PID - this PID is nothing else then a counter that will change increase with each executed process (in theory).
Conclusion:
Every time your service starts you will have a different PID - making it hard to identity the specific SQL instance you are looking for while automating the identification.
PID or ProcessId is what you look for.
What you would engage is WMI - with those queries
- SELECT * FROM Win32_Service
- will list you all services and their ProcessId
- to identify the SQL instances you might need to filter the executable path of the specific SQL service with the column PathName - assuming the Service Name or Display Name is not unique enough
- SELECT * FROM Win32_PerfFormattedData_PerfProc_Process
- will give you more detailed data about the CPU usage (performance data)
- once you have the ProcessID / PID - you can filter here for the process and hopefully get what you want
If WMI does not help you - PowerShell might
- Get-Process should again be able to help you to identify the server/process PID
- Get-Counter should give you the CPU
In the end - you will need to script this - but you can accomplish it.
Personally I like the PowerShell approach a bit better cause it is more versatile and future proof. But I did not write such a script yet as for what you are looking for. Could be interesting, though.
Regards
Florian Rossmark
www.it-admins.com
Add comment