def test_tera(): assert bytes2human(tera(1.)) == '1.0TB' assert bytes2human(tera(999.)) == '999.0TB'
def render(self, context): try: import psutil as pu except: context['error_psutil'] = 'not_found' return '' # cpu cpu_info = cpuTuple( core=pu.NUM_CPUS, used=pu.cpu_percent()) # memory mem_info = memTuple( total=bytes2human(pu.TOTAL_PHYMEM), used=pu.virtual_memory().percent) # disk partitions = list() for part in pu.disk_partitions(): partitions.append( diskPartTuple( device=part.device, mountpoint=part.mountpoint, fstype=part.fstype, total=bytes2human( pu.disk_usage(part.mountpoint).total), percent=pu.disk_usage(part.mountpoint).percent)) # network networks = list() for k, v in pu.net_io_counters(pernic=True).items(): # Skip loopback interface if k == 'lo': continue networks.append( networkTuple( device=k, sent=bytes2human(v.bytes_sent), recv=bytes2human(v.bytes_recv), pkg_sent=v.packets_sent, pkg_recv=v.packets_recv)) # processes processes = list() for process in pu.process_iter(): try: percent = process.get_memory_percent() except AccessDenied: percent = "Access Denied" else: percent = int(percent) processes.append(processTuple( pid=process.pid, name=process.name, status=process.status, user=process.username, memory=percent)) processes_sorted = sorted( processes, key=lambda p: p.memory, reverse=True) all_stats = { 'cpu_info': cpu_info, 'mem_info': mem_info, 'partitions': partitions, 'networks': networks, 'processes': processes_sorted[:10], } context.update(all_stats) return ''
def test_mb(): assert bytes2human(mega(1.)) == '1.0MB' assert bytes2human(mega(123.)) == '123.0MB' assert bytes2human(mega(1023.9)) == '1023.9MB'
def test_giga(): assert bytes2human(giga(1.)) == '1.0GB' assert bytes2human(giga(999.2)) == '999.2GB' assert bytes2human(giga(1023.9)) == '1023.9GB'
def test_bytes(): assert bytes2human(0.) == '0.0bytes' assert bytes2human(0.1) == '0.1bytes' assert bytes2human(1.) == '1.0bytes' assert bytes2human(100.) == '100.0bytes' assert bytes2human(1023.9) == '1023.9bytes'
def test_kb(): assert bytes2human(kbyte(1)) == '1.0KB' assert bytes2human(kbyte(2)) == '2.0KB' assert bytes2human(kbyte(1023.9)) == '1023.9KB'
def test_tera(): bytes2human(tera(1.)).should.be.equal('1.0TB') bytes2human(tera(999.)).should.be.equal('999.0TB')
def test_giga(): bytes2human(giga(1.)).should.be.equal('1.0GB') bytes2human(giga(999.2)).should.be.equal('999.2GB') bytes2human(giga(1023.9)).should.be.equal('1023.9GB')
def test_mb(): bytes2human(mega(1.)).should.be.equal('1.0MB') bytes2human(mega(123.)).should.be.equal('123.0MB') bytes2human(mega(1023.9)).should.be.equal('1023.9MB')
def test_kb(): bytes2human(kbyte(1)).should.be.equal('1.0KB') bytes2human(kbyte(2)).should.be.equal('2.0KB') bytes2human(kbyte(1023.9)).should.be.equal('1023.9KB')
def test_bytes(): bytes2human(0.).should.be.equal('0.0bytes') bytes2human(0.1).should.be.equal('0.1bytes') bytes2human(1.).should.be.equal('1.0bytes') bytes2human(100.).should.be.equal('100.0bytes') bytes2human(1023.9).should.be.equal('1023.9bytes')