Beispiel #1
0
    def memory(self):
        """
        Uses /proc/meminfo to obtain information on memory usage

        See `man 5 proc` for more information
        """
        mem_info = dict_from_file('/proc/meminfo')
        total = to_bytes(*mem_info['MemTotal:'].split())
        free = to_bytes(*mem_info['MemFree:'].split())
        buffers = to_bytes(*mem_info['Buffers:'].split())
        cached = to_bytes(*mem_info['Cached:'].split())

        available = free + buffers + cached
        pavailable = (available * 100) / total

        used = total - available
        pused = (used * 100) / total

        return {
            'total': total,
            'free': free,
            'buffers': buffers,
            'cached': cached,
            'available': available,
            'pavailable': pavailable,
            'used': used,
            'pused': pused,
        }
Beispiel #2
0
    def memory(self):
        """
        Uses /proc/meminfo to obtain information on memory usage

        See `man 5 proc` for more information
        """
        mem_info = dict_from_file('/proc/meminfo')
        total = to_bytes(*mem_info['MemTotal:'].split())
        free = to_bytes(*mem_info['MemFree:'].split())
        buffers = to_bytes(*mem_info['Buffers:'].split())
        cached = to_bytes(*mem_info['Cached:'].split())

        available = free + buffers + cached
        pavailable = (available * 100) / total

        used = total - available
        pused = (used * 100) / total

        return {
            'total': total,
            'free': free,
            'buffers': buffers,
            'cached': cached,
            'available': available,
            'pavailable': pavailable,
            'used': used,
            'pused': pused,
        }
Beispiel #3
0
    def _process_status(self, process_id):
        process_status_file_path = os.path.join('/proc', process_id, 'status')
        process_status = dict_from_file(process_status_file_path, ':\t')

        process_status['Uid'] = int(process_status['Uid'].split('\t')
                                    [0])  # only effective UID is needed
        process_status['State'] = PROCESS_STATE_MAP.get(
            process_status['State'], 'sleep')

        # VmSize field can be missing
        # See ${linux}/fs/proc/array.c:proc_pid_status for more information
        if 'VmSize' in process_status:
            process_status['VmSize'] = to_bytes(
                *process_status['VmSize'].split())
        else:
            process_status['VmSize'] = 0

        return process_status
Beispiel #4
0
    def _process_status(self, process_id):
        process_status_file_path = os.path.join('/proc', process_id, 'status')
        process_status = dict_from_file(process_status_file_path, ':\t')

        process_status['Uid'] = int(
            process_status['Uid'].split('\t')[0]
        )  # only effective UID is needed
        process_status['State'] = PROCESS_STATE_MAP.get(
            process_status['State'], 'sleep'
        )

        # VmSize field can be missing
        # See ${linux}/fs/proc/array.c:proc_pid_status for more information
        if 'VmSize' in process_status:
            process_status['VmSize'] = to_bytes(
                *process_status['VmSize'].split())
        else:
            process_status['VmSize'] = 0

        return process_status
Beispiel #5
0
 def test_returns_integer(self):
     value = to_bytes(1, 'kB')
     assert_is_instance(value, integer_types)
Beispiel #6
0
 def test_returns_integer(self):
     value = to_bytes(1, 'kB')
     assert_is_instance(value, integer_types)