Returns disk usage for /tmp

    :returns: Disk usage (total, used, percentage used)
    :rtype dict
331929
def read_disk():
    
    s = os.statvfs("/tmp")
    return {
        # This should report as 500MB, if not may need to be hardcoded
        # https://aws.amazon.com/lambda/faqs/
        "totalMiB": (s.f_blocks * s.f_bsize) / MB_FACTOR,
        "usedMiB": ((s.f_blocks - s.f_bfree) * s.f_frsize) / MB_FACTOR,
        "usedPercentage": round(
            (((s.f_blocks - s.f_bfree) * s.f_frsize) / (s.f_blocks * s.f_bsize)) * 100,
            2,
        ),
    }
1005085
async def async_get_bytes_total(self, use_cache=True):
        """"""
        now = datetime.utcnow()
        if use_cache and self._trans_cache_timer and self._cache_time > \
                (now - self._trans_cache_timer).total_seconds():
            return self._transfer_rates_cache

        rx = await self.async_get_rx()
        tx = await self.async_get_tx()
        return rx, tx
821652
def get_workspace_disk_usage(workspace, summarize=False):
    """"""
    command = ['du', '-h']
    if summarize:
        command.append('-s')
    else:
        command.append('-a')
    command.append(workspace)
    disk_usage_info = subprocess.check_output(command).decode().split()
    # create pairs of (size, filename)
    filesize_pairs = list(zip(disk_usage_info[::2], disk_usage_info[1::2]))
    filesizes = []
    for filesize_pair in filesize_pairs:
        size, name = filesize_pair
        # trim workspace path in every file name
        filesizes.append({'name': name[len(workspace):],
                          'size': size})
    return filesizes
207092
def get_host_usage(self):
        
        import psutil
        process_names = [proc.name for proc in psutil.process_iter()]
        cpu_pct = psutil.cpu_percent(interval=1)
        mem = psutil.virtual_memory()
        return str(cpu_pct), str(len(process_names)), str(mem.available), str(mem.total)
657719
def diskusage(path):
    '''
    
    '''

    total_size = 0
    seen = set()
    if os.path.isfile(path):
        stat_structure = os.stat(path)
        ret = stat_structure.st_size
        return ret

    for dirpath, dirnames, filenames in salt.utils.path.os_walk(path):
        for f in filenames:
            fp = os.path.join(dirpath, f)

            try:
                stat_structure = os.stat(fp)
            except OSError:
                continue

            if stat_structure.st_ino in seen:
                continue

            seen.add(stat_structure.st_ino)

            total_size += stat_structure.st_size

    ret = total_size
    return ret
338028
def machine_info():
    
    import psutil
    BYTES_IN_GIG = 1073741824.0
    free_bytes = psutil.virtual_memory().total
    return [{"memory": float("%.1f" % (free_bytes / BYTES_IN_GIG)), "cores": multiprocessing.cpu_count(),
             "name": socket.gethostname()}]
306249
def _get_usage(ctx):
    """"""
    formatter = ctx.make_formatter()
    pieces = ctx.command.collect_usage_pieces(ctx)
    formatter.write_usage(ctx.command_path, ' '.join(pieces), prefix='')
    return formatter.getvalue().rstrip('\n')
317485
def usage(self):
        
        c = self._s2i_command(["usage", self.get_full_name()])
        with open(os.devnull, "w") as fd:
            process = subprocess.Popen(c, stdout=fd, stderr=subprocess.PIPE)
            _, output = process.communicate()
            retcode = process.poll()
        if retcode:
            raise ConuException("`s2i usage` failed: %s" % output)
        return output.decode("utf-8").strip()
43559
def os_volumes(self):
        
        if not self.__os_volumes:
            self.__os_volumes = OsVolumes(self.__connection)
        return self.__os_volumes
