Пример #1
0
def bytes_read_write_multi(*partitions_: str,
                           interval=0.0,
                           per_second=False,
                           scale="KiB",
                           precision=2) -> dict:
    """Returns a dictionary with the bytes read and written in the given partitions.

        :Params:
            :partitions (str):  Partitions names (Ex: 'sda1','sda2','sda7')
            :interval (float):  Seconds. When value is greater than zero, it returns bytes read
                                and written in that period of time. When interval value is 0,
                                it returns bytes read and written since the last call
            :per_second (bool): If it's True returns average value per second
            :scale      (str):  Output scale (bytes, KiB, MiB, GiB, TiB, kB, MB, TB or auto)
                                KiB by default
            :precision  (int):  Number of rounding decimal
    """
    dic = _set_delta(*partitions_, interval=interval, persecond=per_second)
    if type(dic) == tuple:
        dic = {partitions_[0]: dic}
    for key, value in dic.items():
        dic[key] = set_bytes(value[0],
                             value[1],
                             scale_in="bytes",
                             scale_out=scale,
                             precision=precision)
    return dic
Пример #2
0
def free(scale="MiB", precision=2):
    """Returns free RAM

        :Params:
            :scale     (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, MB, GB, TB or auto)
            :precision (int): Number of rounding decimals

    """
    return set_bytes(_get_val(b"MemFree")[0], scale_out=scale, precision=precision)
Пример #3
0
def total(scale="MiB", precision=2):
    """Returns total RAM memory size

        :Params:
            :scale     (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, MB, GB, TB or auto)
            :precision (int): Number of rounding decimals

    """
    return set_bytes(_get_val(b"MemTotal")[0], scale_out=scale, precision=precision)
Пример #4
0
def buff_cache(scale="MiB", precision=2):
    """Returns buffers, cached and slab memory

        :Params:
            :precision (int): Number of rounding decimals
    """
    items = (b"Buffers", b"Cached", b"SReclaimable", b"SUnreclaim")
    buff, cache, sre, sur = map(float, _get_val(*items))
    return set_bytes(buff + cache + sre + sur, scale_out=scale, precision=precision)
Пример #5
0
def available(scale="MiB", precision=2):
    """Returns available RAM

    The amount of RAM which is available for allocation to a new process or to existing processes

        :Params:
            :scale     (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, MB, GB, TB or auto)
            :precision (int): Number of rounding decimals

        """
    return set_bytes(_get_val(b"MemAvailable")[0], scale_out=scale, precision=precision)
Пример #6
0
def used(scale="MiB", precision=2):
    """Returns used RAM memory

    Used = Total - (Free + Buffers + Cached + Slab)

        :Params:
            :precision (int): Number of rounding decimals

    """
    items = (b"MemTotal", b"MemFree", b"Buffers", b"Cached", b"Slab")
    tot, free_, buff, cached, slab = map(float, _get_val(*items))
    return set_bytes(tot - (buff + cached + slab + free_), scale_out=scale, precision=precision)
Пример #7
0
def upload_bytes(interface: str, scale="bytes", precision=2):
    """Returns total bytes uploaded in the given interface

        :Params:
            :interface (str): Interface name
            :scale     (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, MB, GB, TB or auto)
            :precision (int): Number of rounding decimals

    """
    return set_bytes(_get_bytes(interface, 1),
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #8
0
def down_up_bytes(interface: str, scale="bytes", precision=2):
    """Returns a tuple with bytes down-uploaded in the given interface

        :Params:
            :interface (str): Interface name
            :scale     (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, MB, GB, TB or auto)
            :precision (int): Number of rounding decimals

    """
    bytes_ = _get_bytes(interface, 2)
    return set_bytes(*bytes_,
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #9
0
def free_space(partition: str, scale="GiB", precision=2):
    """Returns free partition space

        :Params:
            :partition (str): Partition name (Ex: 'sda1')
            :scale     (str): Return scale (bytes, KiB, MiB, GiB, TiB, kB, MB, TB or auto)
            :precision (int): Number of rounding decimals
        """

    stat = _get_stat(partition)
    return set_bytes(stat.f_frsize * stat.f_bavail,
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #10
0
def upload_speed(interface: str, interval=0.0, scale="bytes", precision=2):
    """Returns average upload speed per second in the given interface

        :Params:
            :interface  (str): Interface name
            :interval (float): Interval in seconds.
            :scale      (str): Chosen scale (bytes, KiB, MiB, GiB, TiB, kB, Mb, GB, TB or auto)
            :precision  (int): Number of rounding decimals

    """

    return set_bytes(_set_delta(interface, interval)[1],
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #11
0
def used_space(partition: str, scale="GiB", precision=2):
    """Returns used partition space

        :Params:
            :partition (str): Partition name (Ex: 'sda1')
            :scale     (str): Return scale (bytes, KiB, MiB, GiB, TiB, kB, MB, TB or auto)
                             GiB by default
            :precision (int): Number of rounding decimals
        """

    stat = _get_stat(partition)
    return set_bytes((stat.f_blocks - stat.f_bfree) * stat.f_frsize,
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #12
0
def total_size(partition: str, scale="GiB", precision=2):
    """Returns total size of a partition

    :Params:
        :partition (str): Partition name (Ex: 'sda1')
        :scale     (str): Return scale (bytes, KiB, MiB, GiB, TiB, kB, MB, TB or auto)
                         GiB by default.
        :precision (int): Number of rounding decimals
    """

    stat = _get_stat(partition)
    return set_bytes(stat.f_frsize * stat.f_blocks,
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)
Пример #13
0
def bytes_read_write(partition: str,
                     interval=0.0,
                     per_second=False,
                     scale="KiB",
                     precision=2) -> tuple:
    """Returns a tuple with bytes read and written in a partition in a certain time interval

        :Params:
            :partition  (str):  Partition name (Ex: 'sda1')
            :interval (float):  Seconds. When value is greater than zero, it returns bytes read
                                and written in that period of time. When interval value is 0,
                                it returns bytes read and written since the last call
            :per_second (bool): If it's True returns average value per second
            :scale      (str):  Output scale (bytes, KiB, MiB, GiB, TiB, kB, MB, TB or auto)
                                KiB by default
            :precision  (int):  Number of rounding decimal
    """
    values = _set_delta(partition, interval=interval, persecond=per_second)
    return set_bytes(values[0],
                     values[1],
                     scale_in="bytes",
                     scale_out=scale,
                     precision=precision)