Example #1
0
    class SystemLoadThread(Thread):
        def __init__(self):
            super(SystemLoadThread, self).__init__()
            self.daemon = True
            self.samples = deque(maxlen=10)
            self.load = 0.5
            self.counter = PerformanceCounter(r'\System\Processor Queue Length', r'\Processor(_Total)\% Processor Time')

        def run(self):
            while True:
                pql, pt = self.counter.query()
                self.samples.append(pql)
                if pt >= 100:
                    self.load = max(sum(self.samples) / len(self.samples) / _cpu_count, pt / 100.)
                else:
                    self.load = pt / 100.
                sleep(1)
Example #2
0
 def __init__(self):
     super(SystemLoadThread, self).__init__()
     self.daemon = True
     self.samples = deque(maxlen=10)
     self.load = 0.5
     self.counter = PerformanceCounter(r'\System\Processor Queue Length', r'\Processor(_Total)\% Processor Time')