731646
def collect_metrics(self):
        
        try:
            g = None
            u = resource.getrusage(resource.RUSAGE_SELF)
            if gc_.isenabled():
                c = list(gc_.get_count())
                th = list(gc_.get_threshold())
                g = GC(collect0=c[0] if not self.last_collect else c[0] - self.last_collect[0],
                       collect1=c[1] if not self.last_collect else c[
                           1] - self.last_collect[1],
                       collect2=c[2] if not self.last_collect else c[
                           2] - self.last_collect[2],
                       threshold0=th[0],
                       threshold1=th[1],
                       threshold2=th[2])

            thr = threading.enumerate()
            daemon_threads = [tr.daemon is True for tr in thr].count(True)
            alive_threads = [tr.daemon is False for tr in thr].count(True)
            dummy_threads = [type(tr) is threading._DummyThread for tr in thr].count(True)

            m = Metrics(ru_utime=u[0] if not self.last_usage else u[0] - self.last_usage[0],
                        ru_stime=u[1] if not self.last_usage else u[1] - self.last_usage[1],
                        ru_maxrss=u[2],
                        ru_ixrss=u[3],
                        ru_idrss=u[4],
                        ru_isrss=u[5],
                        ru_minflt=u[6] if not self.last_usage else u[6] - self.last_usage[6],
                        ru_majflt=u[7] if not self.last_usage else u[7] - self.last_usage[7],
                        ru_nswap=u[8] if not self.last_usage else u[8] - self.last_usage[8],
                        ru_inblock=u[9] if not self.last_usage else u[9] - self.last_usage[9],
                        ru_oublock=u[10] if not self.last_usage else u[10] - self.last_usage[10],
                        ru_msgsnd=u[11] if not self.last_usage else u[11] - self.last_usage[11],
                        ru_msgrcv=u[12] if not self.last_usage else u[12] - self.last_usage[12],
                        ru_nsignals=u[13] if not self.last_usage else u[13] - self.last_usage[13],
                        ru_nvcs=u[14] if not self.last_usage else u[14] - self.last_usage[14],
                        ru_nivcsw=u[15] if not self.last_usage else u[15] - self.last_usage[15],
                        alive_threads=alive_threads,
                        dummy_threads=dummy_threads,
                        daemon_threads=daemon_threads,
                        gc=g)

            self.last_usage = u
            if gc_.isenabled():
                self.last_collect = c

            return m
        except:
            logger.debug("collect_metrics", exc_info=True)
638233
def total_memory(self, image='ubuntu'):
        ''''''
        try:
            ret = subprocess.check_output(
                f'''docker run -t {image} cat /proc/meminfo  | grep MemTotal''',
                shell=True,
                stdin=subprocess.DEVNULL)
            # ret: MemTotal:       30208916 kB
            self.tot_mem = int(ret.split()[1])
        except Exception:
            # some system does not have cat or grep
            self.tot_mem = None
        return self.tot_mem
174471
def get_disk_usage(path):
    
    cmd = 'du -sh --block-size=1 {0}'.format(path)
    total = getoutput(cmd).split()[0]
    return int(total)
1286843
def stat(self):
        
        try:
            # Always use the last mount point because it's a very common
            # situation when mount points are moved, or sotorage is
            # double-mounted. Last mount point is always the newest.
            mp = self.mount_points[-1]
        except IndexError:
            return None
        stat = os.statvfs(mp)
        free = stat.f_frsize * stat.f_bavail
        total = stat.f_frsize * stat.f_blocks
        used = total - free
        used_pct = round(used / total * 100)
        free_pct = 100 - used_pct
        return Fstat(total, used, free, used_pct, free_pct)
101519
def file_size(self):
        
        stream = self.get_file_stream()
        stream.seek(0, os.SEEK_END)
        return stream.tell()
987405
def _check_available_disk_space(self, project):
        

        try:
            used_disk_space = psutil.disk_usage(project.path).percent
        except FileNotFoundError:
            log.warning('Could not find "{}" when checking for used disk space'.format(project.path))
            return
        # send a warning if used disk space is >= 90%
        if used_disk_space >= 90:
            message = 'Only {}% or less of disk space detected in "{}" on "{}"'.format(used_disk_space,
                                                                                       project.path,
                                                                                       platform.node())
            log.warning(message)
            project.emit("log.warning", {"message": message})
1272834
def diskdata():
    """"""
    p = os.popen("/bin/df -l -P")
    ddata = {}
    tsize = 0
    for line in p.readlines():
        d = line.split()
        if ("/dev/sd" in d[0] or "/dev/hd" in d[0] or "/dev/mapper" in d[0]):
            tsize = tsize + int(d[1])
    ddata["Disk_GB"] = int(tsize)/1000000
    p.close()
    return ddata
1184544
def memory_usage(self, **kwargs):
        

        def memory_usage_builder(df, **kwargs):
            return df.memory_usage(**kwargs)

        func = self._build_mapreduce_func(memory_usage_builder, **kwargs)
        return self._full_axis_reduce(0, func)