示例#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
文件: __init__.py 项目: blin/zabby
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
文件: kernel.py 项目: blin/zabby
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
文件: __init__.py 项目: blin/zabby
def uptime(host_os=detect_host_os()):
    """
    Returns system uptime in seconds.

    :depends on: [host_os.uptime]
    """
    return host_os.uptime()
示例#6
0
文件: kernel.py 项目: blin/zabby
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
文件: __init__.py 项目: blin/zabby
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
文件: memory.py 项目: blin/zabby
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
文件: memory.py 项目: blin/zabby
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
文件: interface.py 项目: blin/zabby
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
文件: test_linux.py 项目: blin/zabby
 def test_linux_is_detected_correctly(self):
     detected_os = detect_host_os()
     assert_is_instance(detected_os, self.linux.__class__)
示例#27
0
文件: test_linux.py 项目: blin/zabby
 def test_linux_is_detected_correctly(self):
     detected_os = detect_host_os()
     assert_is_instance(detected_os, self.linux.__class__)