问题
I don't want the list of all process, just a total percentage like you would see in windows taskmanager.
I will be using this information via coldfusion, but i am having all kinds of problems just trying to find a total number of current cpu usage.
I don't care if it comes from wmi or t-sql, i just want a total number for which i will be using to populate a gauge chart that via ajax will be showing my current cpu usage percentage...
Thank You...
回答1:
You can use the Win32_PerfRawData_PerfOS_Processor WMI class to get this information. In your query you would use Win32_PerfFormattedData_PerfOS_Processor.Name='_Total'
. See the article ColdFusion and WMI for more information on using WMI as well as the sample vbscirpt code in this article.
回答2:
If it were me I would setup a perfmon counter on the machine in question to measure total CPU. This can be configured to write to a CSV file every couple of seconds.
You can then either have a task that writes that file to the database every minute and get CF to read that data so you can see a graph over time. Or, if you need the most recent value then just get CF to read the CSV file's last value and use that for your gauge.
Personally I store all the data in the database for all our web servers so I can see performance over time and run reports on busy or problem periods. Works great for us.
Hope that helps!
回答3:
This someone else's answer, but in T-SQL, you could use this:
DECLARE @ts_now BIGINT
SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, ms_ticks) FROM sys.dm_os_sys_info
SELECT top 1 record_id,
DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,
SQLProcessUtilization,
SystemIdle,
100 - SystemIdle - SQLProcessUtilization AS OtherProcessUtilization,
100 - SystemIdle AS TotalCPU
FROM (
SELECT
record.value('(./Record/@id)[1]', 'int') AS record_id,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') AS SystemIdle,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') AS SQLProcessUtilization,
TIMESTAMP
FROM (
SELECT TIMESTAMP, CONVERT(XML, record) AS record
FROM sys.dm_os_ring_buffers
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
AND record LIKE '% %') AS x
) AS y
ORDER BY record_id DESC
来源:https://stackoverflow.com/questions/3534868/get-total-cpu-via-wmi-or-t-sql