Пример #1
0
def uname(host_os=detect_host_os()):
    """
    Returns detailed host information.

    :depends on: [host_os.uname]
    """
    return " ".join(host_os.uname())
Пример #2
0
def uname(host_os=detect_host_os()):
    """
    Returns detailed host information.

    :depends on: [host_os.uname]
    """
    return " ".join(host_os.uname())
Пример #3
0
def uptime(host_os=detect_host_os()):
    """
    Returns system uptime in seconds.

    :depends on: [host_os.uptime]
    """
    return host_os.uptime()
Пример #4
0
def maxproc(host_os=detect_host_os()):
    """
    Returns maximum number of running processes

    :depends on: [host_os.maximum_number_of_running_processes]
    """
    return host_os.max_number_of_running_processes()
Пример #5
0
def uptime(host_os=detect_host_os()):
    """
    Returns system uptime in seconds.

    :depends on: [host_os.uptime]
    """
    return host_os.uptime()
Пример #6
0
def maxproc(host_os=detect_host_os()):
    """
    Returns maximum number of running processes

    :depends on: [host_os.maximum_number_of_running_processes]
    """
    return host_os.max_number_of_running_processes()
Пример #7
0
def hostname(hostname_type='host', host_os=detect_host_os()):
    """
    Returns host name.

    :raises: WrongArgumentError if unknown hostname_type is supplied

    :depends on: [host_os.hostname, host_os.AVAILABLE_HOSTNAME_TYPES]
    """
    validate_mode(hostname_type, host_os.AVAILABLE_HOSTNAME_TYPES)

    return host_os.hostname(hostname_type)
Пример #8
0
def hostname(hostname_type='host', host_os=detect_host_os()):
    """
    Returns host name.

    :raises: WrongArgumentError if unknown hostname_type is supplied

    :depends on: [host_os.hostname, host_os.AVAILABLE_HOSTNAME_TYPES]
    """
    validate_mode(hostname_type, host_os.AVAILABLE_HOSTNAME_TYPES)

    return host_os.hostname(hostname_type)
Пример #9
0
def size(mode='total', host_os=detect_host_os()):
    """
    Returns an amount of memory of specified mode

    :param mode: Varies with host_os
    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.AVAILABLE_MEMORY_TYPES, host_os.memory]
    """
    validate_mode(mode, host_os.AVAILABLE_MEMORY_TYPES)

    return host_os.memory()[mode]
Пример #10
0
def size(mode='total', host_os=detect_host_os()):
    """
    Returns an amount of memory of specified mode

    :param mode: Varies with host_os
    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.AVAILABLE_MEMORY_TYPES, host_os.memory]
    """
    validate_mode(mode, host_os.AVAILABLE_MEMORY_TYPES)

    return host_os.memory()[mode]
Пример #11
0
def size(device='all', mode='free', host_os=detect_host_os()):
    """
    Returns free and total swap size converted according to mode

    :param mode: one of free, total, used, pfree, pused

    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.swap_size]
    """
    validate_mode(mode, SIZE_CONVERSION_MODES)

    free, total = host_os.swap_size(device)

    return convert_size(free, total, mode)
Пример #12
0
def size(device="all", mode="free", host_os=detect_host_os()):
    """
    Returns free and total swap size converted according to mode

    :param mode: one of free, total, used, pfree, pused

    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.swap_size]
    """
    validate_mode(mode, SIZE_CONVERSION_MODES)

    free, total = host_os.swap_size(device)

    return convert_size(free, total, mode)
Пример #13
0
def size(filesystem, mode="total", host_os=detect_host_os()):
    """
    Returns free and total fs size converted according to mode

    :param filesystem: what filesystem to check
    :type filesystem: str

    :param mode: one of free, total, used, pfree, pused

    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.fs_size]
    """
    validate_mode(mode, SIZE_CONVERSION_MODES)

    free, total = host_os.fs_size(filesystem)

    return convert_size(free, total, mode)
Пример #14
0
Файл: fs.py Проект: blin/zabby
def size(filesystem, mode="total", host_os=detect_host_os()):
    """
    Returns free and total fs size converted according to mode

    :param filesystem: what filesystem to check
    :type filesystem: str

    :param mode: one of free, total, used, pfree, pused

    :raises: WrongArgument if unsupported mode is supplied

    :depends on: [host_os.fs_size]
    """
    validate_mode(mode, SIZE_CONVERSION_MODES)

    free, total = host_os.fs_size(filesystem)

    return convert_size(free, total, mode)
