Example #1
0
def test_tera():
    assert bytes2human(tera(1.)) == '1.0TB'
    assert bytes2human(tera(999.)) == '999.0TB'
Example #2
0
    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 ''
Example #3
0
def test_mb():
    assert bytes2human(mega(1.)) == '1.0MB'
    assert bytes2human(mega(123.)) == '123.0MB'
    assert bytes2human(mega(1023.9)) == '1023.9MB'
Example #4
0
def test_giga():
    assert bytes2human(giga(1.)) == '1.0GB'
    assert bytes2human(giga(999.2)) == '999.2GB'
    assert bytes2human(giga(1023.9)) == '1023.9GB'
Example #5
0
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'
Example #6
0
def test_kb():
    assert bytes2human(kbyte(1)) == '1.0KB'
    assert bytes2human(kbyte(2)) == '2.0KB'
    assert bytes2human(kbyte(1023.9)) == '1023.9KB'
Example #7
0
def test_tera():
    bytes2human(tera(1.)).should.be.equal('1.0TB')
    bytes2human(tera(999.)).should.be.equal('999.0TB')
Example #8
0
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')
Example #9
0
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')
Example #10
0
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')
Example #11
0
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')