def _refresh(self):
        if self._type == 'virt':
            memUsage = psutil.virtual_memory()
        else:
            memUsage = psutil.swap_memory()

        if self._total != humanize_bytes(memUsage.total, 2):
            self._total = humanize_bytes(memUsage.total, 2)
            self.totalChanged.emit(self._total)

        if self._type == 'virt':
            if self._available != humanize_bytes(memUsage.available, 2):
                self._available = humanize_bytes(memUsage.available, 2)
                self.availableChanged.emit(self._available)

        if self._percent != str(memUsage.percent) + '%':
            self._percent = str(memUsage.percent) + '%'
            self.percentChanged.emit(self._percent)

        if self._used != humanize_bytes(memUsage.used, 2):
            self._used = humanize_bytes(memUsage.used, 2)
            self.usedChanged.emit(self._used)

        if self._free != humanize_bytes(memUsage.free, 2):
            self._free = humanize_bytes(memUsage.free, 2)
            self.freeChanged.emit(self._free)
Exemple #2
0
    def _refresh(self):
        self._data = []

        for p in psutil.process_iter():
            mem = p.get_memory_info()

            self._data.append([
                p.pid,
                p.name,
                p.username,
                str(p.status),
                humanize_bytes(mem.vms),
                humanize_bytes(mem.rss),
                str(round(p.get_memory_percent(), 2)) + "%",
                str(p.get_cpu_percent(interval=None)) + "%"
            ])

        self._data = sorted(self._data, key=lambda p: float(p[-1][:-1]), reverse=True)
        #self.reset()
        self.dataChanged.emit(self.index(0, 0), self.index(self.rowCount() - 1, self.columnCount() - 1))
 def getTotalMemory(self):
     return humanize_bytes(psutil.virtual_memory().total)
    def _refresh(self):
        if self._iface != 'total':
            netinfo = psutil.network_io_counters(pernic=True)[self._iface]
        else:
            netinfo = psutil.network_io_counters()    
        
        
        if self._firstRun:
            self._bytesSentSpeed = '0 bytes/s'
            self._bytesReceivedSpeed = '0 bytes/s'
            self._packetsSentSpeed = '0 packets/s'
            self._packetsReceivedSpeed = '0 packets/s'

            self.bytesSentSpeedChanged.emit(self._bytesSentSpeed)
            self.bytesReceivedSpeedChanged.emit(self._bytesReceivedSpeed)
            self.packetsSentSpeedChanged.emit(self._packetsSentSpeed)
            self.packetsReceivedSpeedChanged.emit(self._packetsReceivedSpeed)

            self._bytesSent = netinfo.bytes_sent
            self._bytesReceived = netinfo.bytes_recv
            self._packetsSent = netinfo.packets_sent
            self._packetsReceived = netinfo.packets_recv

            self.bytesSentChanged.emit(humanize_bytes(self._bytesSent, 2))
            self.bytesReceivedChanged.emit(humanize_bytes(self._bytesReceived, 2))
            self.packetsSentChanged.emit(str(self._packetsSent))
            self.packetsReceivedChanged.emit(str(self._packetsReceived))

            self._firstRun = False

        else:
            # calculate data transmision speeds per minute
            speed = humanize_bytes((netinfo.bytes_sent - self._bytesSent) / self._refreshRate, 2) + '/s'
            if speed != self._bytesSentSpeed:
                self._bytesSentSpeed = speed
                self.bytesSentSpeedChanged.emit(self._bytesSentSpeed)

            speed = humanize_bytes((netinfo.bytes_recv - self._bytesReceived) / self._refreshRate, 2) + '/s'
            if speed != self._bytesReceivedSpeed:
                self._bytesReceivedSpeed = speed
                self.bytesReceivedSpeedChanged.emit(self._bytesReceivedSpeed)

            speed = str(netinfo.packets_sent - self._packetsSent) + ' packets/s'
            if speed != self._packetsSentSpeed:
                self._packetsSentSpeed = speed
                self.packetsSentSpeedChanged.emit(self._packetsSentSpeed)

            speed = str(netinfo.packets_recv - self._packetsReceived) + ' packets/s'
            if speed != self._packetsReceivedSpeed:
                self._packetsReceivedSpeed = speed
                self.packetsReceivedSpeedChanged.emit(self._packetsReceivedSpeed)


            # calculate total data transfered
            if (netinfo.bytes_sent != self._bytesSent):
                self._bytesSent = netinfo.bytes_sent
                #print(self._iface + ': Bytes sent: ' + str(self._bytesSent))
                self.bytesSentChanged.emit(humanize_bytes(self._bytesSent, 2))

            if (netinfo.bytes_recv != self._bytesReceived):
                self._bytesReceived = netinfo.bytes_recv
                #print(self._iface + ': Bytes received' + str(self._bytesReceived))
                self.bytesReceivedChanged.emit(humanize_bytes(self._bytesReceived, 2))

            if (netinfo.packets_sent != self._packetsSent):
                self._packetsSent = netinfo.packets_sent
                self.packetsSentChanged.emit(str(self._packetsSent))

            if (netinfo.packets_recv != self._packetsReceived):
                self._packetsReceived = netinfo.packets_recv
                self.packetsReceivedChanged.emit(str(self._packetsReceived))