Пример #15
0
def out_of_memory(device='all', mode='count', host_os=detect_host_os()):
    """
    Returns total number of pages written to swap or total number of write
    operations or sectors written to swap device

    :param mode: should be one of {'count', 'pages', 'sectors'}

    :raises: WrongArgumentError if mode is pages and device is not 'all'
    :raises: WrongArgumentError if mode is unknown
    :raises: WrongArgumentError if mode is unavailable on this host_os

    :depends on: [
        host_os.swap_info,
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES,
        host_os.swap_device_names,
        host_os.disk_device_stats,
    ]
    """
    return into_out_of('write', device, mode, host_os)
Пример #16
0
def outgoing(interface_name, mode="bytes", host_os=detect_host_os()):
    """
    Returns amount of sent bytes or packets, dropped outgoing packets or
    send errors

    :depends on: [host_os.net_interface_names, host_os.net_interface_info]
    :raises: WrongArgument if unsupported mode is supplied
    :raises: WrongArgument if interface is not present on this host
    :type interface_name: str
    """
    validate_mode(mode, NET_MODES)

    interface_names = host_os.net_interface_names()
    validate_mode(interface_name, interface_names)

    info = host_os.net_interface_info(interface_name)

    return info._asdict()["{direction}_{mode}".format(direction='out',
                                                      mode=mode)]
Пример #17
0
def out_of_memory(device="all", mode="count", host_os=detect_host_os()):
    """
    Returns total number of pages written to swap or total number of write
    operations or sectors written to swap device

    :param mode: should be one of {'count', 'pages', 'sectors'}

    :raises: WrongArgumentError if mode is pages and device is not 'all'
    :raises: WrongArgumentError if mode is unknown
    :raises: WrongArgumentError if mode is unavailable on this host_os

    :depends on: [
        host_os.swap_info,
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES,
        host_os.swap_device_names,
        host_os.disk_device_stats,
    ]
    """
    return into_out_of("write", device, mode, host_os)
Пример #18
0
def incoming(interface_name, mode="bytes", host_os=detect_host_os()):
    """
    Returns amount of received bytes or packets, dropped incoming packets or
    receive errors

    :depends on: [host_os.net_interface_names, host_os.net_interface_info]
    :raises: WrongArgument if unsupported mode is supplied
    :raises: WrongArgument if interface is not present on this host
    :type interface_name: str
    """
    validate_mode(mode, NET_MODES)

    interface_names = host_os.net_interface_names()
    validate_mode(interface_name, interface_names)

    info = host_os.net_interface_info(interface_name)

    return info._asdict()[
        "{direction}_{mode}".format(direction='in', mode=mode)
    ]
Пример #19
0
Файл: proc.py Проект: blin/zabby
def num(name=ALL_PROCESSES, user=ALL_USERS, state='all', cmdline=None,
        host_os=detect_host_os()):
    """
    Returns number of userspace processes matching filter

    :depends on: [host_os.process_infos, host_os.uid]
    :raises: WrongArgument if unsupported state is supplied
    :raises: OperatingSystemError if user is invalid
    """
    validate_mode(state, PROC_NUM_MODES)

    uid = None
    if user != ALL_USERS:
        uid = host_os.uid(user)

    number_of_processes = 0
    for process_info in host_os.process_infos():
        if _matches_filter(process_info, name, uid, state, cmdline):
            number_of_processes += 1

    return number_of_processes
Пример #20
0
Файл: dev.py Проект: blin/zabby
def read(device='all', stat_type='operations', mode='avg1',
         host_os=detect_host_os()):
    """
    Returns total number of read operations, or bytes or sectors read from
    device.

    :param device: Should be either all or device name
    :param stat_type: Should be one of
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES

    :raises: WrongArgumentError if unknown device is supplied
    :raises: WrongArgumentError if unknown stat_type is supplied

    :depends on: [
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES,
        host_os.disk_device_names,
        host_os.disk_device_stats,
        host_os.disk_device_stats_shifted
    ]
    """
    return read_write('read', device, stat_type, mode, host_os)
Пример #21
0
Файл: cpu.py Проект: blin/zabby
def load(cpu='all', mode='avg1', host_os=detect_host_os()):
    """
    Returns average number of processes that are either in a runnable or
    uninterruptable state.

    :raises: WrongArgumentError if unknown cpu is supplied
    :raises: WrongArgumentError if unknown mode is supplied

    :depends on: [host_os.system_load, host_os.cpu_count]
    """
    validate_mode(cpu, ['all', 'percpu'])
    validate_mode(mode, AVERAGE_MODE.keys())

    system_load = host_os.system_load()

    value = system_load._asdict()[mode]

    if cpu == 'percpu':
        value /= host_os.cpu_count()

    return value
