November 12, 2008

Get CPU Utilization from Remote Windows Machines with WMI

This is a little script that gets the CPU Utilization metric from a remote Windows machine. On multi-way or multi-core machines, it will return an average of all processors/cores.

To run this, you will first need to install the WMI module. Follow the instructions and get the download from here:

import wmi

def get_cpu(computer, user, password):
    c = wmi.WMI(find_classes=False, computer=computer, user=user, password=password)
    utilizations = [cpu.LoadPercentage for cpu in c.Win32_Processor()]
    utilization = int(sum(utilizations) / len(utilizations))
    return utilization
Post a Comment