Пример #22
0
Файл: cpu.py Проект: blin/zabby
def load(cpu='all', mode='avg1', host_os=detect_host_os()):
    """
    Returns average number of processes that are either in a runnable or
    uninterruptable state.

    :raises: WrongArgumentError if unknown cpu is supplied
    :raises: WrongArgumentError if unknown mode is supplied

    :depends on: [host_os.system_load, host_os.cpu_count]
    """
    validate_mode(cpu, ['all', 'percpu'])
    validate_mode(mode, AVERAGE_MODE.keys())

    system_load = host_os.system_load()

    value = system_load._asdict()[mode]

    if cpu == 'percpu':
        value /= host_os.cpu_count()

    return value
Пример #23
0
Файл: cpu.py Проект: blin/zabby
def util(cpu='all', state='user', mode='avg1', host_os=detect_host_os()):
    """
    Returns average percentage of time spent by cpu in a state over a period
    of time

    :raises: WrongArgumentError if unknown cpu is supplied
    :raises: WrongArgumentError if unknown state is supplied
    :raises: WrongArgumentError if unknown mode is supplied

    :depends on: [host_os.cpu_count, host_os.cpu_times_shifted,
                  host_os.cpu_times]
    """
    validate_mode(state, CPU_TIMES)

    available_cpus = list(range(host_os.cpu_count()))
    if cpu == 'all':
        cpus = available_cpus
    else:
        cpu = int(cpu)
        validate_mode(cpu, available_cpus)
        cpus = [cpu]

    validate_mode(mode, AVERAGE_MODE.keys())

    time_in_state = 0
    time_total = 0
    for cpu in cpus:
        shifted_cpu_times = host_os.cpu_times_shifted(cpu, AVERAGE_MODE[mode])
        if shifted_cpu_times is not None:
            current_cpu_times = host_os.cpu_times(cpu)

            cpu_time_in_state = (current_cpu_times._asdict()[state] -
                                 shifted_cpu_times._asdict()[state])
            cpu_time_total = (sum(current_cpu_times) - sum(shifted_cpu_times))

            time_in_state += cpu_time_in_state
            time_total += cpu_time_total
    return (((time_in_state * 100) / time_total)
            if time_total != 0
            else 0.0)
Пример #24
0
Файл: cpu.py Проект: blin/zabby
def util(cpu='all', state='user', mode='avg1', host_os=detect_host_os()):
    """
    Returns average percentage of time spent by cpu in a state over a period
    of time

    :raises: WrongArgumentError if unknown cpu is supplied
    :raises: WrongArgumentError if unknown state is supplied
    :raises: WrongArgumentError if unknown mode is supplied

    :depends on: [host_os.cpu_count, host_os.cpu_times_shifted,
                  host_os.cpu_times]
    """
    validate_mode(state, CPU_TIMES)

    available_cpus = list(range(host_os.cpu_count()))
    if cpu == 'all':
        cpus = available_cpus
    else:
        cpu = int(cpu)
        validate_mode(cpu, available_cpus)
        cpus = [cpu]

    validate_mode(mode, AVERAGE_MODE.keys())

    time_in_state = 0
    time_total = 0
    for cpu in cpus:
        shifted_cpu_times = host_os.cpu_times_shifted(cpu, AVERAGE_MODE[mode])
        if shifted_cpu_times is not None:
            current_cpu_times = host_os.cpu_times(cpu)

            cpu_time_in_state = (current_cpu_times._asdict()[state] -
                                 shifted_cpu_times._asdict()[state])
            cpu_time_total = (sum(current_cpu_times) - sum(shifted_cpu_times))

            time_in_state += cpu_time_in_state
            time_total += cpu_time_total
    return (((time_in_state * 100) / time_total) if time_total != 0 else 0.0)
Пример #25
0
Файл: dev.py Проект: blin/zabby
def write(device='all',
          stat_type='operations',
          mode='avg1',
          host_os=detect_host_os()):
    """
    Returns total number of read operations, or bytes or sectors read from
    device.

    :param device: Should be either all or device name
    :param stat_type: Should be one of
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES

    :raises: WrongArgumentError if unknown device is supplied
    :raises: WrongArgumentError if unknown stat_type is supplied

    :depends on: [
        host_os.AVAILABLE_DISK_DEVICE_STATS_TYPES,
        host_os.disk_device_names,
        host_os.disk_device_stats,
        host_os.disk_device_stats_shifted
    ]
    """
    return read_write('write', device, stat_type, mode, host_os)
Пример #26
0
 def test_linux_is_detected_correctly(self):
     detected_os = detect_host_os()
     assert_is_instance(detected_os, self.linux.__class__)
Пример #27
0
 def test_linux_is_detected_correctly(self):
     detected_os = detect_host_os()
     assert_is_instance(detected_os, self.linux.__class__)